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