2019-11-21 12:45:28 -06:00
|
|
|
#![deny(unreachable_patterns)]
|
|
|
|
|
2019-12-27 11:53:00 -06:00
|
|
|
// We wrap patterns in a tuple because top-level or-patterns were special-cased.
|
2019-11-21 12:45:28 -06:00
|
|
|
fn main() {
|
|
|
|
match (0u8,) {
|
|
|
|
(1 | 2,) => {}
|
|
|
|
(1,) => {} //~ ERROR unreachable pattern
|
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
match (0u8,) {
|
|
|
|
(1 | 2,) => {}
|
|
|
|
(2,) => {} //~ ERROR unreachable pattern
|
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
match (0u8,) {
|
|
|
|
(1,) => {}
|
|
|
|
(2,) => {}
|
|
|
|
(1 | 2,) => {} //~ ERROR unreachable pattern
|
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
match (0u8, 0u8) {
|
|
|
|
(1 | 2, 3 | 4) => {}
|
2019-12-27 06:03:03 -06:00
|
|
|
(1, 3) => {} //~ ERROR unreachable pattern
|
|
|
|
(1, 4) => {} //~ ERROR unreachable pattern
|
|
|
|
(2, 4) => {} //~ ERROR unreachable pattern
|
2019-11-21 12:45:28 -06:00
|
|
|
(2 | 1, 4) => {} //~ ERROR unreachable pattern
|
2019-11-26 08:53:54 -06:00
|
|
|
(1, 5 | 6) => {}
|
|
|
|
(1, 4 | 5) => {} //~ ERROR unreachable pattern
|
2019-11-21 12:45:28 -06:00
|
|
|
_ => {}
|
|
|
|
}
|
2020-07-02 15:49:58 -05:00
|
|
|
match (true, true) {
|
|
|
|
(false | true, false | true) => (),
|
|
|
|
}
|
2019-11-21 13:06:49 -06:00
|
|
|
match (Some(0u8),) {
|
|
|
|
(None | Some(1 | 2),) => {}
|
|
|
|
(Some(1),) => {} //~ ERROR unreachable pattern
|
2019-12-27 06:03:03 -06:00
|
|
|
(None,) => {} //~ ERROR unreachable pattern
|
2019-11-26 08:53:54 -06:00
|
|
|
_ => {}
|
2019-11-21 13:06:49 -06:00
|
|
|
}
|
|
|
|
match ((0u8,),) {
|
2019-12-27 06:03:03 -06:00
|
|
|
((1 | 2,) | (3 | 4,),) => {}
|
|
|
|
((1..=4,),) => {} //~ ERROR unreachable pattern
|
|
|
|
_ => {}
|
2019-11-25 12:23:09 -06:00
|
|
|
}
|
2019-11-29 07:02:14 -06:00
|
|
|
|
|
|
|
match (0,) {
|
2019-12-27 06:03:03 -06:00
|
|
|
(1 | 1,) => {} //~ ERROR unreachable
|
2019-11-29 07:02:14 -06:00
|
|
|
_ => {}
|
|
|
|
}
|
2021-01-02 16:38:18 -06:00
|
|
|
match 0 {
|
|
|
|
(0 | 1) | 1 => {} //~ ERROR unreachable
|
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
match 0 {
|
2021-01-01 16:14:22 -06:00
|
|
|
// We get two errors because recursive or-pattern expansion means we don't notice the two
|
|
|
|
// errors span a whole pattern. This could be better but doesn't matter much
|
2021-01-02 16:38:18 -06:00
|
|
|
0 | (0 | 0) => {}
|
|
|
|
//~^ ERROR unreachable
|
2021-01-01 16:14:22 -06:00
|
|
|
//~| ERROR unreachable
|
2021-01-02 16:38:18 -06:00
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
match None {
|
|
|
|
// There is only one error that correctly points to the whole subpattern
|
|
|
|
Some(0) |
|
|
|
|
Some( //~ ERROR unreachable
|
|
|
|
0 | 0) => {}
|
|
|
|
_ => {}
|
|
|
|
}
|
2019-11-29 07:02:14 -06:00
|
|
|
match [0; 2] {
|
|
|
|
[0
|
|
|
|
| 0 //~ ERROR unreachable
|
|
|
|
, 0
|
|
|
|
| 0] => {} //~ ERROR unreachable
|
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
match &[][..] {
|
|
|
|
[0] => {}
|
|
|
|
[0, _] => {}
|
|
|
|
[0, _, _] => {}
|
|
|
|
[1, ..] => {}
|
|
|
|
[1 //~ ERROR unreachable
|
|
|
|
| 2, ..] => {}
|
|
|
|
_ => {}
|
|
|
|
}
|
2020-12-16 18:42:49 -06:00
|
|
|
match &[][..] {
|
|
|
|
[true] => {}
|
2020-12-16 19:25:53 -06:00
|
|
|
[true | false, ..] => {}
|
2020-12-16 18:42:49 -06:00
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
match &[][..] {
|
|
|
|
[false] => {}
|
|
|
|
[true, ..] => {}
|
|
|
|
[true //~ ERROR unreachable
|
|
|
|
| false, ..] => {}
|
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
match (true, None) {
|
|
|
|
(true, Some(_)) => {}
|
|
|
|
(false, Some(true)) => {}
|
2020-12-16 19:07:49 -06:00
|
|
|
(true | false, None | Some(true //~ ERROR unreachable
|
2020-12-16 18:42:49 -06:00
|
|
|
| false)) => {}
|
|
|
|
}
|
|
|
|
macro_rules! t_or_f {
|
|
|
|
() => {
|
2021-01-01 16:14:35 -06:00
|
|
|
(true //~ ERROR unreachable
|
|
|
|
| false)
|
2020-12-16 18:42:49 -06:00
|
|
|
};
|
|
|
|
}
|
|
|
|
match (true, None) {
|
|
|
|
(true, Some(_)) => {}
|
|
|
|
(false, Some(true)) => {}
|
|
|
|
(true | false, None | Some(t_or_f!())) => {}
|
|
|
|
}
|
2019-11-29 07:02:14 -06:00
|
|
|
match Some(0) {
|
|
|
|
Some(0) => {}
|
|
|
|
Some(0 //~ ERROR unreachable
|
|
|
|
| 1) => {}
|
|
|
|
_ => {}
|
|
|
|
}
|
2020-07-02 15:49:58 -05:00
|
|
|
|
|
|
|
// A subpattern that is only unreachable in one branch is overall reachable.
|
|
|
|
match (true, true) {
|
|
|
|
(true, true) => {}
|
|
|
|
(false | true, false | true) => {}
|
|
|
|
}
|
|
|
|
match (true, true) {
|
2020-10-20 13:32:59 -05:00
|
|
|
(true, true) => {}
|
|
|
|
(false, false) => {}
|
2020-07-02 15:49:58 -05:00
|
|
|
(false | true, false | true) => {}
|
|
|
|
}
|
2020-10-20 13:32:59 -05:00
|
|
|
// https://github.com/rust-lang/rust/issues/76836
|
|
|
|
match None {
|
|
|
|
Some(false) => {}
|
|
|
|
None | Some(true
|
2020-10-20 16:08:19 -05:00
|
|
|
| false) => {} //~ ERROR unreachable
|
2020-10-20 13:32:59 -05:00
|
|
|
}
|
|
|
|
|
2020-07-02 15:49:58 -05:00
|
|
|
// A subpattern that is unreachable in all branches is overall unreachable.
|
|
|
|
match (true, true) {
|
|
|
|
(false, true) => {}
|
|
|
|
(true, true) => {}
|
|
|
|
(false | true, false
|
|
|
|
| true) => {} //~ ERROR unreachable
|
|
|
|
}
|
|
|
|
match (true, true) {
|
|
|
|
(true, false) => {}
|
|
|
|
(true, true) => {}
|
|
|
|
(false
|
|
|
|
| true, //~ ERROR unreachable
|
|
|
|
false | true) => {}
|
|
|
|
}
|
2019-11-21 12:45:28 -06:00
|
|
|
}
|