Open
Description
I noticed that the non-lexical lifetimes do not work if the reference is used in the structure field.
rustc 1.38.0 (625451e37 2019-09-23)
#[derive(Debug)]
struct Foo<'a, T> {
x: &'a T,
}
fn main() {
let str_1 = "str1".to_string();
let str_2 = "str2".to_string();
let mut foo = Foo { x: &str_1 };
foo.x = &str_2;
// move out
let str_3 = str_1;
println!("{:?} {}", foo, str_3);
}
error[E0505]: cannot move out of `str_1` because it is borrowed
--> src/main.rs:15:17
|
10 | let mut foo = Foo { x: &str_1 };
| ------ borrow of `str_1` occurs here
...
15 | let str_3 = str_1;
| ^^^^^ move out of `str_1` occurs here
16 |
17 | println!("{:?} {}", foo, str_3);
| --- borrow later used here
error: aborting due to previous error
For more information about this error, try `rustc --explain E0505`.
error: Could not compile `testapp2`.
To learn more, run the command again with --verbose.
Process finished with exit code 101