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."
375
+
* If Place contains a deref of an `&`...
376
+
* ...or something
377
+
378
+
## Key examples
379
+
380
+
### box-mut
381
+
382
+
```rust
383
+
fnbox_mut() {
384
+
letmuts=Foo { x:0 } ;
385
+
386
+
letpx=&muts;
387
+
letbx=Box::new(px);
388
+
389
+
390
+
letc= #[rustc_capture_analysis] move||bx.x +=10;
391
+
// Mutable reference to this place:
392
+
// (*(*bx)).x
393
+
// ^ ^
394
+
// | a Box
395
+
// a &mut
396
+
}
397
+
```
398
+
399
+
```
400
+
Closure mode = move
401
+
C = {
402
+
(ref mut, (*(*bx)).x)
403
+
}
404
+
C' = C
405
+
```
406
+
407
+
Output is the same: `C' = C`
408
+
409
+
### Packed-field-ref-and-move
410
+
411
+
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