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