mirror of
https://github.com/rust-lang/rust
synced 2024-11-05 20:45:15 +00:00
26 lines
440 B
Rust
26 lines
440 B
Rust
struct Guard<'a> {
|
|
f: Box<dyn Fn() + Send + 'a>,
|
|
}
|
|
|
|
fn scoped<'a, F: Fn() + Send + 'a>(f: F) -> Guard<'a> {
|
|
Guard { f: Box::new(f) }
|
|
}
|
|
|
|
impl<'a> Guard<'a> {
|
|
fn join(self) {}
|
|
}
|
|
|
|
fn main() {
|
|
let bad = {
|
|
let x = 1;
|
|
let y = &x;
|
|
//~^ ERROR `x` does not live long enough
|
|
|
|
scoped(|| {
|
|
let _z = y;
|
|
//~^ ERROR `y` does not live long enough
|
|
})
|
|
};
|
|
|
|
bad.join();
|
|
}
|