rust/src/test/ui/borrowck/borrowck-borrowed-uniq-rvalue-2.rs
2018-12-25 21:08:33 -07:00

23 lines
377 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 borrowed value does not live long enough
x.x[0];
}