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

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

45 lines
840 B
Rust
Raw Normal View History

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