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
* "Optimization: borrow the ref, not data owned by ref."
390
+
* If Place contains a deref of an `&`...
391
+
* ...or something
392
+
393
+
## Key examples
394
+
395
+
### box-mut
396
+
397
+
```rust
398
+
fnbox_mut() {
399
+
letmuts=Foo { x:0 } ;
400
+
401
+
letpx=&muts;
402
+
letbx=Box::new(px);
403
+
404
+
405
+
letc= #[rustc_capture_analysis] move||bx.x +=10;
406
+
// Mutable reference to this place:
407
+
// (*(*bx)).x
408
+
// ^ ^
409
+
// | a Box
410
+
// a &mut
411
+
}
412
+
```
413
+
414
+
```
415
+
Closure mode = move
416
+
C = {
417
+
(ref mut, (*(*bx)).x)
418
+
}
419
+
C' = C
420
+
```
421
+
422
+
Output is the same: `C' = C`
423
+
424
+
### Packed-field-ref-and-move
425
+
426
+
When you have a closure that both references a packed field (which is unsafe) and moves from it (which is safe) we capture the entire struct, rather than just moving the field. This is to aid in predictability, so that removing the move doesn't make the closure become unsafe:
0 commit comments