2018-12-16 22:21:47 -05:00
|
|
|
struct Defer<'a> {
|
2013-12-09 23:16:18 -08:00
|
|
|
x: &'a [&'a str],
|
2012-11-14 01:22:37 -05:00
|
|
|
}
|
|
|
|
|
2018-12-16 22:21:47 -05:00
|
|
|
impl<'a> Drop for Defer<'a> {
|
2013-09-16 21:18:07 -04:00
|
|
|
fn drop(&mut self) {
|
2013-03-20 18:18:57 -07:00
|
|
|
unsafe {
|
2015-01-07 14:58:31 -08:00
|
|
|
println!("{:?}", self.x);
|
2013-03-20 18:18:57 -07:00
|
|
|
}
|
2012-11-14 01:22:37 -05:00
|
|
|
}
|
2012-08-17 17:30:29 -07:00
|
|
|
}
|
|
|
|
|
2018-12-16 22:21:47 -05:00
|
|
|
fn defer<'r>(x: &'r [&'r str]) -> Defer<'r> {
|
|
|
|
Defer {
|
2012-09-05 15:58:43 -07:00
|
|
|
x: x
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-17 17:30:29 -07:00
|
|
|
fn main() {
|
2019-04-22 08:40:08 +01:00
|
|
|
let x = defer(&vec!["Goodbye", "world!"]); //~ ERROR temporary value dropped while borrowed
|
2013-03-15 15:24:24 -04:00
|
|
|
x.x[0];
|
2012-08-17 17:30:29 -07:00
|
|
|
}
|