Rollup merge of #64007 - estebank:overlapping-patterns, r=matthewjasper
Add check for overlapping ranges to unreachable patterns lint Fix #63987.
This commit is contained in:
commit
53a3bfc82b
17 changed files with 317 additions and 115 deletions
|
|
@ -1,7 +1,7 @@
|
|||
// build-pass (FIXME(62277): could be check-pass?)
|
||||
|
||||
// check-pass
|
||||
#![feature(exclusive_range_pattern)]
|
||||
#![warn(unreachable_patterns)]
|
||||
#![warn(overlapping_patterns)]
|
||||
|
||||
fn main() {
|
||||
// These cases should generate no warning.
|
||||
|
|
@ -13,7 +13,7 @@ fn main() {
|
|||
|
||||
match 10 {
|
||||
1..10 => {},
|
||||
9..=10 => {},
|
||||
9..=10 => {}, //~ WARNING multiple patterns covering the same range
|
||||
_ => {},
|
||||
}
|
||||
|
||||
|
|
@ -23,22 +23,25 @@ fn main() {
|
|||
_ => {},
|
||||
}
|
||||
|
||||
// These cases should generate an "unreachable pattern" warning.
|
||||
// These cases should generate "unreachable pattern" warnings.
|
||||
match 10 {
|
||||
1..10 => {},
|
||||
9 => {},
|
||||
9 => {}, //~ WARNING unreachable pattern
|
||||
_ => {},
|
||||
}
|
||||
|
||||
match 10 {
|
||||
1..10 => {},
|
||||
8..=9 => {},
|
||||
8..=9 => {}, //~ WARNING multiple patterns covering the same range
|
||||
_ => {},
|
||||
}
|
||||
|
||||
match 10 {
|
||||
1..10 => {},
|
||||
9..=9 => {},
|
||||
5..7 => {},
|
||||
6 => {}, //~ WARNING unreachable pattern
|
||||
1..10 => {}, //~ WARNING multiple patterns covering the same range
|
||||
9..=9 => {}, //~ WARNING unreachable pattern
|
||||
6 => {}, //~ WARNING unreachable pattern
|
||||
_ => {},
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,17 @@
|
|||
warning: multiple patterns covering the same range
|
||||
--> $DIR/issue-43253.rs:16:9
|
||||
|
|
||||
LL | 1..10 => {},
|
||||
| ----- this range overlaps on `9i32`
|
||||
LL | 9..=10 => {},
|
||||
| ^^^^^^ overlapping patterns
|
||||
|
|
||||
note: lint level defined here
|
||||
--> $DIR/issue-43253.rs:4:9
|
||||
|
|
||||
LL | #![warn(overlapping_patterns)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
warning: unreachable pattern
|
||||
--> $DIR/issue-43253.rs:29:9
|
||||
|
|
||||
|
|
@ -5,7 +19,7 @@ LL | 9 => {},
|
|||
| ^
|
||||
|
|
||||
note: lint level defined here
|
||||
--> $DIR/issue-43253.rs:4:9
|
||||
--> $DIR/issue-43253.rs:3:9
|
||||
|
|
||||
LL | #![warn(unreachable_patterns)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
@ -19,6 +33,18 @@ LL | 8..=9 => {},
|
|||
warning: unreachable pattern
|
||||
--> $DIR/issue-43253.rs:41:9
|
||||
|
|
||||
LL | 6 => {},
|
||||
| ^
|
||||
|
||||
warning: unreachable pattern
|
||||
--> $DIR/issue-43253.rs:43:9
|
||||
|
|
||||
LL | 9..=9 => {},
|
||||
| ^^^^^
|
||||
|
||||
warning: unreachable pattern
|
||||
--> $DIR/issue-43253.rs:44:9
|
||||
|
|
||||
LL | 6 => {},
|
||||
| ^
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
#![feature(precise_pointer_size_matching)]
|
||||
#![feature(exclusive_range_pattern)]
|
||||
|
||||
#![deny(unreachable_patterns)]
|
||||
#![deny(overlapping_patterns)]
|
||||
|
||||
use std::{char, u8, u16, u32, u64, u128, i8, i16, i32, i64, i128};
|
||||
|
||||
|
|
@ -41,7 +41,8 @@ fn main() {
|
|||
match x { //~ ERROR non-exhaustive patterns
|
||||
-7 => {}
|
||||
-5..=120 => {}
|
||||
-2..=20 => {} //~ ERROR unreachable pattern
|
||||
-2..=20 => {}
|
||||
//~^ ERROR unreachable pattern
|
||||
125 => {}
|
||||
}
|
||||
|
||||
|
|
@ -135,9 +136,9 @@ fn main() {
|
|||
(125 .. 128, false) => {}
|
||||
}
|
||||
|
||||
match 0u8 { // ok
|
||||
match 0u8 {
|
||||
0 .. 2 => {}
|
||||
1 ..= 2 => {}
|
||||
1 ..= 2 => {} //~ ERROR multiple patterns covering the same range
|
||||
_ => {}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ LL | 200 => {}
|
|||
| ^^^
|
||||
|
|
||||
note: lint level defined here
|
||||
--> $DIR/exhaustive_integer_patterns.rs:4:9
|
||||
--> $DIR/exhaustive_integer_patterns.rs:3:9
|
||||
|
|
||||
LL | #![deny(unreachable_patterns)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
@ -41,7 +41,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:83:11
|
||||
|
|
||||
LL | match 0i8 {
|
||||
| ^^^ pattern `std::i8::MIN` not covered
|
||||
|
|
@ -49,7 +49,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:91:11
|
||||
|
|
||||
LL | match 0i16 {
|
||||
| ^^^^ pattern `0i16` not covered
|
||||
|
|
@ -57,7 +57,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:109:11
|
||||
|
|
||||
LL | match 0u8 {
|
||||
| ^^^ pattern `128u8..=std::u8::MAX` not covered
|
||||
|
|
@ -65,7 +65,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:121:11
|
||||
|
|
||||
LL | match (0u8, Some(())) {
|
||||
| ^^^^^^^^^^^^^^^ patterns `(0u8, Some(_))` and `(2u8..=std::u8::MAX, Some(_))` not covered
|
||||
|
|
@ -73,15 +73,29 @@ 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:126: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:141:9
|
||||
|
|
||||
LL | 0 .. 2 => {}
|
||||
| ------ this range overlaps on `1u8`
|
||||
LL | 1 ..= 2 => {}
|
||||
| ^^^^^^^ overlapping patterns
|
||||
|
|
||||
note: lint level defined here
|
||||
--> $DIR/exhaustive_integer_patterns.rs:4:9
|
||||
|
|
||||
LL | #![deny(overlapping_patterns)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error[E0004]: non-exhaustive patterns: `std::u128::MAX` not covered
|
||||
--> $DIR/exhaustive_integer_patterns.rs:145:11
|
||||
--> $DIR/exhaustive_integer_patterns.rs:146:11
|
||||
|
|
||||
LL | match 0u128 {
|
||||
| ^^^^^ pattern `std::u128::MAX` not covered
|
||||
|
|
@ -89,7 +103,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:150:11
|
||||
|
|
||||
LL | match 0u128 {
|
||||
| ^^^^^ pattern `5u128..=std::u128::MAX` not covered
|
||||
|
|
@ -97,13 +111,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:154: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 13 previous errors
|
||||
error: aborting due to 14 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0004`.
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
// Test that codegen works correctly when there are multiple refutable
|
||||
// patterns in match expression.
|
||||
|
||||
|
||||
enum Foo {
|
||||
FooUint(usize),
|
||||
FooNullary,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
// run-pass
|
||||
#![allow(unused_imports)]
|
||||
#![allow(unused_imports, overlapping_patterns)]
|
||||
// pretty-expanded FIXME #23616
|
||||
|
||||
use m::{START, END};
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
// run-pass
|
||||
#![allow(overlapping_patterns)]
|
||||
|
||||
fn main() {
|
||||
let x = 'a';
|
||||
|
||||
|
|
|
|||
|
|
@ -1,39 +1,45 @@
|
|||
//error-pattern: unreachable
|
||||
//error-pattern: unreachable
|
||||
//error-pattern: unreachable
|
||||
//error-pattern: unreachable
|
||||
//error-pattern: unreachable
|
||||
|
||||
#![deny(unreachable_patterns)]
|
||||
#![deny(unreachable_patterns, overlapping_patterns)]
|
||||
|
||||
fn main() {
|
||||
match 5 {
|
||||
1 ..= 10 => { }
|
||||
5 ..= 6 => { }
|
||||
//~^ ERROR unreachable pattern
|
||||
_ => {}
|
||||
};
|
||||
|
||||
match 5 {
|
||||
3 ..= 6 => { }
|
||||
4 ..= 6 => { }
|
||||
//~^ ERROR unreachable pattern
|
||||
_ => {}
|
||||
};
|
||||
|
||||
match 5 {
|
||||
4 ..= 6 => { }
|
||||
4 ..= 6 => { }
|
||||
//~^ ERROR unreachable pattern
|
||||
_ => {}
|
||||
};
|
||||
|
||||
match 'c' {
|
||||
'A' ..= 'z' => {}
|
||||
'a' ..= 'z' => {}
|
||||
//~^ ERROR unreachable pattern
|
||||
_ => {}
|
||||
};
|
||||
|
||||
match 1.0f64 {
|
||||
0.01f64 ..= 6.5f64 => {}
|
||||
0.02f64 => {}
|
||||
//~^ WARNING floating-point types cannot be used in patterns
|
||||
//~| WARNING floating-point types cannot be used in patterns
|
||||
//~| WARNING floating-point types cannot be used in patterns
|
||||
//~| WARNING this was previously accepted by the compiler
|
||||
//~| WARNING this was previously accepted by the compiler
|
||||
//~| WARNING this was previously accepted by the compiler
|
||||
0.02f64 => {} //~ ERROR unreachable pattern
|
||||
//~^ WARNING floating-point types cannot be used in patterns
|
||||
//~| WARNING this was previously accepted by the compiler
|
||||
_ => {}
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,35 +1,35 @@
|
|||
error: unreachable pattern
|
||||
--> $DIR/match-range-fail-dominate.rs:12:7
|
||||
--> $DIR/match-range-fail-dominate.rs:6:7
|
||||
|
|
||||
LL | 5 ..= 6 => { }
|
||||
| ^^^^^^^
|
||||
|
|
||||
note: lint level defined here
|
||||
--> $DIR/match-range-fail-dominate.rs:7:9
|
||||
--> $DIR/match-range-fail-dominate.rs:1:9
|
||||
|
|
||||
LL | #![deny(unreachable_patterns)]
|
||||
LL | #![deny(unreachable_patterns, overlapping_patterns)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: unreachable pattern
|
||||
--> $DIR/match-range-fail-dominate.rs:18:7
|
||||
--> $DIR/match-range-fail-dominate.rs:13:7
|
||||
|
|
||||
LL | 4 ..= 6 => { }
|
||||
| ^^^^^^^
|
||||
|
||||
error: unreachable pattern
|
||||
--> $DIR/match-range-fail-dominate.rs:24:7
|
||||
--> $DIR/match-range-fail-dominate.rs:20:7
|
||||
|
|
||||
LL | 4 ..= 6 => { }
|
||||
| ^^^^^^^
|
||||
|
||||
error: unreachable pattern
|
||||
--> $DIR/match-range-fail-dominate.rs:30:7
|
||||
--> $DIR/match-range-fail-dominate.rs:27:7
|
||||
|
|
||||
LL | 'a' ..= 'z' => {}
|
||||
| ^^^^^^^^^^^
|
||||
|
||||
warning: floating-point types cannot be used in patterns
|
||||
--> $DIR/match-range-fail-dominate.rs:35:7
|
||||
--> $DIR/match-range-fail-dominate.rs:33:7
|
||||
|
|
||||
LL | 0.01f64 ..= 6.5f64 => {}
|
||||
| ^^^^^^^
|
||||
|
|
@ -39,7 +39,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:35:19
|
||||
--> $DIR/match-range-fail-dominate.rs:33:19
|
||||
|
|
||||
LL | 0.01f64 ..= 6.5f64 => {}
|
||||
| ^^^^^^
|
||||
|
|
@ -48,7 +48,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:40:7
|
||||
|
|
||||
LL | 0.02f64 => {}
|
||||
| ^^^^^^^
|
||||
|
|
@ -57,13 +57,13 @@ 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:40:7
|
||||
|
|
||||
LL | 0.02f64 => {}
|
||||
| ^^^^^^^
|
||||
|
||||
warning: floating-point types cannot be used in patterns
|
||||
--> $DIR/match-range-fail-dominate.rs:35:7
|
||||
--> $DIR/match-range-fail-dominate.rs:33:7
|
||||
|
|
||||
LL | 0.01f64 ..= 6.5f64 => {}
|
||||
| ^^^^^^^
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
#![feature(precise_pointer_size_matching)]
|
||||
#![feature(exclusive_range_pattern)]
|
||||
|
||||
#![deny(unreachable_patterns)]
|
||||
#![deny(unreachable_patterns, overlapping_patterns)]
|
||||
|
||||
use std::{usize, isize};
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ pub fn main() {
|
|||
let i = 5;
|
||||
match &&&&i {
|
||||
1 ..= 3 => panic!(),
|
||||
3 ..= 8 => {},
|
||||
4 ..= 8 => {},
|
||||
_ => panic!(),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue