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-16
Original file line number
Diff line number
Diff line change
@@ -106,14 +106,14 @@ let c = || match x {
106
106
107
107
### Capturing references in move contexts
108
108
109
-
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.
109
+
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)."
350
-
* "When taking ownership, only capture data found on the stack."
351
-
* "Otherwise, reborrow the reference."
352
-
* If Mode is `ref mut` and the place contains a deref of an `&mut`:
353
-
* Return (Place, Mode)
354
-
* Else if Mode is `ref *` and the place contains a deref of an `&`:
355
-
* Return (Place, Mode)
356
-
* Else if place contains a deref at index `i`:
350
+
* If place contains a deref at index `i`:
357
351
* Let `(Place1, _) = truncate_place(Place, Mode, i)`
358
352
* Return (Place1, ByValue)
359
353
* Else:
360
354
* Return (Place, ByValue)
355
+
* 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