diff --git a/src/librustc_mir/hair/pattern/check_match.rs b/src/librustc_mir/hair/pattern/check_match.rs index d6ec155c96303..7bc4bf291ee48 100644 --- a/src/librustc_mir/hair/pattern/check_match.rs +++ b/src/librustc_mir/hair/pattern/check_match.rs @@ -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, diff --git a/src/test/ui/check_match/issue-43253.stderr b/src/test/ui/check_match/issue-43253.stderr index 2f6888c0118aa..ca4cd89732276 100644 --- a/src/test/ui/check_match/issue-43253.stderr +++ b/src/test/ui/check_match/issue-43253.stderr @@ -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 | diff --git a/src/test/ui/exhaustive_integer_patterns.rs b/src/test/ui/exhaustive_integer_patterns.rs index ef88ce94aa6a2..a0c1b013f390a 100644 --- a/src/test/ui/exhaustive_integer_patterns.rs +++ b/src/test/ui/exhaustive_integer_patterns.rs @@ -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 => {} } diff --git a/src/test/ui/exhaustive_integer_patterns.stderr b/src/test/ui/exhaustive_integer_patterns.stderr index 59cd3fffa8df5..44fbc96922571 100644 --- a/src/test/ui/exhaustive_integer_patterns.stderr +++ b/src/test/ui/exhaustive_integer_patterns.stderr @@ -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 | @@ -57,7 +63,7 @@ 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 @@ -65,7 +71,7 @@ LL | match 0i8 { = 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 @@ -73,7 +79,7 @@ LL | match 0i16 { = 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 @@ -81,7 +87,7 @@ LL | match 0u8 { = 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 @@ -89,7 +95,7 @@ LL | match (0u8, Some(())) { = 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 @@ -97,7 +103,7 @@ LL | match (0u8, true) { = 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` @@ -105,7 +111,7 @@ 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 @@ -113,7 +119,7 @@ LL | match 0u128 { = 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 @@ -121,13 +127,13 @@ LL | match 0u128 { = 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`. diff --git a/src/test/ui/match/match-range-fail-dominate.rs b/src/test/ui/match/match-range-fail-dominate.rs index bdbb1f050a7a3..b6a89b8910c49 100644 --- a/src/test/ui/match/match-range-fail-dominate.rs +++ b/src/test/ui/match/match-range-fail-dominate.rs @@ -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 _ => {} }; diff --git a/src/test/ui/match/match-range-fail-dominate.stderr b/src/test/ui/match/match-range-fail-dominate.stderr index b14e9b5008d9d..4a76e05fab53e 100644 --- a/src/test/ui/match/match-range-fail-dominate.stderr +++ b/src/test/ui/match/match-range-fail-dominate.stderr @@ -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 => {} | ^^^^^^^ @@ -47,7 +77,7 @@ LL | 0.01f64 ..= 6.5f64 => {} = note: for more information, see issue #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 => {} | ^^^^^^ @@ -56,7 +86,7 @@ LL | 0.01f64 ..= 6.5f64 => {} = note: for more information, see issue #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 => {} | ^^^^^^^ @@ -65,19 +95,13 @@ LL | 0.02f64 => {} = note: for more information, see issue #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 => {} | ^^^^^^^ @@ -85,5 +109,5 @@ 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 -error: aborting due to 5 previous errors +error: aborting due to 9 previous errors