2015-08-11 17:27:05 -07:00
|
|
|
struct Guard<'a> {
|
2019-05-28 14:46:13 -04:00
|
|
|
f: Box<dyn Fn() + Send + 'a>,
|
2015-08-11 17:27:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
fn scoped<'a, F: Fn() + Send + 'a>(f: F) -> Guard<'a> {
|
|
|
|
Guard { f: Box::new(f) }
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> Guard<'a> {
|
|
|
|
fn join(self) {}
|
|
|
|
}
|
2015-02-14 16:05:15 +11:00
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let bad = {
|
|
|
|
let x = 1;
|
2017-11-20 13:13:27 +01:00
|
|
|
let y = &x;
|
2017-12-13 17:27:23 -08:00
|
|
|
//~^ ERROR `x` does not live long enough
|
2015-02-14 16:05:15 +11:00
|
|
|
|
2015-08-11 17:27:05 -07:00
|
|
|
scoped(|| {
|
2015-02-14 16:05:15 +11:00
|
|
|
let _z = y;
|
2016-08-16 15:02:20 -07:00
|
|
|
//~^ ERROR `y` does not live long enough
|
2015-02-14 16:05:15 +11:00
|
|
|
})
|
2017-12-13 17:27:23 -08:00
|
|
|
};
|
2015-02-14 16:05:15 +11:00
|
|
|
|
2015-02-17 19:00:20 -08:00
|
|
|
bad.join();
|
2015-02-14 16:05:15 +11:00
|
|
|
}
|