2024-07-21 07:46:05 -05:00
|
|
|
#![feature(never_type)]
|
2024-08-28 13:10:26 -05:00
|
|
|
#![feature(exhaustive_patterns)]
|
2024-07-21 07:46:05 -05:00
|
|
|
#![deny(unreachable_patterns)]
|
|
|
|
//~^ NOTE lint level is defined here
|
|
|
|
|
|
|
|
#[rustfmt::skip]
|
|
|
|
fn main() {
|
|
|
|
match (0u8,) {
|
|
|
|
(1 | 2,) => {}
|
2024-08-19 13:51:21 -05:00
|
|
|
//~^ NOTE matches all the relevant values
|
2024-07-21 07:46:05 -05:00
|
|
|
(2,) => {}
|
|
|
|
//~^ ERROR unreachable pattern
|
2024-08-19 13:51:21 -05:00
|
|
|
//~| NOTE no value can reach this
|
2024-07-21 07:46:05 -05:00
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
|
|
|
|
match (0u8,) {
|
|
|
|
(1,) => {}
|
|
|
|
//~^ NOTE matches some of the same values
|
|
|
|
(2,) => {}
|
|
|
|
//~^ NOTE matches some of the same values
|
|
|
|
(1 | 2,) => {}
|
|
|
|
//~^ ERROR unreachable pattern
|
2024-08-19 13:51:21 -05:00
|
|
|
//~| NOTE no value can reach this
|
|
|
|
//~| NOTE multiple earlier patterns match some of the same values
|
2024-07-24 01:40:04 -05:00
|
|
|
//~| NOTE collectively making this unreachable
|
2024-07-21 07:46:05 -05:00
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
|
2024-08-19 14:26:32 -05:00
|
|
|
match 0u8 {
|
|
|
|
1 => {}
|
|
|
|
//~^ NOTE matches some of the same values
|
|
|
|
2 => {}
|
|
|
|
//~^ NOTE matches some of the same values
|
|
|
|
3 => {}
|
|
|
|
//~^ NOTE matches some of the same values
|
|
|
|
4 => {}
|
|
|
|
//~^ NOTE matches some of the same values
|
|
|
|
5 => {}
|
|
|
|
6 => {}
|
|
|
|
1 ..= 6 => {}
|
|
|
|
//~^ ERROR unreachable pattern
|
|
|
|
//~| NOTE no value can reach this
|
|
|
|
//~| NOTE multiple earlier patterns match some of the same values
|
|
|
|
//~| NOTE ...and 2 other patterns
|
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
|
2024-07-21 07:46:05 -05:00
|
|
|
let res: Result<(),!> = Ok(());
|
|
|
|
match res {
|
|
|
|
Ok(_) => {}
|
|
|
|
Err(_) => {}
|
|
|
|
//~^ ERROR unreachable pattern
|
2024-08-19 13:51:21 -05:00
|
|
|
//~| NOTE matches no values because `!` is uninhabited
|
2024-08-19 14:08:18 -05:00
|
|
|
//~| NOTE to learn more about uninhabited types, see
|
2024-07-21 07:46:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Copy, Clone)]
|
|
|
|
enum Void1 {}
|
|
|
|
#[derive(Copy, Clone)]
|
|
|
|
enum Void2 {}
|
|
|
|
// Only an empty type matched _by value_ can make an arm unreachable. We must get the right one.
|
|
|
|
let res1: Result<(), Void1> = Ok(());
|
|
|
|
let res2: Result<(), Void2> = Ok(());
|
|
|
|
match (&res1, res2) {
|
|
|
|
(Err(_), Err(_)) => {}
|
|
|
|
//~^ ERROR unreachable pattern
|
2024-08-19 13:51:21 -05:00
|
|
|
//~| NOTE matches no values because `Void2` is uninhabited
|
2024-08-19 14:08:18 -05:00
|
|
|
//~| NOTE to learn more about uninhabited types, see
|
2024-07-21 07:46:05 -05:00
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
match (res1, &res2) {
|
|
|
|
(Err(_), Err(_)) => {}
|
|
|
|
//~^ ERROR unreachable pattern
|
2024-08-19 13:51:21 -05:00
|
|
|
//~| NOTE matches no values because `Void1` is uninhabited
|
2024-08-19 14:08:18 -05:00
|
|
|
//~| NOTE to learn more about uninhabited types, see
|
2024-07-21 07:46:05 -05:00
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if let (0
|
2024-08-19 13:51:21 -05:00
|
|
|
//~^ NOTE matches all the relevant values
|
2024-07-21 07:46:05 -05:00
|
|
|
| 0, _) = (0, 0) {}
|
|
|
|
//~^ ERROR unreachable pattern
|
2024-08-19 13:51:21 -05:00
|
|
|
//~| NOTE no value can reach this
|
2024-07-21 07:46:05 -05:00
|
|
|
|
|
|
|
match (true, true) {
|
|
|
|
(_, true) if false => {} // Guarded patterns don't cover others
|
|
|
|
(true, _) => {}
|
|
|
|
//~^ NOTE matches some of the same values
|
|
|
|
(false, _) => {}
|
|
|
|
//~^ NOTE matches some of the same values
|
|
|
|
(_, true) => {}
|
|
|
|
//~^ ERROR unreachable pattern
|
2024-08-19 13:51:21 -05:00
|
|
|
//~| NOTE no value can reach this
|
|
|
|
//~| NOTE multiple earlier patterns match some of the same values
|
2024-07-24 01:40:04 -05:00
|
|
|
//~| NOTE collectively making this unreachable
|
2024-07-21 07:46:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
match (true, true) {
|
|
|
|
(true, _) => {}
|
2024-08-19 13:51:21 -05:00
|
|
|
//~^ NOTE matches all the relevant values
|
2024-07-21 07:46:05 -05:00
|
|
|
(false, _) => {}
|
|
|
|
#[allow(unreachable_patterns)]
|
|
|
|
(_, true) => {} // Doesn't cover below because it's already unreachable.
|
|
|
|
(true, true) => {}
|
|
|
|
//~^ ERROR unreachable pattern
|
2024-08-19 13:51:21 -05:00
|
|
|
//~| NOTE no value can reach this
|
2024-07-21 07:46:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Despite skipping some irrelevant cases, we still report a set of rows that covers the
|
|
|
|
// unreachable one.
|
|
|
|
match (true, true, 0) {
|
|
|
|
(true, _, _) => {}
|
|
|
|
(_, true, 0..10) => {}
|
2024-08-19 13:51:21 -05:00
|
|
|
//~^ NOTE matches all the relevant values
|
2024-07-21 07:46:05 -05:00
|
|
|
(_, true, 10..) => {}
|
|
|
|
(_, true, 3) => {}
|
|
|
|
//~^ ERROR unreachable pattern
|
2024-08-19 13:51:21 -05:00
|
|
|
//~| NOTE no value can reach this
|
2024-07-21 07:46:05 -05:00
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
}
|