Skip to content

dropck is unsound with closure upvars #27241

Closed
@arielb1

Description

@arielb1

This should be fixed by @nikomatsakis's new patch even if the code isn't changed, but I thought it would be nice to track too.

use std::fmt;
struct NoisyDrop<T: fmt::Debug>(T);
impl<T: fmt::Debug> Drop for NoisyDrop<T> {
    fn drop(&mut self) {
        let _ = vec!["0wned"];
        println!("dropping {:?}", self.0)
    }
}
fn foo() {
    let (w,v);
    v = vec![0usize];
    w = {
        let u = NoisyDrop(&v);
        move || u.0.len()
    };
}

fn main() { foo() }

After this, the only non-trivial variants dropck correctly handles are TySlice and TyTuple - I guess even a stopped clock is right twice a day.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions