Skip to content

Commit

Permalink
reference examples: add box, nll fixes, and typos
Browse files Browse the repository at this point in the history
  • Loading branch information
samsartor committed Jul 27, 2018
1 parent f366f92 commit 15f2eee
Showing 1 changed file with 28 additions and 11 deletions.
39 changes: 28 additions & 11 deletions text/0000-capture-disjoint-fields.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,30 +169,33 @@ let foo = 10;
- `&mut foo` (not a struct)

```rust
let _a = &mut foo.a;
let a = &mut foo.a;
|| (&mut foo.b, &mut foo.c);
somefunc(a);
```

- `&mut foo.b` (used in entirety)
- `&mut foo.a` (used in entirety)
- `&mut foo.c` (used in entirety)

The borrow checker passes because `foo.a`, `foo.b`, and `foo.c` are disjoint.

```rust
let _a = &mut foo.a;
let a = &mut foo.a;
move || foo.b;
somefunc(a);
```

- `foo.b` (used in entirety)

The borrow checker passes because `foo.a` and `foo.b` are disjoint.

```rust
let _hello = &foo.hello;
let hello = &foo.hello;
move || foo.drop_world.a;
somefunc(hello);
```

- `foo.drop_world` (owned & implements drop)
- `foo.drop_world` (owned and implements drop)

The borrow checker passes because `foo.hello` and `foo.drop_world` are disjoint.

Expand All @@ -216,13 +219,14 @@ let bar = (1, 2); // struct
- `bar` (used in entirety)

```rust
let _foo_again = &mut foo;
let foo_again = &mut foo;
|| &mut foo.a;
somefunc(foo_again);
```

- `&mut foo.a` (used in entirety)

The borrow checker fails because `_foo_again` and `foo.a` intersect.
The borrow checker fails because `foo_again` and `foo.a` intersect.

```rust
let _a = foo.a;
Expand All @@ -234,14 +238,27 @@ let _a = foo.a;
The borrow checker fails because `foo.a` has already been moved.

```rust
let _a = drop_foo.a;
let a = &drop_foo.a;
move || drop_foo.b;
somefunc(a);
```

- `drop_foo` (owned and implements drop)

The borrow checker fails because `drop_foo` can not be moved while borrowed.

```rust
|| &box_foo.a;
```

- `drop_foo` (owned & implements drop)
- `&<Box<_> as Deref>::deref(&box_foo).b` (pure function call)

```rust
move || &box_foo.a;
```

The borrow checker fails because `drop_foo` can not be destructured + use of
partially moved value.
- `box_foo` (`move` forces full capure of `box_foo`, since it can not be
destructured)

# Drawbacks
[drawbacks]: #drawbacks
Expand Down

0 comments on commit 15f2eee

Please sign in to comment.