Skip to content

Commit

Permalink
Fix test for lifetime elision hint
Browse files Browse the repository at this point in the history
  • Loading branch information
Noratrieb committed Oct 26, 2021
1 parent 2f4d780 commit 76ec1aa
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 66 deletions.
16 changes: 4 additions & 12 deletions src/test/ui/lifetimes/issue-90170-elision-mismatch.fixed
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() {}
16 changes: 4 additions & 12 deletions src/test/ui/lifetimes/issue-90170-elision-mismatch.rs
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 src/test/ui/lifetimes/issue-90170-elision-mismatch.stderr
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`.

0 comments on commit 76ec1aa

Please sign in to comment.