-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Open
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-lifetimesArea: Lifetimes / regionsArea: Lifetimes / regionsD-newcomer-roadblockDiagnostics: Confusing error or lint; hard to understand for new users.Diagnostics: Confusing error or lint; hard to understand for new users.T-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.
Description
Given the following code:
fn bar(val: &'_ str) {
let a: &'static str = val;
}
The current output is:
error[E0621]: explicit lifetime required in the type of `val`
--> src/lib.rs:2:27
|
2 | let a: &'static str = val;
| ^^^ lifetime `'static` required
error: aborting due to previous error
However, if we explicitly name the lifetime:
fn bar<'a>(val: &'a str) {
let a: &'static str = val;
}
the error message is much better:
error[E0312]: lifetime of reference outlives lifetime of borrowed content...
--> src/lib.rs:2:27
|
2 | let a: &'static str = val;
| ^^^
|
= note: ...the reference is valid for the static lifetime...
note: ...but the borrowed content is only valid for the lifetime `'a` as defined on the function body at 1:8
--> src/lib.rs:1:8
|
1 | fn bar<'a>(val: &'a str) {
| ^^
error: aborting due to previous error
We should emit the same error message when the lifetime is elided (referring to it as 'this elided lifetime' or something similar).
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-lifetimesArea: Lifetimes / regionsArea: Lifetimes / regionsD-newcomer-roadblockDiagnostics: Confusing error or lint; hard to understand for new users.Diagnostics: Confusing error or lint; hard to understand for new users.T-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.