Merge move_fn_closure run-passtest into closure-drop

This commit is contained in:
Oliver Schneider 2017-02-24 10:42:11 +01:00
parent 38d16ccacc
commit 31c81ac322
2 changed files with 5 additions and 34 deletions

View File

@ -13,17 +13,12 @@ fn f<T: FnOnce()>(t: T) {
fn main() {
let mut ran_drop = false;
{
// FIXME: v is a temporary hack to force the below closure to be a FnOnce-only closure
// (with sig fn(self)). Without it, the closure sig would be fn(&self) which requires a
// shim to call via FnOnce::call_once, and Miri's current shim doesn't correctly call
// destructors.
let v = vec![1];
let x = Foo(&mut ran_drop);
let g = move || {
let _ = x;
drop(v); // Force the closure to be FnOnce-only by using a capture by-value.
};
f(g);
// 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);
}
assert!(ran_drop);
}

View File

@ -1,24 +0,0 @@
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 _ = x; };
f(x);
}
assert!(ran_drop);
}