forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#91343 - FabianWolff:issue-91328-as-deref, r…
…=jackh726 Fix suggestion to slice if scrutinee is a `Result` or `Option` Fixes rust-lang#91328.
- Loading branch information
Showing
4 changed files
with
138 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Regression test for issue #91328. | ||
|
||
// run-rustfix | ||
|
||
#![allow(dead_code)] | ||
|
||
fn foo(r: Result<Vec<i32>, i32>) -> i32 { | ||
match r.as_deref() { | ||
//~^ HELP: consider using `as_deref` here | ||
Ok([a, b]) => a + b, | ||
//~^ ERROR: expected an array or slice | ||
//~| NOTE: pattern cannot match with input type | ||
_ => 42, | ||
} | ||
} | ||
|
||
fn bar(o: Option<Vec<i32>>) -> i32 { | ||
match o.as_deref() { | ||
//~^ HELP: consider using `as_deref` here | ||
Some([a, b]) => a + b, | ||
//~^ ERROR: expected an array or slice | ||
//~| NOTE: pattern cannot match with input type | ||
_ => 42, | ||
} | ||
} | ||
|
||
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() {} |
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,37 @@ | ||
// Regression test for issue #91328. | ||
|
||
// run-rustfix | ||
|
||
#![allow(dead_code)] | ||
|
||
fn foo(r: Result<Vec<i32>, i32>) -> i32 { | ||
match r { | ||
//~^ HELP: consider using `as_deref` here | ||
Ok([a, b]) => a + b, | ||
//~^ ERROR: expected an array or slice | ||
//~| NOTE: pattern cannot match with input type | ||
_ => 42, | ||
} | ||
} | ||
|
||
fn bar(o: Option<Vec<i32>>) -> i32 { | ||
match o { | ||
//~^ HELP: consider using `as_deref` here | ||
Some([a, b]) => a + b, | ||
//~^ ERROR: expected an array or slice | ||
//~| NOTE: pattern cannot match with input type | ||
_ => 42, | ||
} | ||
} | ||
|
||
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() {} |
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,30 @@ | ||
error[E0529]: expected an array or slice, found `Vec<i32>` | ||
--> $DIR/issue-91328.rs:10:12 | ||
| | ||
LL | match r { | ||
| - help: consider using `as_deref` here: `r.as_deref()` | ||
LL | | ||
LL | Ok([a, b]) => a + b, | ||
| ^^^^^^ pattern cannot match with input type `Vec<i32>` | ||
|
||
error[E0529]: expected an array or slice, found `Vec<i32>` | ||
--> $DIR/issue-91328.rs:20:14 | ||
| | ||
LL | match o { | ||
| - help: consider using `as_deref` here: `o.as_deref()` | ||
LL | | ||
LL | Some([a, b]) => a + b, | ||
| ^^^^^^ pattern cannot match with input type `Vec<i32>` | ||
|
||
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`. |