-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
A-NLLArea: Non-lexical lifetimes (NLL)Area: Non-lexical lifetimes (NLL)C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.NLL-completeWorking towards the "valid code works" goalWorking towards the "valid code works" goalT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language teamRelevant to the language team
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
Metadata
Metadata
Assignees
Labels
A-NLLArea: Non-lexical lifetimes (NLL)Area: Non-lexical lifetimes (NLL)C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.NLL-completeWorking towards the "valid code works" goalWorking towards the "valid code works" goalT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language teamRelevant to the language team