Skip to content

Commit 89b19cc

Browse files
committed
Continue to emit unreachable pattern on cases caught by overlapping patterns
1 parent 6832da8 commit 89b19cc

File tree

6 files changed

+76
-34
lines changed

6 files changed

+76
-34
lines changed

src/librustc_mir/hair/pattern/check_match.rs

-4
Original file line numberDiff line numberDiff line change
@@ -429,10 +429,6 @@ fn check_arms<'tcx>(
429429

430430
hir::MatchSource::ForLoopDesugar |
431431
hir::MatchSource::Normal => {
432-
if let box PatternKind::Range(..) = pat.kind {
433-
// Covered by `overlapping_patterns` with more context
434-
break;
435-
}
436432
let mut err = cx.tcx.struct_span_lint_hir(
437433
lint::builtin::UNREACHABLE_PATTERNS,
438434
hir_pat.hir_id,

src/test/ui/check_match/issue-43253.stderr

+6
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ LL | 1..10 => {},
3232
LL | 8..=9 => {},
3333
| ^^^^^ overlapping patterns
3434

35+
warning: unreachable pattern
36+
--> $DIR/issue-43253.rs:35:9
37+
|
38+
LL | 8..=9 => {},
39+
| ^^^^^
40+
3541
warning: unreachable pattern
3642
--> $DIR/issue-43253.rs:41:9
3743
|

src/test/ui/exhaustive_integer_patterns.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ fn main() {
4141
match x { //~ ERROR non-exhaustive patterns
4242
-7 => {}
4343
-5..=120 => {}
44-
-2..=20 => {} //~ ERROR multiple patterns covering the same range
44+
-2..=20 => {}
45+
//~^ ERROR unreachable pattern
46+
//~| ERROR multiple patterns covering the same range
4547
125 => {}
4648
}
4749

src/test/ui/exhaustive_integer_patterns.stderr

+16-10
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ LL | -5..=120 => {}
4848
LL | -2..=20 => {}
4949
| ^^^^^^^ overlapping patterns
5050

51+
error: unreachable pattern
52+
--> $DIR/exhaustive_integer_patterns.rs:44:9
53+
|
54+
LL | -2..=20 => {}
55+
| ^^^^^^^
56+
5157
error[E0004]: non-exhaustive patterns: `std::i8::MIN..=-8i8`, `-6i8`, `121i8..=124i8` and 1 more not covered
5258
--> $DIR/exhaustive_integer_patterns.rs:41:11
5359
|
@@ -57,77 +63,77 @@ LL | match x {
5763
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
5864

5965
error[E0004]: non-exhaustive patterns: `std::i8::MIN` not covered
60-
--> $DIR/exhaustive_integer_patterns.rs:82:11
66+
--> $DIR/exhaustive_integer_patterns.rs:84:11
6167
|
6268
LL | match 0i8 {
6369
| ^^^ pattern `std::i8::MIN` not covered
6470
|
6571
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
6672

6773
error[E0004]: non-exhaustive patterns: `0i16` not covered
68-
--> $DIR/exhaustive_integer_patterns.rs:90:11
74+
--> $DIR/exhaustive_integer_patterns.rs:92:11
6975
|
7076
LL | match 0i16 {
7177
| ^^^^ pattern `0i16` not covered
7278
|
7379
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
7480

7581
error[E0004]: non-exhaustive patterns: `128u8..=std::u8::MAX` not covered
76-
--> $DIR/exhaustive_integer_patterns.rs:108:11
82+
--> $DIR/exhaustive_integer_patterns.rs:110:11
7783
|
7884
LL | match 0u8 {
7985
| ^^^ pattern `128u8..=std::u8::MAX` not covered
8086
|
8187
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
8288

8389
error[E0004]: non-exhaustive patterns: `(0u8, Some(_))` and `(2u8..=std::u8::MAX, Some(_))` not covered
84-
--> $DIR/exhaustive_integer_patterns.rs:120:11
90+
--> $DIR/exhaustive_integer_patterns.rs:122:11
8591
|
8692
LL | match (0u8, Some(())) {
8793
| ^^^^^^^^^^^^^^^ patterns `(0u8, Some(_))` and `(2u8..=std::u8::MAX, Some(_))` not covered
8894
|
8995
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
9096

9197
error[E0004]: non-exhaustive patterns: `(126u8..=127u8, false)` not covered
92-
--> $DIR/exhaustive_integer_patterns.rs:125:11
98+
--> $DIR/exhaustive_integer_patterns.rs:127:11
9399
|
94100
LL | match (0u8, true) {
95101
| ^^^^^^^^^^^ pattern `(126u8..=127u8, false)` not covered
96102
|
97103
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
98104

99105
error: multiple patterns covering the same range
100-
--> $DIR/exhaustive_integer_patterns.rs:140:9
106+
--> $DIR/exhaustive_integer_patterns.rs:142:9
101107
|
102108
LL | 0 .. 2 => {}
103109
| ------ this range overlaps on `1u8`
104110
LL | 1 ..= 2 => {}
105111
| ^^^^^^^ overlapping patterns
106112

107113
error[E0004]: non-exhaustive patterns: `std::u128::MAX` not covered
108-
--> $DIR/exhaustive_integer_patterns.rs:145:11
114+
--> $DIR/exhaustive_integer_patterns.rs:147:11
109115
|
110116
LL | match 0u128 {
111117
| ^^^^^ pattern `std::u128::MAX` not covered
112118
|
113119
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
114120

115121
error[E0004]: non-exhaustive patterns: `5u128..=std::u128::MAX` not covered
116-
--> $DIR/exhaustive_integer_patterns.rs:149:11
122+
--> $DIR/exhaustive_integer_patterns.rs:151:11
117123
|
118124
LL | match 0u128 {
119125
| ^^^^^ pattern `5u128..=std::u128::MAX` not covered
120126
|
121127
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
122128

123129
error[E0004]: non-exhaustive patterns: `0u128..=3u128` not covered
124-
--> $DIR/exhaustive_integer_patterns.rs:153:11
130+
--> $DIR/exhaustive_integer_patterns.rs:155:11
125131
|
126132
LL | match 0u128 {
127133
| ^^^^^ pattern `0u128..=3u128` not covered
128134
|
129135
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
130136

131-
error: aborting due to 15 previous errors
137+
error: aborting due to 16 previous errors
132138

133139
For more information about this error, try `rustc --explain E0004`.

src/test/ui/match/match-range-fail-dominate.rs

+12-4
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,33 @@
33
fn main() {
44
match 5 {
55
1 ..= 10 => { }
6-
5 ..= 6 => { } //~ ERROR multiple patterns covering the same range
6+
5 ..= 6 => { }
7+
//~^ ERROR unreachable pattern
8+
//~| ERROR multiple patterns covering the same range
79
_ => {}
810
};
911

1012
match 5 {
1113
3 ..= 6 => { }
12-
4 ..= 6 => { } //~ ERROR multiple patterns covering the same range
14+
4 ..= 6 => { }
15+
//~^ ERROR unreachable pattern
16+
//~| ERROR multiple patterns covering the same range
1317
_ => {}
1418
};
1519

1620
match 5 {
1721
4 ..= 6 => { }
18-
4 ..= 6 => { } //~ ERROR multiple patterns covering the same range
22+
4 ..= 6 => { }
23+
//~^ ERROR unreachable pattern
24+
//~| ERROR multiple patterns covering the same range
1925
_ => {}
2026
};
2127

2228
match 'c' {
2329
'A' ..= 'z' => {}
24-
'a' ..= 'z' => {} //~ ERROR multiple patterns covering the same range
30+
'a' ..= 'z' => {}
31+
//~^ ERROR unreachable pattern
32+
//~| ERROR multiple patterns covering the same range
2533
_ => {}
2634
};
2735

src/test/ui/match/match-range-fail-dominate.stderr

+39-15
Original file line numberDiff line numberDiff line change
@@ -12,32 +12,62 @@ note: lint level defined here
1212
LL | #![deny(unreachable_patterns, overlapping_patterns)]
1313
| ^^^^^^^^^^^^^^^^^^^^
1414

15+
error: unreachable pattern
16+
--> $DIR/match-range-fail-dominate.rs:6:7
17+
|
18+
LL | 5 ..= 6 => { }
19+
| ^^^^^^^
20+
|
21+
note: lint level defined here
22+
--> $DIR/match-range-fail-dominate.rs:1:9
23+
|
24+
LL | #![deny(unreachable_patterns, overlapping_patterns)]
25+
| ^^^^^^^^^^^^^^^^^^^^
26+
1527
error: multiple patterns covering the same range
16-
--> $DIR/match-range-fail-dominate.rs:12:7
28+
--> $DIR/match-range-fail-dominate.rs:14:7
1729
|
1830
LL | 3 ..= 6 => { }
1931
| ------- this range overlaps on `4i32..=6i32`
2032
LL | 4 ..= 6 => { }
2133
| ^^^^^^^ overlapping patterns
2234

35+
error: unreachable pattern
36+
--> $DIR/match-range-fail-dominate.rs:14:7
37+
|
38+
LL | 4 ..= 6 => { }
39+
| ^^^^^^^
40+
2341
error: multiple patterns covering the same range
24-
--> $DIR/match-range-fail-dominate.rs:18:7
42+
--> $DIR/match-range-fail-dominate.rs:22:7
2543
|
2644
LL | 4 ..= 6 => { }
2745
| ------- this range overlaps on `4i32..=6i32`
2846
LL | 4 ..= 6 => { }
2947
| ^^^^^^^ overlapping patterns
3048

49+
error: unreachable pattern
50+
--> $DIR/match-range-fail-dominate.rs:22:7
51+
|
52+
LL | 4 ..= 6 => { }
53+
| ^^^^^^^
54+
3155
error: multiple patterns covering the same range
32-
--> $DIR/match-range-fail-dominate.rs:24:7
56+
--> $DIR/match-range-fail-dominate.rs:30:7
3357
|
3458
LL | 'A' ..= 'z' => {}
3559
| ----------- this range overlaps on `'a'..='z'`
3660
LL | 'a' ..= 'z' => {}
3761
| ^^^^^^^^^^^ overlapping patterns
3862

63+
error: unreachable pattern
64+
--> $DIR/match-range-fail-dominate.rs:30:7
65+
|
66+
LL | 'a' ..= 'z' => {}
67+
| ^^^^^^^^^^^
68+
3969
warning: floating-point types cannot be used in patterns
40-
--> $DIR/match-range-fail-dominate.rs:29:7
70+
--> $DIR/match-range-fail-dominate.rs:37:7
4171
|
4272
LL | 0.01f64 ..= 6.5f64 => {}
4373
| ^^^^^^^
@@ -47,7 +77,7 @@ LL | 0.01f64 ..= 6.5f64 => {}
4777
= note: for more information, see issue #41620 <https://github.com/rust-lang/rust/issues/41620>
4878

4979
warning: floating-point types cannot be used in patterns
50-
--> $DIR/match-range-fail-dominate.rs:29:19
80+
--> $DIR/match-range-fail-dominate.rs:37:19
5181
|
5282
LL | 0.01f64 ..= 6.5f64 => {}
5383
| ^^^^^^
@@ -56,7 +86,7 @@ LL | 0.01f64 ..= 6.5f64 => {}
5686
= note: for more information, see issue #41620 <https://github.com/rust-lang/rust/issues/41620>
5787

5888
warning: floating-point types cannot be used in patterns
59-
--> $DIR/match-range-fail-dominate.rs:36:7
89+
--> $DIR/match-range-fail-dominate.rs:44:7
6090
|
6191
LL | 0.02f64 => {}
6292
| ^^^^^^^
@@ -65,25 +95,19 @@ LL | 0.02f64 => {}
6595
= note: for more information, see issue #41620 <https://github.com/rust-lang/rust/issues/41620>
6696

6797
error: unreachable pattern
68-
--> $DIR/match-range-fail-dominate.rs:36:7
98+
--> $DIR/match-range-fail-dominate.rs:44:7
6999
|
70100
LL | 0.02f64 => {}
71101
| ^^^^^^^
72-
|
73-
note: lint level defined here
74-
--> $DIR/match-range-fail-dominate.rs:1:9
75-
|
76-
LL | #![deny(unreachable_patterns, overlapping_patterns)]
77-
| ^^^^^^^^^^^^^^^^^^^^
78102

79103
warning: floating-point types cannot be used in patterns
80-
--> $DIR/match-range-fail-dominate.rs:29:7
104+
--> $DIR/match-range-fail-dominate.rs:37:7
81105
|
82106
LL | 0.01f64 ..= 6.5f64 => {}
83107
| ^^^^^^^
84108
|
85109
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
86110
= note: for more information, see issue #41620 <https://github.com/rust-lang/rust/issues/41620>
87111

88-
error: aborting due to 5 previous errors
112+
error: aborting due to 9 previous errors
89113

0 commit comments

Comments
 (0)