rust/src/test/ui/borrowck/borrowck-borrowed-uniq-rvalue-2.rs

23 lines
377 B
Rust
Raw Normal View History

struct Defer<'a> {
x: &'a [&'a str],
}
impl<'a> Drop for Defer<'a> {
2013-09-16 20:18:07 -05:00
fn drop(&mut self) {
unsafe {
println!("{:?}", self.x);
}
}
}
fn defer<'r>(x: &'r [&'r str]) -> Defer<'r> {
Defer {
2012-09-05 17:58:43 -05:00
x: x
}
}
fn main() {
let x = defer(&vec!["Goodbye", "world!"]); //~ ERROR borrowed value does not live long enough
2013-03-15 14:24:24 -05:00
x.x[0];
}