Closed
Description
This merge introduced a helpful hint for a (elided) lifetime mismatch error. However, we don't get the hint when the function is in a trait
or an impl
.
Given the following code:
fn foo(slice_a: &mut [u8], slice_b: &mut [u8]) {
core::mem::swap(&mut slice_a, &mut slice_b);
}
The current output is:
error[E0623]: lifetime mismatch
--> src/main.rs:21:35
|
20 | fn foo(slice_a: &mut [u8], slice_b: &mut [u8]) {
| --------- --------- these two types are declared with different lifetimes...
21 | core::mem::swap(&mut slice_a, &mut slice_b);
| ^^^^^^^^^^^^ ...but data from `slice_b` flows into `slice_a` here
|
= note: each elided lifetime in input position becomes a distinct lifetime
help: consider introducing a named lifetime parameter
|
20 | fn foo<'a>(slice_a: &'a mut [u8], slice_b: &'a mut [u8]) {
| ++++ ++ ++
error[E0623]: lifetime mismatch
--> src/main.rs:21:35
|
20 | fn foo(slice_a: &mut [u8], slice_b: &mut [u8]) {
| --------- ---------
| |
| these two types are declared with different lifetimes...
21 | core::mem::swap(&mut slice_a, &mut slice_b);
| ^^^^^^^^^^^^ ...but data from `slice_a` flows into `slice_b` here
|
= note: each elided lifetime in input position becomes a distinct lifetime
help: consider introducing a named lifetime parameter
|
20 | fn foo<'a>(slice_a: &'a mut [u8], slice_b: &'a mut [u8]) {
| ++++ ++ ++
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0623`.
But given the following:
trait FooTrait {
fn foo(slice_a: &mut [u8], slice_b: &mut [u8]) {
core::mem::swap(&mut slice_a, &mut slice_b);
}
}
The output is missing the hint:
error[E0623]: lifetime mismatch
--> src/main.rs:30:39
|
29 | fn foo(slice_a: &mut [u8], slice_b: &mut [u8]) {
| --------- --------- these two types are declared with different lifetimes...
30 | core::mem::swap(&mut slice_a, &mut slice_b);
| ^^^^^^^^^^^^ ...but data from `slice_b` flows into `slice_a` here
error[E0623]: lifetime mismatch
--> src/main.rs:30:39
|
29 | fn foo(slice_a: &mut [u8], slice_b: &mut [u8]) {
| --------- ---------
| |
| these two types are declared with different lifetimes...
30 | core::mem::swap(&mut slice_a, &mut slice_b);
| ^^^^^^^^^^^^ ...but data from `slice_a` flows into `slice_b` here
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0623`.
Ideally the output should look like:
error[E0623]: lifetime mismatch
--> src/main.rs:30:39
|
29 | fn foo(slice_a: &mut [u8], slice_b: &mut [u8]) {
| --------- --------- these two types are declared with different lifetimes...
30 | core::mem::swap(&mut slice_a, &mut slice_b);
| ^^^^^^^^^^^^ ...but data from `slice_b` flows into `slice_a` here
|
= note: each elided lifetime in input position becomes a distinct lifetime
help: consider introducing a named lifetime parameter
|
29 | fn foo<'a>(slice_a: &'a mut [u8], slice_b: &'a mut [u8]) {
| ++++ ++ ++
error[E0623]: lifetime mismatch
--> src/main.rs:30:39
|
29 | fn foo(slice_a: &mut [u8], slice_b: &mut [u8]) {
| --------- ---------
| |
| these two types are declared with different lifetimes...
30 | core::mem::swap(&mut slice_a, &mut slice_b);
| ^^^^^^^^^^^^ ...but data from `slice_a` flows into `slice_b` here
|
= note: each elided lifetime in input position becomes a distinct lifetime
help: consider introducing a named lifetime parameter
|
29 | fn foo<'a>(slice_a: &'a mut [u8], slice_b: &'a mut [u8]) {
| ++++ ++ ++
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0623`.