-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bail out of MIR construction if
check_match
fails
- Loading branch information
Showing
5 changed files
with
154 additions
and
13 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
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,23 @@ | ||
// regression test for #108683 | ||
// edition:2021 | ||
|
||
enum Refutable { | ||
A, | ||
B, | ||
} | ||
|
||
fn example(v1: u32, v2: [u32; 4], v3: Refutable) { | ||
const PAT: u32 = 0; | ||
let v4 = &v2[..]; | ||
|| { | ||
let 0 = v1; //~ ERROR refutable pattern in local binding | ||
let (0 | 1) = v1; //~ ERROR refutable pattern in local binding | ||
let 1.. = v1; //~ ERROR refutable pattern in local binding | ||
let [0, 0, 0, 0] = v2; //~ ERROR refutable pattern in local binding | ||
let [0] = v4; //~ ERROR refutable pattern in local binding | ||
let Refutable::A = v3; //~ ERROR refutable pattern in local binding | ||
let PAT = v1; //~ ERROR refutable pattern in local binding | ||
}; | ||
} | ||
|
||
fn main() {} |
113 changes: 113 additions & 0 deletions
113
tests/ui/closures/2229_closure_analysis/bad-pattern.stderr
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,113 @@ | ||
error[E0005]: refutable pattern in local binding | ||
--> $DIR/bad-pattern.rs:13:13 | ||
| | ||
LL | let 0 = v1; | ||
| ^ pattern `1_u32..=u32::MAX` not covered | ||
| | ||
= note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant | ||
= note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html | ||
= note: the matched value is of type `u32` | ||
help: you might want to use `if let` to ignore the variant that isn't matched | ||
| | ||
LL | if let 0 = v1 { todo!() }; | ||
| ++ +++++++++++ | ||
help: alternatively, you could prepend the pattern with an underscore to define a new named variable; identifiers cannot begin with digits | ||
| | ||
LL | let _0 = v1; | ||
| + | ||
|
||
error[E0005]: refutable pattern in local binding | ||
--> $DIR/bad-pattern.rs:14:14 | ||
| | ||
LL | let (0 | 1) = v1; | ||
| ^^^^^ pattern `2_u32..=u32::MAX` not covered | ||
| | ||
= note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant | ||
= note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html | ||
= note: the matched value is of type `u32` | ||
help: you might want to use `if let` to ignore the variant that isn't matched | ||
| | ||
LL | if let (0 | 1) = v1 { todo!() }; | ||
| ++ +++++++++++ | ||
|
||
error[E0005]: refutable pattern in local binding | ||
--> $DIR/bad-pattern.rs:15:13 | ||
| | ||
LL | let 1.. = v1; | ||
| ^^^ pattern `0_u32` not covered | ||
| | ||
= note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant | ||
= note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html | ||
= note: the matched value is of type `u32` | ||
help: you might want to use `if let` to ignore the variant that isn't matched | ||
| | ||
LL | if let 1.. = v1 { todo!() }; | ||
| ++ +++++++++++ | ||
|
||
error[E0005]: refutable pattern in local binding | ||
--> $DIR/bad-pattern.rs:16:13 | ||
| | ||
LL | let [0, 0, 0, 0] = v2; | ||
| ^^^^^^^^^^^^ pattern `[1_u32..=u32::MAX, _, _, _]` not covered | ||
| | ||
= note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant | ||
= note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html | ||
= note: the matched value is of type `[u32; 4]` | ||
help: you might want to use `if let` to ignore the variant that isn't matched | ||
| | ||
LL | if let [0, 0, 0, 0] = v2 { todo!() }; | ||
| ++ +++++++++++ | ||
|
||
error[E0005]: refutable pattern in local binding | ||
--> $DIR/bad-pattern.rs:17:13 | ||
| | ||
LL | let [0] = v4; | ||
| ^^^ patterns `&[]` and `&[_, _, ..]` not covered | ||
| | ||
= note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant | ||
= note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html | ||
= note: the matched value is of type `&[u32]` | ||
help: you might want to use `if let` to ignore the variants that aren't matched | ||
| | ||
LL | if let [0] = v4 { todo!() }; | ||
| ++ +++++++++++ | ||
|
||
error[E0005]: refutable pattern in local binding | ||
--> $DIR/bad-pattern.rs:18:13 | ||
| | ||
LL | let Refutable::A = v3; | ||
| ^^^^^^^^^^^^ pattern `Refutable::B` not covered | ||
| | ||
= note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant | ||
= note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html | ||
note: `Refutable` defined here | ||
--> $DIR/bad-pattern.rs:4:6 | ||
| | ||
LL | enum Refutable { | ||
| ^^^^^^^^^ | ||
LL | A, | ||
LL | B, | ||
| - not covered | ||
= note: the matched value is of type `Refutable` | ||
help: you might want to use `if let` to ignore the variant that isn't matched | ||
| | ||
LL | if let Refutable::A = v3 { todo!() }; | ||
| ++ +++++++++++ | ||
|
||
error[E0005]: refutable pattern in local binding | ||
--> $DIR/bad-pattern.rs:19:13 | ||
| | ||
LL | let PAT = v1; | ||
| ^^^ | ||
| | | ||
| pattern `1_u32..=u32::MAX` not covered | ||
| missing patterns are not covered because `PAT` is interpreted as a constant pattern, not a new variable | ||
| help: introduce a variable instead: `PAT_var` | ||
| | ||
= note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant | ||
= note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html | ||
= note: the matched value is of type `u32` | ||
|
||
error: aborting due to 7 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0005`. |