Skip to content

Commit 220b9b2

Browse files
committed
Move overlapping patterns to its own lint
1 parent 91a3db9 commit 220b9b2

File tree

12 files changed

+40
-14
lines changed

12 files changed

+40
-14
lines changed

src/libcore/ascii.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ pub fn escape_default(c: u8) -> EscapeDefault {
101101
b'\'' => ([b'\\', b'\'', 0, 0], 2),
102102
b'"' => ([b'\\', b'"', 0, 0], 2),
103103
// The three arms above are in the following range
104-
#[allow(unreachable_patterns)]
104+
#[allow(overlapping_patterns)]
105105
b'\x20' ..= b'\x7e' => ([c, 0, 0, 0], 1),
106106
_ => ([b'\\', b'x', hexify(c >> 4), hexify(c & 0xf)], 4),
107107
};

src/librustc/lint/builtin.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ declare_lint! {
8080
"detects unreachable patterns"
8181
}
8282

83+
declare_lint! {
84+
pub OVERLAPPING_PATTERNS,
85+
Warn,
86+
"detects overlapping patterns"
87+
}
88+
8389
declare_lint! {
8490
pub UNUSED_MACROS,
8591
Warn,
@@ -423,6 +429,7 @@ declare_lint_pass! {
423429
DEAD_CODE,
424430
UNREACHABLE_CODE,
425431
UNREACHABLE_PATTERNS,
432+
OVERLAPPING_PATTERNS,
426433
UNUSED_MACROS,
427434
WARNINGS,
428435
UNUSED_FEATURES,

src/librustc_lint/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
255255
UNUSED_MUT,
256256
UNREACHABLE_CODE,
257257
UNREACHABLE_PATTERNS,
258+
OVERLAPPING_PATTERNS,
258259
UNUSED_MUST_USE,
259260
UNUSED_UNSAFE,
260261
PATH_STATEMENTS,

src/librustc_mir/hair/pattern/_match.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1741,7 +1741,7 @@ fn split_grouped_constructors<'p, 'tcx>(
17411741

17421742
if let (true, Some(hir_id)) = (!overlaps.is_empty(), hir_id) {
17431743
let mut err = tcx.struct_span_lint_hir(
1744-
lint::builtin::UNREACHABLE_PATTERNS,
1744+
lint::builtin::OVERLAPPING_PATTERNS,
17451745
hir_id,
17461746
ctor_range.span,
17471747
"multiple patterns covering the same range",

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// check-pass
2-
32
#![feature(exclusive_range_pattern)]
43
#![warn(unreachable_patterns)]
4+
#![warn(overlapping_patterns)]
55

66
fn main() {
77
// These cases should generate no warning.

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,20 @@ LL | 9..=10 => {},
99
note: lint level defined here
1010
--> $DIR/issue-43253.rs:4:9
1111
|
12-
LL | #![warn(unreachable_patterns)]
12+
LL | #![warn(overlapping_patterns)]
1313
| ^^^^^^^^^^^^^^^^^^^^
1414

1515
warning: unreachable pattern
1616
--> $DIR/issue-43253.rs:29:9
1717
|
1818
LL | 9 => {},
1919
| ^
20+
|
21+
note: lint level defined here
22+
--> $DIR/issue-43253.rs:3:9
23+
|
24+
LL | #![warn(unreachable_patterns)]
25+
| ^^^^^^^^^^^^^^^^^^^^
2026

2127
warning: multiple patterns covering the same range
2228
--> $DIR/issue-43253.rs:35:9

src/test/ui/exhaustive_integer_patterns.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#![feature(precise_pointer_size_matching)]
22
#![feature(exclusive_range_pattern)]
3-
43
#![deny(unreachable_patterns)]
4+
#![deny(overlapping_patterns)]
55

66
use std::{char, u8, u16, u32, u64, u128, i8, i16, i32, i64, i128};
77

src/test/ui/exhaustive_integer_patterns.stderr

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,20 @@ LL | 100 ..= 200 => {}
99
note: lint level defined here
1010
--> $DIR/exhaustive_integer_patterns.rs:4:9
1111
|
12-
LL | #![deny(unreachable_patterns)]
12+
LL | #![deny(overlapping_patterns)]
1313
| ^^^^^^^^^^^^^^^^^^^^
1414

1515
error: unreachable pattern
1616
--> $DIR/exhaustive_integer_patterns.rs:23:9
1717
|
1818
LL | 200 => {}
1919
| ^^^
20+
|
21+
note: lint level defined here
22+
--> $DIR/exhaustive_integer_patterns.rs:3:9
23+
|
24+
LL | #![deny(unreachable_patterns)]
25+
| ^^^^^^^^^^^^^^^^^^^^
2026

2127
error[E0004]: non-exhaustive patterns: `128u8..=std::u8::MAX` not covered
2228
--> $DIR/exhaustive_integer_patterns.rs:28:11

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![deny(unreachable_patterns)]
1+
#![deny(unreachable_patterns, overlapping_patterns)]
22

33
fn main() {
44
match 5 {

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ LL | 5 ..= 6 => { }
77
| ^^^^^^^ overlapping patterns
88
|
99
note: lint level defined here
10-
--> $DIR/match-range-fail-dominate.rs:1:9
10+
--> $DIR/match-range-fail-dominate.rs:1:31
1111
|
12-
LL | #![deny(unreachable_patterns)]
13-
| ^^^^^^^^^^^^^^^^^^^^
12+
LL | #![deny(unreachable_patterns, overlapping_patterns)]
13+
| ^^^^^^^^^^^^^^^^^^^^
1414

1515
error: multiple patterns covering the same range
1616
--> $DIR/match-range-fail-dominate.rs:12:7
@@ -69,6 +69,12 @@ error: unreachable pattern
6969
|
7070
LL | 0.02f64 => {}
7171
| ^^^^^^^
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+
| ^^^^^^^^^^^^^^^^^^^^
7278

7379
warning: floating-point types cannot be used in patterns
7480
--> $DIR/match-range-fail-dominate.rs:29:7

0 commit comments

Comments
 (0)