Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix suggestion to slice if scrutinee is a Result or Option #91343

Merged
merged 3 commits into from
Feb 1, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add match on Vec<_> to ui/typeck/issue-91328.rs test
FabianWolff committed Jan 31, 2022
commit 0363f11ff03269d84eedb50d2130000fdfeceeb0
10 changes: 10 additions & 0 deletions src/test/ui/typeck/issue-91328.fixed
Original file line number Diff line number Diff line change
@@ -24,4 +24,14 @@ fn bar(o: Option<Vec<i32>>) -> i32 {
}
}

fn baz(v: Vec<i32>) -> i32 {
match v[..] {
//~^ HELP: consider slicing here
[a, b] => a + b,
//~^ ERROR: expected an array or slice
//~| NOTE: pattern cannot match with input type
_ => 42,
}
}

fn main() {}
10 changes: 10 additions & 0 deletions src/test/ui/typeck/issue-91328.rs
Original file line number Diff line number Diff line change
@@ -24,4 +24,14 @@ fn bar(o: Option<Vec<i32>>) -> i32 {
}
}

fn baz(v: Vec<i32>) -> i32 {
match v {
//~^ HELP: consider slicing here
[a, b] => a + b,
//~^ ERROR: expected an array or slice
//~| NOTE: pattern cannot match with input type
_ => 42,
}
}

fn main() {}
11 changes: 10 additions & 1 deletion src/test/ui/typeck/issue-91328.stderr
Original file line number Diff line number Diff line change
@@ -16,6 +16,15 @@ LL |
LL | Some([a, b]) => a + b,
| ^^^^^^ pattern cannot match with input type `Vec<i32>`

error: aborting due to 2 previous errors
error[E0529]: expected an array or slice, found `Vec<i32>`
--> $DIR/issue-91328.rs:30:9
|
LL | match v {
| - help: consider slicing here: `v[..]`
LL |
LL | [a, b] => a + b,
| ^^^^^^ pattern cannot match with input type `Vec<i32>`

error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0529`.