forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#87033 - FabianWolff:issue-87017, r=estebank
Provide a suggestion when trying to destructure a `Vec` as a slice Fixes rust-lang#87017. r? `@estebank`
- Loading branch information
Showing
5 changed files
with
110 additions
and
2 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
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,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 | ||
_ => {} | ||
} | ||
} |
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,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 | ||
_ => {} | ||
} | ||
} |
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,36 @@ | ||
error[E0529]: expected an array or slice, found `Vec<i32>` | ||
--> $DIR/pattern-slice-vec.rs:8: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: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:23:9 | ||
| | ||
LL | match &v { | ||
| -- help: consider slicing here: `&v[..]` | ||
LL | | ||
LL | [5] => {} | ||
| ^^^ pattern cannot match with input type `Vec<_>` | ||
|
||
error: aborting due to 4 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0529`. |