about summary refs log tree commit diff
path: root/src/tools/miri/tests/pass/closure-drop.rs
blob: 9f9454b4c71c564469fe78d1e2bfd9d957ea0a23 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
struct Foo<'a>(&'a mut bool);

impl<'a> Drop for Foo<'a> {
    fn drop(&mut self) {
        *self.0 = true;
    }
}

fn f<T: FnOnce()>(t: T) {
    t()
}

fn main() {
    let mut ran_drop = false;
    {
        let x = Foo(&mut ran_drop);
        // this closure never by val uses its captures
        // so it's basically a fn(&self)
        // the shim used to not drop the `x`
        let x = move || {
            let _val = x;
        };
        f(x);
    }
    assert!(ran_drop);
}