rust/tests/ui/uninhabited/uninhabited-patterns.rs

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

48 lines
946 B
Rust
Raw Normal View History

#![feature(box_patterns)]
#![feature(never_type)]
#![feature(exhaustive_patterns)]
2019-12-29 18:23:42 -06:00
#![deny(unreachable_patterns)]
mod foo {
pub struct SecretlyEmpty {
_priv: !,
}
}
struct NotSoSecretlyEmpty {
_priv: !,
}
2017-02-04 02:27:45 -06:00
fn foo() -> Option<NotSoSecretlyEmpty> {
None
}
fn main() {
let x: &[!] = &[];
match x {
&[] => (),
&[..] => (), //~ ERROR unreachable pattern
};
let x: Result<Box<NotSoSecretlyEmpty>, &[Result<!, !>]> = Err(&[]);
match x {
Ok(box _) => (), //~ ERROR unreachable pattern
Err(&[]) => (),
Err(&[..]) => (), //~ ERROR unreachable pattern
}
let x: Result<foo::SecretlyEmpty, Result<NotSoSecretlyEmpty, u32>> = Err(Err(123));
match x {
Ok(_y) => (),
Err(Err(_y)) => (),
Err(Ok(_y)) => (), //~ ERROR unreachable pattern
}
2017-02-04 02:27:45 -06:00
while let Some(_y) = foo() {
//~^ ERROR unreachable pattern
}
}