Skip to content

Commit 3f160c6

Browse files
authored
Rollup merge of rust-lang#81897 - vandenheuvel:match_exhaustive_diagnostics_regression_test, r=Mark-Simulacrum
Add match pattern diagnostics regression test Closes rust-lang#72377 by adding a regression test. This test case fails on stable but now works on beta and nightly. It *should* have worked already for years, the crucial point whether it is mentioned that some uncovered patterns are not explicitly mentioned.
2 parents 9503ea1 + 5fe8490 commit 3f160c6

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#[derive(PartialEq, Eq)]
2+
enum X { A, B, C, }
3+
4+
fn main() {
5+
let x = X::A;
6+
let y = Some(X::A);
7+
8+
match (x, y) {
9+
//~^ ERROR non-exhaustive patterns: `(A, Some(A))`, `(A, Some(B))`, `(B, Some(B))` and 2
10+
//~| more not covered
11+
(_, None) => false,
12+
(v, Some(w)) if v == w => true,
13+
(X::B, Some(X::C)) => false,
14+
(X::B, Some(X::A)) => false,
15+
(X::A, Some(X::C)) | (X::C, Some(X::A)) => false,
16+
};
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0004]: non-exhaustive patterns: `(A, Some(A))`, `(A, Some(B))`, `(B, Some(B))` and 2 more not covered
2+
--> $DIR/issue-72377.rs:8:11
3+
|
4+
LL | match (x, y) {
5+
| ^^^^^^ patterns `(A, Some(A))`, `(A, Some(B))`, `(B, Some(B))` and 2 more not covered
6+
|
7+
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
8+
= note: the matched value is of type `(X, Option<X>)`
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0004`.

0 commit comments

Comments
 (0)