Move overlapping patterns to its own lint
This commit is contained in:
parent
91a3db95a1
commit
220b9b29c2
@ -101,7 +101,7 @@ pub fn escape_default(c: u8) -> EscapeDefault {
|
||||
b'\'' => ([b'\\', b'\'', 0, 0], 2),
|
||||
b'"' => ([b'\\', b'"', 0, 0], 2),
|
||||
// The three arms above are in the following range
|
||||
#[allow(unreachable_patterns)]
|
||||
#[allow(overlapping_patterns)]
|
||||
b'\x20' ..= b'\x7e' => ([c, 0, 0, 0], 1),
|
||||
_ => ([b'\\', b'x', hexify(c >> 4), hexify(c & 0xf)], 4),
|
||||
};
|
||||
|
@ -80,6 +80,12 @@ declare_lint! {
|
||||
"detects unreachable patterns"
|
||||
}
|
||||
|
||||
declare_lint! {
|
||||
pub OVERLAPPING_PATTERNS,
|
||||
Warn,
|
||||
"detects overlapping patterns"
|
||||
}
|
||||
|
||||
declare_lint! {
|
||||
pub UNUSED_MACROS,
|
||||
Warn,
|
||||
@ -423,6 +429,7 @@ declare_lint_pass! {
|
||||
DEAD_CODE,
|
||||
UNREACHABLE_CODE,
|
||||
UNREACHABLE_PATTERNS,
|
||||
OVERLAPPING_PATTERNS,
|
||||
UNUSED_MACROS,
|
||||
WARNINGS,
|
||||
UNUSED_FEATURES,
|
||||
|
@ -255,6 +255,7 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
|
||||
UNUSED_MUT,
|
||||
UNREACHABLE_CODE,
|
||||
UNREACHABLE_PATTERNS,
|
||||
OVERLAPPING_PATTERNS,
|
||||
UNUSED_MUST_USE,
|
||||
UNUSED_UNSAFE,
|
||||
PATH_STATEMENTS,
|
||||
|
@ -1741,7 +1741,7 @@ fn split_grouped_constructors<'p, 'tcx>(
|
||||
|
||||
if let (true, Some(hir_id)) = (!overlaps.is_empty(), hir_id) {
|
||||
let mut err = tcx.struct_span_lint_hir(
|
||||
lint::builtin::UNREACHABLE_PATTERNS,
|
||||
lint::builtin::OVERLAPPING_PATTERNS,
|
||||
hir_id,
|
||||
ctor_range.span,
|
||||
"multiple patterns covering the same range",
|
||||
|
@ -1,7 +1,7 @@
|
||||
// check-pass
|
||||
|
||||
#![feature(exclusive_range_pattern)]
|
||||
#![warn(unreachable_patterns)]
|
||||
#![warn(overlapping_patterns)]
|
||||
|
||||
fn main() {
|
||||
// These cases should generate no warning.
|
||||
|
@ -9,7 +9,7 @@ LL | 9..=10 => {},
|
||||
note: lint level defined here
|
||||
--> $DIR/issue-43253.rs:4:9
|
||||
|
|
||||
LL | #![warn(unreachable_patterns)]
|
||||
LL | #![warn(overlapping_patterns)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
warning: unreachable pattern
|
||||
@ -17,6 +17,12 @@ warning: unreachable pattern
|
||||
|
|
||||
LL | 9 => {},
|
||||
| ^
|
||||
|
|
||||
note: lint level defined here
|
||||
--> $DIR/issue-43253.rs:3:9
|
||||
|
|
||||
LL | #![warn(unreachable_patterns)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
warning: multiple patterns covering the same range
|
||||
--> $DIR/issue-43253.rs:35:9
|
||||
|
@ -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};
|
||||
|
||||
|
@ -9,7 +9,7 @@ LL | 100 ..= 200 => {}
|
||||
note: lint level defined here
|
||||
--> $DIR/exhaustive_integer_patterns.rs:4:9
|
||||
|
|
||||
LL | #![deny(unreachable_patterns)]
|
||||
LL | #![deny(overlapping_patterns)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: unreachable pattern
|
||||
@ -17,6 +17,12 @@ error: unreachable pattern
|
||||
|
|
||||
LL | 200 => {}
|
||||
| ^^^
|
||||
|
|
||||
note: lint level defined here
|
||||
--> $DIR/exhaustive_integer_patterns.rs:3:9
|
||||
|
|
||||
LL | #![deny(unreachable_patterns)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error[E0004]: non-exhaustive patterns: `128u8..=std::u8::MAX` not covered
|
||||
--> $DIR/exhaustive_integer_patterns.rs:28:11
|
||||
|
@ -1,4 +1,4 @@
|
||||
#![deny(unreachable_patterns)]
|
||||
#![deny(unreachable_patterns, overlapping_patterns)]
|
||||
|
||||
fn main() {
|
||||
match 5 {
|
||||
|
@ -7,10 +7,10 @@ LL | 5 ..= 6 => { }
|
||||
| ^^^^^^^ overlapping patterns
|
||||
|
|
||||
note: lint level defined here
|
||||
--> $DIR/match-range-fail-dominate.rs:1:9
|
||||
--> $DIR/match-range-fail-dominate.rs:1:31
|
||||
|
|
||||
LL | #![deny(unreachable_patterns)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
LL | #![deny(unreachable_patterns, overlapping_patterns)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: multiple patterns covering the same range
|
||||
--> $DIR/match-range-fail-dominate.rs:12:7
|
||||
@ -69,6 +69,12 @@ error: unreachable pattern
|
||||
|
|
||||
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
|
||||
|
@ -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};
|
||||
|
||||
|
@ -7,10 +7,10 @@ LL | -5 ..= 20 => {}
|
||||
| ^^^^^^^^^ overlapping patterns
|
||||
|
|
||||
note: lint level defined here
|
||||
--> $DIR/precise_pointer_size_matching.rs:11:9
|
||||
--> $DIR/precise_pointer_size_matching.rs:11:31
|
||||
|
|
||||
LL | #![deny(unreachable_patterns)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
LL | #![deny(unreachable_patterns, overlapping_patterns)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error[E0004]: non-exhaustive patterns: `std::isize::MIN..=-6isize` and `21isize..=std::isize::MAX` not covered
|
||||
--> $DIR/precise_pointer_size_matching.rs:24:11
|
||||
|
Loading…
x
Reference in New Issue
Block a user