rust-lang/project-rfc-2229

Don't truncate Derefs if the data is not moved into the closure

Closed this issue · 0 comments

Both these examples currently truncate the capture to the root variable

fn box_mut() {
    let mut s = Foo { x: 0 } ;
    
    let px = &mut s;
    let bx = Box::new(px);
    
    
    let c = #[rustc_capture_analysis] move || bx.x += 10;
}

fn mut_box() {
    let s = String::new();
    
    let bx = Box::new(s);
    let px = &mut bx;
    
    
    
    let c = #[rustc_capture_analysis]  move || px.truncate(0);
}