Rollup merge of #157668 - jdonszelmann:matches-must-match-exhaustively, r=lqd

Add test for matches in `rustc_must_match_exhaustively`

r? @lcnr
This commit is contained in:
Jacob Pratt
2026-06-09 16:53:07 -04:00
committed by GitHub
2 changed files with 20 additions and 1 deletions
@@ -46,6 +46,9 @@ fn foo(f: Foo) {
let Foo::A { .. } = f else { loop {} };
//~^ ERROR match is not exhaustive
matches!(f, Foo::A { .. });
//~^ ERROR match is not exhaustive
}
fn main() {}
@@ -83,5 +83,21 @@ note: using `let else` only matches on one variant (try using `match`)
LL | let Foo::A { .. } = f else { loop {} };
| ^^^^^^^^^^^^^
error: aborting due to 5 previous errors
error: match is not exhaustive
--> $DIR/must_match_exhaustively.rs:50:14
|
LL | #[rustc_must_match_exhaustively]
| -------------------------------- required because of this attribute
...
LL | matches!(f, Foo::A { .. });
| ^
|
= help: explicitly list all variants of the enum in a `match`
note: because of this wildcard pattern
--> $DIR/must_match_exhaustively.rs:50:5
|
LL | matches!(f, Foo::A { .. });
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 6 previous errors