Run rustfix in pattern-slice-vec.rs UI test

This commit is contained in:
Fabian Wolff 2021-08-02 18:35:49 +02:00
parent c29aadd9cf
commit 7b26f76cb5
3 changed files with 46 additions and 4 deletions

View File

@ -0,0 +1,27 @@
// Regression test for #87017.
// run-rustfix
fn main() {
fn foo() -> Vec<i32> { vec![1, 2, 3] }
if let [_, _, _] = foo()[..] {}
//~^ ERROR: expected an array or slice
//~| HELP: consider slicing here
if let [] = &foo()[..] {}
//~^ ERROR: expected an array or slice
//~| HELP: consider slicing here
if let [] = foo()[..] {}
//~^ ERROR: expected an array or slice
//~| HELP: consider slicing here
let v = vec![];
match &v[..] {
//~^ HELP: consider slicing here
[5] => {}
//~^ ERROR: expected an array or slice
_ => {}
}
}

View File

@ -1,15 +1,22 @@
// Regression test for #87017.
// run-rustfix
fn main() {
fn foo() -> Vec<i32> { vec![1, 2, 3] }
if let [_, _, _] = foo() {}
//~^ ERROR: expected an array or slice
//~| HELP: consider slicing here
if let [] = &foo() {}
//~^ ERROR: expected an array or slice
//~| HELP: consider slicing here
if let [] = foo() {}
//~^ ERROR: expected an array or slice
//~| HELP: consider slicing here
let v = vec![];
match &v {
//~^ HELP: consider slicing here

View File

@ -1,5 +1,5 @@
error[E0529]: expected an array or slice, found `Vec<i32>`
--> $DIR/pattern-slice-vec.rs:6:12
--> $DIR/pattern-slice-vec.rs:8:12
|
LL | if let [_, _, _] = foo() {}
| ^^^^^^^^^ ----- help: consider slicing here: `foo()[..]`
@ -7,15 +7,23 @@ LL | if let [_, _, _] = foo() {}
| pattern cannot match with input type `Vec<i32>`
error[E0529]: expected an array or slice, found `Vec<i32>`
--> $DIR/pattern-slice-vec.rs:9:12
--> $DIR/pattern-slice-vec.rs:12:12
|
LL | if let [] = &foo() {}
| ^^ ------ help: consider slicing here: `&foo()[..]`
| |
| pattern cannot match with input type `Vec<i32>`
error[E0529]: expected an array or slice, found `Vec<i32>`
--> $DIR/pattern-slice-vec.rs:16:12
|
LL | if let [] = foo() {}
| ^^ ----- help: consider slicing here: `foo()[..]`
| |
| pattern cannot match with input type `Vec<i32>`
error[E0529]: expected an array or slice, found `Vec<_>`
--> $DIR/pattern-slice-vec.rs:16:9
--> $DIR/pattern-slice-vec.rs:23:9
|
LL | match &v {
| -- help: consider slicing here: `&v[..]`
@ -23,6 +31,6 @@ LL |
LL | [5] => {}
| ^^^ pattern cannot match with input type `Vec<_>`
error: aborting due to 3 previous errors
error: aborting due to 4 previous errors
For more information about this error, try `rustc --explain E0529`.