rust/tests/ui/pattern/usefulness/empty-match-check-notes.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

53 lines
1.4 KiB
Rust
Raw Normal View History

2023-10-29 04:13:07 -05:00
//@ aux-build:empty.rs
//@ revisions: normal exhaustive_patterns
//
// This tests a match with no arms on various types, and checks NOTEs.
#![feature(never_type)]
#![cfg_attr(exhaustive_patterns, feature(exhaustive_patterns))]
#![deny(unreachable_patterns)]
//~^ NOTE the lint level is defined here
extern crate empty;
enum EmptyEnum {}
fn empty_enum(x: EmptyEnum) {
match x {} // ok
match x {
_ => {} //~ ERROR unreachable pattern
}
match x {
_ if false => {} //~ ERROR unreachable pattern
}
}
fn empty_foreign_enum(x: empty::EmptyForeignEnum) {
match x {} // ok
match x {
_ => {} //~ ERROR unreachable pattern
}
match x {
_ if false => {} //~ ERROR unreachable pattern
}
}
fn empty_foreign_enum_private(x: Option<empty::SecretlyUninhabitedForeignStruct>) {
let None = x;
//~^ ERROR refutable pattern in local binding
//~| NOTE `let` bindings require an "irrefutable pattern"
//~| NOTE for more information, visit
//~| NOTE the matched value is of type
//~| NOTE pattern `Some(_)` not covered
//[exhaustive_patterns]~| NOTE currently uninhabited, but this variant contains private fields
}
fn main() {
match 0u8 {
//~^ ERROR not covered
2023-10-29 04:13:07 -05:00
//~| NOTE the matched value is of type
//~| NOTE match arms with guards don't count towards exhaustivity
//~| NOTE not covered
2023-10-29 04:13:07 -05:00
_ if false => {}
}
}