diff options
| author | Fabian Wolff <fabian.wolff@alumni.ethz.ch> | 2021-11-29 01:50:12 +0100 |
|---|---|---|
| committer | Fabian Wolff <fabian.wolff@alumni.ethz.ch> | 2022-01-31 19:04:22 +0100 |
| commit | c15ef58f4f67ee9ae02773642145650495f9f413 (patch) | |
| tree | 12f4daa8fb02803530f46df0bda7eda9308a7f1a /src/test | |
| parent | 24b8bb13bff98bb747cd403b86596af43aceee78 (diff) | |
Fix suggestion to slice if scrutinee is a `Result` or `Option`
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/ui/typeck/issue-91328.fixed | 27 | ||||
| -rw-r--r-- | src/test/ui/typeck/issue-91328.rs | 27 | ||||
| -rw-r--r-- | src/test/ui/typeck/issue-91328.stderr | 21 |
3 files changed, 75 insertions, 0 deletions
diff --git a/src/test/ui/typeck/issue-91328.fixed b/src/test/ui/typeck/issue-91328.fixed new file mode 100644 index 00000000000..48dc26718da --- /dev/null +++ b/src/test/ui/typeck/issue-91328.fixed @@ -0,0 +1,27 @@ +// 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 main() {} diff --git a/src/test/ui/typeck/issue-91328.rs b/src/test/ui/typeck/issue-91328.rs new file mode 100644 index 00000000000..de5deb95349 --- /dev/null +++ b/src/test/ui/typeck/issue-91328.rs @@ -0,0 +1,27 @@ +// 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 main() {} diff --git a/src/test/ui/typeck/issue-91328.stderr b/src/test/ui/typeck/issue-91328.stderr new file mode 100644 index 00000000000..4a9ddb2b927 --- /dev/null +++ b/src/test/ui/typeck/issue-91328.stderr @@ -0,0 +1,21 @@ +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: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0529`. |
