mirror of
https://github.com/rust-lang/rust.git
synced 2025-11-27 08:27:57 +00:00
This removes special-casing of boxes from `rustc_pattern_analysis`, as a first step in replacing `box_patterns` with `deref_patterns`. Incidentally, it fixes a bug caused by box patterns being represented as structs rather than pointers, where `exhaustive_patterns` could generate spurious `unreachable_patterns` lints on arms required for exhaustiveness; following the lint's advice would result in an error.
50 lines
1023 B
Rust
50 lines
1023 B
Rust
#![feature(exhaustive_patterns)]
|
|
#![feature(box_patterns)]
|
|
#![feature(never_type)]
|
|
#![deny(unreachable_patterns)]
|
|
|
|
mod foo {
|
|
pub struct SecretlyEmpty {
|
|
_priv: !,
|
|
}
|
|
}
|
|
|
|
struct NotSoSecretlyEmpty {
|
|
_priv: !,
|
|
}
|
|
|
|
fn foo() -> Option<NotSoSecretlyEmpty> {
|
|
None
|
|
}
|
|
|
|
fn main() {
|
|
let x: &[!] = &[];
|
|
|
|
match x {
|
|
&[] => (),
|
|
&[..] => (),
|
|
};
|
|
|
|
let x: Result<Box<NotSoSecretlyEmpty>, &[Result<!, !>]> = Err(&[]);
|
|
match x {
|
|
Ok(box _) => (), // We'd get a non-exhaustiveness error if this arm was removed; don't lint.
|
|
Err(&[]) => (),
|
|
Err(&[..]) => (),
|
|
}
|
|
match x { //~ ERROR non-exhaustive patterns
|
|
Err(&[]) => (),
|
|
Err(&[..]) => (),
|
|
}
|
|
|
|
let x: Result<foo::SecretlyEmpty, Result<NotSoSecretlyEmpty, u32>> = Err(Err(123));
|
|
match x {
|
|
Ok(_y) => (),
|
|
Err(Err(_y)) => (),
|
|
Err(Ok(_y)) => (), //~ ERROR unreachable pattern
|
|
}
|
|
|
|
while let Some(_y) = foo() {
|
|
//~^ ERROR unreachable pattern
|
|
}
|
|
}
|