Skip to content

Unable to capture-by-copy without move #143466

@samsartor

Description

@samsartor

I tried this code:

pub struct Stuff {
    integer: i32,
}

fn main() {
    let stuff = Stuff { integer: 42 };
    std::thread::spawn(|| {
        let _integer_copy: i32 = stuff.integer;
    });    
}

It gives "error[E0713]: borrow may still be in use when destructor runs" and "error[E0505]: cannot move out of stuff because it is borrowed" instead of simply copying the integer. I assume it is a bit of an ambiguity in how https://doc.rust-lang.org/reference/types/closure.html#capture-precision/disjoint-captures should be implemented.

EDIT: Ok, my original version of this looked weird and complicated but it turns out to have nothing at all to do with Drop. I think I'm just brain-farting on how this case is supposed to work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions