You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Here's a bit of a verbose test case for a situation where I get away with accessing a value in a ~-closure environment after its destructor has run. valgrind also complains. Not sure whether this falls under a known bug, I didn't really know what terms to search for.
struct A {
foo : Option<~fn(&mut A)>
}
impl A {
fn call(&mut self) {
(*self.foo.get_ref())(self); // this is probably the broken bit
}
}
struct S {
msg: ~str
}
impl Drop for S {
fn drop(&mut self) {
println!("drop {:?}", *self);
self.msg = ~"dropped";
}
}
fn main() {
let x = S { msg: ~"ok" };
let f: ~fn(&mut A) = |a| { a.foo = None; println!("{:?}", x); }; // this frees closure environment via `a`, then accesses it
let mut a = A { foo: Some(f) };
a.call();
}