-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add beginner friendly lifetime elision hint to E0623
Suggest adding a new lifetime parameter when two elided lifetimes should match up but don't Issue #90170 This also changes the tests introduced by the previous commits because of another rustc issue (#90258)
- Loading branch information
Showing
11 changed files
with
220 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// run-rustfix | ||
|
||
pub fn foo<'a>(x: &mut Vec<&'a u8>, y: &'a u8) { x.push(y); } //~ ERROR lifetime mismatch | ||
|
||
pub fn foo2<'a>(x: &mut Vec<&'a u8>, y: &'a u8) { x.push(y); } //~ ERROR lifetime mismatch | ||
|
||
pub fn foo3<'a>(_other: &'a [u8], x: &mut Vec<&'a u8>, y: &'a u8) { x.push(y); } //~ ERROR lifetime mismatch | ||
|
||
fn main() {} |
29 changes: 29 additions & 0 deletions
29
src/test/ui/lifetimes/issue-90170-elision-mismatch.nll.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
error: lifetime may not live long enough | ||
--> $DIR/issue-90170-elision-mismatch.rs:3:40 | ||
| | ||
LL | pub fn foo(x: &mut Vec<&u8>, y: &u8) { x.push(y); } | ||
| - - ^^^^^^^^^ argument requires that `'1` must outlive `'2` | ||
| | | | ||
| | let's call the lifetime of this reference `'1` | ||
| let's call the lifetime of this reference `'2` | ||
|
||
error: lifetime may not live long enough | ||
--> $DIR/issue-90170-elision-mismatch.rs:5:44 | ||
| | ||
LL | pub fn foo2(x: &mut Vec<&'_ u8>, y: &u8) { x.push(y); } | ||
| - - ^^^^^^^^^ argument requires that `'1` must outlive `'2` | ||
| | | | ||
| | let's call the lifetime of this reference `'1` | ||
| let's call the lifetime of this reference `'2` | ||
|
||
error: lifetime may not live long enough | ||
--> $DIR/issue-90170-elision-mismatch.rs:7:63 | ||
| | ||
LL | pub fn foo3<'a>(_other: &'a [u8], x: &mut Vec<&u8>, y: &u8) { x.push(y); } | ||
| - - ^^^^^^^^^ argument requires that `'1` must outlive `'2` | ||
| | | | ||
| | let's call the lifetime of this reference `'1` | ||
| let's call the lifetime of this reference `'2` | ||
|
||
error: aborting due to 3 previous errors | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// run-rustfix | ||
|
||
pub fn foo(x: &mut Vec<&u8>, y: &u8) { x.push(y); } //~ ERROR lifetime mismatch | ||
|
||
pub fn foo2(x: &mut Vec<&'_ u8>, y: &u8) { x.push(y); } //~ ERROR lifetime mismatch | ||
|
||
pub fn foo3<'a>(_other: &'a [u8], x: &mut Vec<&u8>, y: &u8) { x.push(y); } //~ ERROR lifetime mismatch | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
error[E0623]: lifetime mismatch | ||
--> $DIR/issue-90170-elision-mismatch.rs:3:47 | ||
| | ||
LL | pub fn foo(x: &mut Vec<&u8>, y: &u8) { x.push(y); } | ||
| --- --- ^ ...but data from `y` flows into `x` here | ||
| | | ||
| these two types are declared with different lifetimes... | ||
| | ||
= note: each elided lifetime in input position becomes a distinct lifetime | ||
help: consider introducing a named lifetime parameter | ||
| | ||
LL | pub fn foo<'a>(x: &mut Vec<&'a u8>, y: &'a u8) { x.push(y); } | ||
| ++++ ++ ++ | ||
|
||
error[E0623]: lifetime mismatch | ||
--> $DIR/issue-90170-elision-mismatch.rs:5:51 | ||
| | ||
LL | pub fn foo2(x: &mut Vec<&'_ u8>, y: &u8) { x.push(y); } | ||
| ------ --- ^ ...but data from `y` flows into `x` here | ||
| | | ||
| these two types are declared with different lifetimes... | ||
| | ||
= note: each elided lifetime in input position becomes a distinct lifetime | ||
help: consider introducing a named lifetime parameter | ||
| | ||
LL | pub fn foo2<'a>(x: &mut Vec<&'a u8>, y: &'a u8) { x.push(y); } | ||
| ++++ ~~ ++ | ||
|
||
error[E0623]: lifetime mismatch | ||
--> $DIR/issue-90170-elision-mismatch.rs:7:70 | ||
| | ||
LL | pub fn foo3<'a>(_other: &'a [u8], x: &mut Vec<&u8>, y: &u8) { x.push(y); } | ||
| --- --- ^ ...but data from `y` flows into `x` here | ||
| | | ||
| these two types are declared with different lifetimes... | ||
| | ||
= note: each elided lifetime in input position becomes a distinct lifetime | ||
help: consider introducing a named lifetime parameter | ||
| | ||
LL | pub fn foo3<'a>(_other: &'a [u8], x: &mut Vec<&'a u8>, y: &'a u8) { x.push(y); } | ||
| ++ ++ | ||
|
||
error: aborting due to 3 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0623`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters