Closed
Description
With 1.24.0-nightly (2017-12-21 250b492):
This compiles:
#![feature(nll)]
fn main() {
let mut vec = Vec::new();
let a = 1;
vec.push(&a);
let b = 2;
vec.push(&b);
println!("{:?}", vec);
}
But this does not:
#![feature(nll)]
fn f() {
let mut vec = Vec::new();
let a = String::from("");
vec.push(&a);
let b = String::from("");
vec.push(&b);
println!("{:?}", vec);
}
fn main() {}
error[E0597]: `a` does not live long enough
--> src/main.rs:7:14
|
7 | vec.push(&a);
| ^^ borrowed value does not live long enough
...
13 | }
| - borrowed value only lives until here
|
= note: borrowed value must be valid for lifetime '_#11r...