-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
31 additions
and
66 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,9 @@ | ||
// run-rustfix | ||
|
||
fn foo<'a>(x: &mut Vec<&'a u8>, y: &'a u8) { x.push(y); } //~ ERROR lifetime mismatch | ||
pub fn foo<'a>(x: &mut Vec<&'a u8>, y: &'a u8) { x.push(y); } //~ ERROR lifetime mismatch | ||
|
||
fn foo2<'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 | ||
|
||
fn foo3<'a>(_other: &'a [u8], 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 ok<'a>(slice_a: &'a mut [u8], slice_b: &'a mut [u8]) { | ||
core::mem::swap(&mut slice_a, &mut slice_b); | ||
} | ||
|
||
fn main() { | ||
let a = [1u8, 2, 3]; | ||
let b = [4u8, 5, 6]; | ||
foo(&mut a, &mut b); | ||
} | ||
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 |
---|---|---|
@@ -1,17 +1,9 @@ | ||
// run-rustfix | ||
|
||
fn foo(x: &mut Vec<&u8>, y: &u8) { x.push(y); } //~ ERROR lifetime mismatch | ||
pub fn foo(x: &mut Vec<&u8>, y: &u8) { x.push(y); } //~ ERROR lifetime mismatch | ||
|
||
fn foo2(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 | ||
|
||
fn foo3<'a>(_other: &'a [u8], 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 ok<'a>(slice_a: &'a mut [u8], slice_b: &'a mut [u8]) { | ||
core::mem::swap(&mut slice_a, &mut slice_b); | ||
} | ||
|
||
fn main() { | ||
let a = [1u8, 2, 3]; | ||
let b = [4u8, 5, 6]; | ||
foo(&mut a, &mut b); | ||
} | ||
fn main() {} |
65 changes: 23 additions & 42 deletions
65
src/test/ui/lifetimes/issue-90170-elision-mismatch.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 |
---|---|---|
@@ -1,64 +1,45 @@ | ||
error[E0623]: lifetime mismatch | ||
--> $DIR/issue-90170-elision-mismatch.rs:3:43 | ||
--> $DIR/issue-90170-elision-mismatch.rs:3:47 | ||
| | ||
LL | 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... | ||
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 | fn foo<'a>(x: &mut Vec<&'a u8>, y: &'a u8) { x.push(y); } | ||
| ++++ ++ ++ | ||
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:47 | ||
--> $DIR/issue-90170-elision-mismatch.rs:5:51 | ||
| | ||
LL | 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... | ||
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 | fn foo2<'a>(x: &mut Vec<&'a u8>, y: &'a u8) { x.push(y); } | ||
| ++++ ~~ ++ | ||
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:66 | ||
--> $DIR/issue-90170-elision-mismatch.rs:7:70 | ||
| | ||
LL | 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... | ||
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 | fn foo3<'a>(_other: &'a [u8], x: &mut Vec<&'a u8>, y: &'a u8) { x.push(y); } | ||
| ++ ++ | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/issue-90170-elision-mismatch.rs:16:9 | ||
| | ||
LL | foo(&mut a, &mut b); | ||
| ^^^^^^ expected struct `Vec`, found array `[u8; 3]` | ||
| | ||
= note: expected mutable reference `&mut Vec<&u8>` | ||
found mutable reference `&mut [u8; 3]` | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/issue-90170-elision-mismatch.rs:16:17 | ||
| | ||
LL | foo(&mut a, &mut b); | ||
| ^^^^^^ expected `u8`, found array `[u8; 3]` | ||
| | ||
= note: expected reference `&u8` | ||
found mutable reference `&mut [u8; 3]` | ||
LL | pub fn foo3<'a>(_other: &'a [u8], x: &mut Vec<&'a u8>, y: &'a u8) { x.push(y); } | ||
| ++ ++ | ||
|
||
error: aborting due to 5 previous errors | ||
error: aborting due to 3 previous errors | ||
|
||
Some errors have detailed explanations: E0308, E0623. | ||
For more information about an error, try `rustc --explain E0308`. | ||
For more information about this error, try `rustc --explain E0623`. |