mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
add #[rustc_must_match_exhaustively]
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
//@ compile-flags: -Z unstable-options
|
||||
//@ ignore-stage1
|
||||
|
||||
#![feature(rustc_private)]
|
||||
#![feature(rustc_attrs)]
|
||||
#![deny(rustc::rustc_must_match_exhaustively)]
|
||||
|
||||
|
||||
#[rustc_must_match_exhaustively]
|
||||
#[derive(Copy, Clone)]
|
||||
enum Foo {
|
||||
A {field: u32},
|
||||
B,
|
||||
}
|
||||
|
||||
fn foo(f: Foo) {
|
||||
match f {
|
||||
Foo::A {..}=> {}
|
||||
Foo::B => {}
|
||||
}
|
||||
|
||||
match f {
|
||||
//~^ ERROR match is not exhaustive
|
||||
Foo::A {..} => {}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
match f {
|
||||
//~^ ERROR match is not exhaustive
|
||||
Foo::A {..} => {}
|
||||
a => {}
|
||||
}
|
||||
|
||||
match &f {
|
||||
//~^ ERROR match is not exhaustive
|
||||
Foo::A {..} => {}
|
||||
a => {}
|
||||
}
|
||||
|
||||
match f {
|
||||
Foo::A {..} => {}
|
||||
a@Foo::B => {}
|
||||
}
|
||||
|
||||
if let Foo::A {..} = f {}
|
||||
//~^ ERROR match is not exhaustive
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,71 @@
|
||||
error: match is not exhaustive
|
||||
--> $DIR/must_match_exhaustively.rs:22:11
|
||||
|
|
||||
LL | #[rustc_must_match_exhaustively]
|
||||
| -------------------------------- required because of this attribute
|
||||
...
|
||||
LL | match f {
|
||||
| ^
|
||||
|
|
||||
= help: explicitly list all variants of the enum in a `match`
|
||||
note: because of this wildcard pattern
|
||||
--> $DIR/must_match_exhaustively.rs:25:9
|
||||
|
|
||||
LL | _ => {}
|
||||
| ^
|
||||
note: the lint level is defined here
|
||||
--> $DIR/must_match_exhaustively.rs:6:9
|
||||
|
|
||||
LL | #![deny(rustc::rustc_must_match_exhaustively)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: match is not exhaustive
|
||||
--> $DIR/must_match_exhaustively.rs:28:11
|
||||
|
|
||||
LL | #[rustc_must_match_exhaustively]
|
||||
| -------------------------------- required because of this attribute
|
||||
...
|
||||
LL | match f {
|
||||
| ^
|
||||
|
|
||||
= help: explicitly list all variants of the enum in a `match`
|
||||
note: because of this variable binding
|
||||
--> $DIR/must_match_exhaustively.rs:31:9
|
||||
|
|
||||
LL | a => {}
|
||||
| ^
|
||||
|
||||
error: match is not exhaustive
|
||||
--> $DIR/must_match_exhaustively.rs:34:11
|
||||
|
|
||||
LL | #[rustc_must_match_exhaustively]
|
||||
| -------------------------------- required because of this attribute
|
||||
...
|
||||
LL | match &f {
|
||||
| ^^
|
||||
|
|
||||
= help: explicitly list all variants of the enum in a `match`
|
||||
note: because of this variable binding
|
||||
--> $DIR/must_match_exhaustively.rs:37:9
|
||||
|
|
||||
LL | a => {}
|
||||
| ^
|
||||
|
||||
error: match is not exhaustive
|
||||
--> $DIR/must_match_exhaustively.rs:45:8
|
||||
|
|
||||
LL | #[rustc_must_match_exhaustively]
|
||||
| -------------------------------- required because of this attribute
|
||||
...
|
||||
LL | if let Foo::A {..} = f {}
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: explicitly list all variants of the enum in a `match`
|
||||
note: using if let only matches on one variant (try using `match`)
|
||||
--> $DIR/must_match_exhaustively.rs:45:8
|
||||
|
|
||||
LL | if let Foo::A {..} = f {}
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
Reference in New Issue
Block a user