You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/types/closure.md
+21-16Lines changed: 21 additions & 16 deletions
Original file line number
Diff line number
Diff line change
@@ -111,14 +111,14 @@ let c = || match x {
111
111
112
112
### Capturing references in move contexts
113
113
114
-
Moving fields out of references is not allowed. As a result, in the case of move closures, when values accessed through a shared references are moved into the closure body, the compiler, instead of moving the values out of the reference, would reborrow the data.
114
+
Moving fields out of references is not allowed. As a result, in the case of move closures, when values accessed through a shared references are moved into the closure body, the compiler will truncate right before a dereference.
* "Take ownership if data being accessed is owned by the variable used to access it (or if closure attempts to move data that it doesn't own)."
364
-
* "When taking ownership, only capture data found on the stack."
365
-
* "Otherwise, reborrow the reference."
366
-
* If Mode is `ref mut` and the place contains a deref of an `&mut`:
367
-
* Return (Place, Mode)
368
-
* Else if Mode is `ref *` and the place contains a deref of an `&`:
369
-
* Return (Place, Mode)
370
-
* Else if place contains a deref at index `i`:
364
+
* If place contains a deref at index `i`:
371
365
* Let `(Place1, _) = truncate_place(Place, Mode, i)`
372
366
* Return (Place1, ByValue)
373
367
* Else:
374
368
* Return (Place, ByValue)
369
+
* Note that initially we had considered an approach where "Take ownership if data being accessed is owned by the variable used to access it (or if closure attempts to move data that it doesn't own). That is when taking ownership only capture data that is found on the stack otherwise reborrow the reference.". This cause a bug around lifetimes, check [rust-lang/rust#88431](https://github.com/rust-lang/rust/issues/88431).
0 commit comments