2017-02-10 17:05:29 -06:00
|
|
|
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);
|
2017-02-24 03:42:11 -06:00
|
|
|
// 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 _ = x; };
|
|
|
|
f(x);
|
2017-02-10 17:05:29 -06:00
|
|
|
}
|
|
|
|
assert!(ran_drop);
|
|
|
|
}
|
|
|
|
|