mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-24 07:44:10 +00:00
23 lines
375 B
Rust
23 lines
375 B
Rust
struct Defer<'a> {
|
|
x: &'a [&'a str],
|
|
}
|
|
|
|
impl<'a> Drop for Defer<'a> {
|
|
fn drop(&mut self) {
|
|
unsafe {
|
|
println!("{:?}", self.x);
|
|
}
|
|
}
|
|
}
|
|
|
|
fn defer<'r>(x: &'r [&'r str]) -> Defer<'r> {
|
|
Defer {
|
|
x: x
|
|
}
|
|
}
|
|
|
|
fn main() {
|
|
let x = defer(&vec!["Goodbye", "world!"]); //~ ERROR temporary value dropped while borrowed
|
|
x.x[0];
|
|
}
|