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