Skip to content

Commit

Permalink
Continue to emit unreachable pattern on cases caught by overlapping p…
Browse files Browse the repository at this point in the history
…atterns
  • Loading branch information
estebank committed Oct 16, 2019
1 parent 6832da8 commit 89b19cc
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 34 deletions.
4 changes: 0 additions & 4 deletions src/librustc_mir/hair/pattern/check_match.rs
Expand Up @@ -429,10 +429,6 @@ fn check_arms<'tcx>(

hir::MatchSource::ForLoopDesugar |
hir::MatchSource::Normal => {
if let box PatternKind::Range(..) = pat.kind {
// Covered by `overlapping_patterns` with more context
break;
}
let mut err = cx.tcx.struct_span_lint_hir(
lint::builtin::UNREACHABLE_PATTERNS,
hir_pat.hir_id,
Expand Down
6 changes: 6 additions & 0 deletions src/test/ui/check_match/issue-43253.stderr
Expand Up @@ -32,6 +32,12 @@ LL | 1..10 => {},
LL | 8..=9 => {},
| ^^^^^ overlapping patterns

warning: unreachable pattern
--> $DIR/issue-43253.rs:35:9
|
LL | 8..=9 => {},
| ^^^^^

warning: unreachable pattern
--> $DIR/issue-43253.rs:41:9
|
Expand Down
4 changes: 3 additions & 1 deletion src/test/ui/exhaustive_integer_patterns.rs
Expand Up @@ -41,7 +41,9 @@ fn main() {
match x { //~ ERROR non-exhaustive patterns
-7 => {}
-5..=120 => {}
-2..=20 => {} //~ ERROR multiple patterns covering the same range
-2..=20 => {}
//~^ ERROR unreachable pattern
//~| ERROR multiple patterns covering the same range
125 => {}
}

Expand Down
26 changes: 16 additions & 10 deletions src/test/ui/exhaustive_integer_patterns.stderr
Expand Up @@ -48,6 +48,12 @@ LL | -5..=120 => {}
LL | -2..=20 => {}
| ^^^^^^^ overlapping patterns

error: unreachable pattern
--> $DIR/exhaustive_integer_patterns.rs:44:9
|
LL | -2..=20 => {}
| ^^^^^^^

error[E0004]: non-exhaustive patterns: `std::i8::MIN..=-8i8`, `-6i8`, `121i8..=124i8` and 1 more not covered
--> $DIR/exhaustive_integer_patterns.rs:41:11
|
Expand All @@ -57,77 +63,77 @@ LL | match x {
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms

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

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

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

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

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

error: multiple patterns covering the same range
--> $DIR/exhaustive_integer_patterns.rs:140:9
--> $DIR/exhaustive_integer_patterns.rs:142:9
|
LL | 0 .. 2 => {}
| ------ this range overlaps on `1u8`
LL | 1 ..= 2 => {}
| ^^^^^^^ overlapping patterns

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

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

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

error: aborting due to 15 previous errors
error: aborting due to 16 previous errors

For more information about this error, try `rustc --explain E0004`.
16 changes: 12 additions & 4 deletions src/test/ui/match/match-range-fail-dominate.rs
Expand Up @@ -3,25 +3,33 @@
fn main() {
match 5 {
1 ..= 10 => { }
5 ..= 6 => { } //~ ERROR multiple patterns covering the same range
5 ..= 6 => { }
//~^ ERROR unreachable pattern
//~| ERROR multiple patterns covering the same range
_ => {}
};

match 5 {
3 ..= 6 => { }
4 ..= 6 => { } //~ ERROR multiple patterns covering the same range
4 ..= 6 => { }
//~^ ERROR unreachable pattern
//~| ERROR multiple patterns covering the same range
_ => {}
};

match 5 {
4 ..= 6 => { }
4 ..= 6 => { } //~ ERROR multiple patterns covering the same range
4 ..= 6 => { }
//~^ ERROR unreachable pattern
//~| ERROR multiple patterns covering the same range
_ => {}
};

match 'c' {
'A' ..= 'z' => {}
'a' ..= 'z' => {} //~ ERROR multiple patterns covering the same range
'a' ..= 'z' => {}
//~^ ERROR unreachable pattern
//~| ERROR multiple patterns covering the same range
_ => {}
};

Expand Down
54 changes: 39 additions & 15 deletions src/test/ui/match/match-range-fail-dominate.stderr
Expand Up @@ -12,32 +12,62 @@ note: lint level defined here
LL | #![deny(unreachable_patterns, overlapping_patterns)]
| ^^^^^^^^^^^^^^^^^^^^

error: unreachable pattern
--> $DIR/match-range-fail-dominate.rs:6:7
|
LL | 5 ..= 6 => { }
| ^^^^^^^
|
note: lint level defined here
--> $DIR/match-range-fail-dominate.rs:1:9
|
LL | #![deny(unreachable_patterns, overlapping_patterns)]
| ^^^^^^^^^^^^^^^^^^^^

error: multiple patterns covering the same range
--> $DIR/match-range-fail-dominate.rs:12:7
--> $DIR/match-range-fail-dominate.rs:14:7
|
LL | 3 ..= 6 => { }
| ------- this range overlaps on `4i32..=6i32`
LL | 4 ..= 6 => { }
| ^^^^^^^ overlapping patterns

error: unreachable pattern
--> $DIR/match-range-fail-dominate.rs:14:7
|
LL | 4 ..= 6 => { }
| ^^^^^^^

error: multiple patterns covering the same range
--> $DIR/match-range-fail-dominate.rs:18:7
--> $DIR/match-range-fail-dominate.rs:22:7
|
LL | 4 ..= 6 => { }
| ------- this range overlaps on `4i32..=6i32`
LL | 4 ..= 6 => { }
| ^^^^^^^ overlapping patterns

error: unreachable pattern
--> $DIR/match-range-fail-dominate.rs:22:7
|
LL | 4 ..= 6 => { }
| ^^^^^^^

error: multiple patterns covering the same range
--> $DIR/match-range-fail-dominate.rs:24:7
--> $DIR/match-range-fail-dominate.rs:30:7
|
LL | 'A' ..= 'z' => {}
| ----------- this range overlaps on `'a'..='z'`
LL | 'a' ..= 'z' => {}
| ^^^^^^^^^^^ overlapping patterns

error: unreachable pattern
--> $DIR/match-range-fail-dominate.rs:30:7
|
LL | 'a' ..= 'z' => {}
| ^^^^^^^^^^^

warning: floating-point types cannot be used in patterns
--> $DIR/match-range-fail-dominate.rs:29:7
--> $DIR/match-range-fail-dominate.rs:37:7
|
LL | 0.01f64 ..= 6.5f64 => {}
| ^^^^^^^
Expand All @@ -47,7 +77,7 @@ LL | 0.01f64 ..= 6.5f64 => {}
= note: for more information, see issue #41620 <https://github.com/rust-lang/rust/issues/41620>

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

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

error: unreachable pattern
--> $DIR/match-range-fail-dominate.rs:36:7
--> $DIR/match-range-fail-dominate.rs:44:7
|
LL | 0.02f64 => {}
| ^^^^^^^
|
note: lint level defined here
--> $DIR/match-range-fail-dominate.rs:1:9
|
LL | #![deny(unreachable_patterns, overlapping_patterns)]
| ^^^^^^^^^^^^^^^^^^^^

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

error: aborting due to 5 previous errors
error: aborting due to 9 previous errors

0 comments on commit 89b19cc

Please sign in to comment.