Closed
Description
When there is a (elided) lifetime mismatch, we output a hint to introduce a lifetime but the hint does not suggest adding a lifetime to the return type.
Given the following code:
trait T {
fn foo(&self, x: &i32) -> Option<&i32> {
Some(x)
}
}
The current output is:
error[E0623]: lifetime mismatch
--> src/main.rs:11:9
|
10 | fn foo(&self, x: &i32) -> Option<&i32> {
| ---- ------------
| |
| this parameter and the return type are declared with different lifetimes...
11 | Some(x)
| ^^^^^^^ ...but data from `x` is returned here
|
= note: each elided lifetime in input position becomes a distinct lifetime
help: consider introducing a named lifetime parameter
|
10 | fn foo<'a>(&'a self, x: &'a i32) -> Option<&i32> {
| ++++ ++ ++
error: aborting due to previous error
For more information about this error, try `rustc --explain E0623`.
Ideally the output should also suggest adding 'a
to the return type:
error[E0623]: lifetime mismatch
--> src/main.rs:11:9
|
10 | fn foo(&self, x: &i32) -> Option<&i32> {
| ---- ------------
| |
| this parameter and the return type are declared with different lifetimes...
11 | Some(x)
| ^^^^^^^ ...but data from `x` is returned here
|
= note: each elided lifetime in input position becomes a distinct lifetime
help: consider introducing a named lifetime parameter
|
10 | fn foo<'a>(&'a self, x: &'a i32) -> Option<&'a i32> {
| ++++ ++ ++ ++
error: aborting due to previous error
For more information about this error, try `rustc --explain E0623`.