Skip to content

Commit d30f678

Browse files
committed
final phrasing revisions
1 parent 4c8f1ae commit d30f678

File tree

1 file changed

+29
-29
lines changed

1 file changed

+29
-29
lines changed

text/0000-capture-disjoint-fields.md

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ should be applied to capturing. If implemented, the following code examples
1212
would become valid:
1313

1414
```rust
15-
let _a = &mut foo.a;
15+
let a = &mut foo.a;
1616
|| &mut foo.b; // Error! cannot borrow `foo`
17+
somefunc(a);
1718
```
1819

1920
```rust
20-
let _a = &mut foo.a;
21+
let a = &mut foo.a;
2122
move || foo.b; // Error! cannot move `foo`
23+
somefunc(a);
2224
```
2325

2426
Note that some discussion of this has already taken place:
@@ -118,33 +120,35 @@ capture set.
118120
Currently, lowering creates exactly one capture expression for each used
119121
binding, which borrows or moves the value in its entirety. This RFC proposes
120122
that lowering should instead create the minimal capture, where each expression
121-
is as specific as possible.
123+
is as precise as possible.
122124

123-
This minimal set of capture expressions *might* be created by starting with the
124-
existing capture set (one maximal expression per binding) and then iterativly
125-
modifying and splitting the expressions by adding additional dereferences and
126-
path components.
125+
This minimal set of capture expressions *might* be created through a sort of
126+
iterative refinement. We would start out capturing all of the local variables.
127+
Then, each path would be made more precise by adding additional dereferences and
128+
path components depending on which paths are used and how. References to structs
129+
would be made more precise by reborrowing fields and owned structs would be made
130+
more precise by moving fields.
127131

128132
A capture expression is minimal if it produces a value that is used by the
129133
closure in its entirety (e.g. is a primitive, is passed outside the closure,
130-
etc.) or if making the expression more specific would require one the following.
134+
etc.) or if making the expression more precise would require one the following.
131135

132136
- a call to an impure function
133137
- an illegal move (for example, out of a `Drop` type)
134138

135139
When generating a capture expression, we must decide if the output should be
136140
owned or if it can be a reference. In a non-`move` closure, a capture expression
137141
will *only* produce owned data if ownership of that data is required by the body
138-
of the closure. In a `move` closure, will *always* produced owned data unless
139-
the captured binding does not have ownership.
142+
of the closure. A `move` closure will *always* produce owned data unless the
143+
captured binding does not have ownership.
140144

141145
Note that *all* functions are considered impure (including to overloaded deref
142-
impls). And, for the sake of capturing, all indexing is considered impure *(see
143-
unresolved)*. It is possible that overloaded `Deref::deref` implementations
144-
could be marked as pure by using a new, marker trait (such as `DerefPure`) or
145-
attribute (such as `#[deref_transparent]`). However, such a solution should be
146-
proposed in a separate RFC. In the meantime, `<Box as Deref>::deref` could be a
147-
special case of a pure function *(see unresolved)*.
146+
implementations). And, for the sake of capturing, all indexing is considered
147+
impure. It is possible that overloaded `Deref::deref` implementations could be
148+
marked as pure by using a new, marker trait (such as `DerefPure`) or attribute
149+
(such as `#[deref_transparent]`). However, such a solution should be proposed in
150+
a separate RFC. In the meantime, `<Box as Deref>::deref` could be a special case
151+
of a pure function *(see unresolved)*.
148152

149153
Also note that, because capture expressions are all subsets of the closure body,
150154
this RFC does not change *what* is executed. It does change the order/number of
@@ -196,7 +200,7 @@ move || foo.drop_world.a;
196200
somefunc(hello);
197201
```
198202

199-
- `foo.drop_world` (ownership available, can't be more specific without moving
203+
- `foo.drop_world` (ownership available, can't be more precise without moving
200204
out of `Drop`)
201205

202206
The borrow checker passes because `foo.hello` and `foo.drop_world` are disjoint.
@@ -205,14 +209,14 @@ The borrow checker passes because `foo.hello` and `foo.drop_world` are disjoint.
205209
|| println!("{}", foo.wrapper_thing.a);
206210
```
207211

208-
- `&foo.wrapper_thing` (ownership not required, can't be more specific because
212+
- `&foo.wrapper_thing` (ownership not required, can't be more precise because
209213
overloaded `Deref` on `wrapper_thing` is impure)
210214

211215
```rust
212216
|| foo.list[0];
213217
```
214218

215-
- `foo.list` (ownership required, can't be more specific because indexing is
219+
- `foo.list` (ownership required, can't be more precise because indexing is
216220
impure)
217221

218222
```rust
@@ -247,10 +251,10 @@ move || drop_foo.b;
247251
somefunc(a);
248252
```
249253

250-
- `drop_foo` (ownership available, can't be more specific without moving out of
254+
- `drop_foo` (ownership available, can't be more precise without moving out of
251255
`Drop`)
252256

253-
The borrow checker fails because `drop_foo` can not be moved while borrowed.
257+
The borrow checker fails because `drop_foo` cannot be moved while borrowed.
254258

255259
```rust
256260
|| &box_foo.a;
@@ -262,7 +266,7 @@ The borrow checker fails because `drop_foo` can not be moved while borrowed.
262266
move || &box_foo.a;
263267
```
264268

265-
- `box_foo` (ownership available, can't be more specific without moving out of
269+
- `box_foo` (ownership available, can't be more precise without moving out of
266270
`Drop`)
267271

268272
```rust
@@ -296,15 +300,11 @@ difference when inlining.
296300
[unresolved]: #unresolved-questions
297301

298302
- How to optimize pointers. Can borrows that all reference parts of the same
299-
object be stored as a single pointer? How should this optimization be
300-
implemented (e.g. a special `repr`, refinement typing)?
301-
302-
- Any reason for non-overloaded index-by-constant to be pre-evaluated? It is
303-
technically pure. Could this be left as an implementation/optimization
304-
decision?
303+
object be stored as a single pointer? How should this optimization be
304+
implemented (e.g. a special `repr`, refinement typing)?
305305

306306
- How to signal that a function is pure. Is this even needed/wanted? Any other
307-
places where the language could benefit?
307+
places where the language could benefit?
308308

309309
- Should `Box` be special?
310310

0 commit comments

Comments
 (0)