Open
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).