2015-10-16 10:54:05 -05:00
|
|
|
use std::rc::Rc;
|
|
|
|
use std::sync::Arc;
|
|
|
|
|
|
|
|
struct Foo<'a>(&'a String);
|
|
|
|
|
|
|
|
impl<'a> Drop for Foo<'a> {
|
|
|
|
fn drop(&mut self) {
|
|
|
|
println!("{:?}", self.0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
{
|
|
|
|
let (y, x);
|
|
|
|
x = "alive".to_string();
|
2016-10-14 10:55:45 -05:00
|
|
|
y = Arc::new(Foo(&x));
|
2017-12-13 19:27:23 -06:00
|
|
|
}
|
|
|
|
//~^^ ERROR `x` does not live long enough
|
2015-10-16 10:54:05 -05:00
|
|
|
|
|
|
|
{
|
|
|
|
let (y, x);
|
|
|
|
x = "alive".to_string();
|
2016-10-14 10:55:45 -05:00
|
|
|
y = Rc::new(Foo(&x));
|
2017-12-13 19:27:23 -06:00
|
|
|
}
|
|
|
|
//~^^ ERROR `x` does not live long enough
|
2015-10-16 10:54:05 -05:00
|
|
|
}
|