Rename the overlapping_patterns lint to overlapping_range_endpoints

This commit is contained in:
Nadrieril 2020-10-22 18:34:00 +01:00
parent 06ca6bba8d
commit d1a50ffb7c
7 changed files with 52 additions and 51 deletions

View File

@ -283,7 +283,7 @@ fn register_builtins(store: &mut LintStore, no_interleave_lints: bool) {
UNUSED_MUT,
UNREACHABLE_CODE,
UNREACHABLE_PATTERNS,
OVERLAPPING_PATTERNS,
OVERLAPPING_RANGE_ENDPOINTS,
UNUSED_MUST_USE,
UNUSED_UNSAFE,
PATH_STATEMENTS,
@ -335,6 +335,7 @@ fn register_builtins(store: &mut LintStore, no_interleave_lints: bool) {
store.register_renamed("exceeding_bitshifts", "arithmetic_overflow");
store.register_renamed("redundant_semicolon", "redundant_semicolons");
store.register_renamed("intra_doc_link_resolution_failure", "broken_intra_doc_links");
store.register_renamed("overlapping_patterns", "overlapping_range_endpoints");
store.register_removed("unknown_features", "replaced by an error");
store.register_removed("unsigned_negation", "replaced by negate_unsigned feature gate");
store.register_removed("negate_unsigned", "cast a signed value instead");

View File

@ -588,8 +588,8 @@ declare_lint! {
}
declare_lint! {
/// The `overlapping_patterns` lint detects `match` arms that have
/// [range patterns] that overlap.
/// The `overlapping_range_endpoints` lint detects `match` arms that have [range patterns] that
/// overlap on their endpoints.
///
/// [range patterns]: https://doc.rust-lang.org/nightly/reference/patterns.html#range-patterns
///
@ -607,13 +607,12 @@ declare_lint! {
///
/// ### Explanation
///
/// It is likely a mistake to have range patterns in a match expression
/// that overlap. Check that the beginning and end values are what you
/// expect, and keep in mind that with `..=` the left and right bounds are
/// inclusive.
pub OVERLAPPING_PATTERNS,
/// It is likely a mistake to have range patterns in a match expression that overlap in this
/// way. Check that the beginning and end values are what you expect, and keep in mind that
/// with `..=` the left and right bounds are inclusive.
pub OVERLAPPING_RANGE_ENDPOINTS,
Warn,
"detects overlapping patterns"
"detects range patterns with overlapping endpoints"
}
declare_lint! {
@ -2765,7 +2764,7 @@ declare_lint_pass! {
DEAD_CODE,
UNREACHABLE_CODE,
UNREACHABLE_PATTERNS,
OVERLAPPING_PATTERNS,
OVERLAPPING_RANGE_ENDPOINTS,
BINDINGS_WITH_VARIANT_NAME,
UNUSED_MACROS,
WARNINGS,

View File

@ -273,7 +273,7 @@ impl IntRange {
let mut borders: Vec<_> = row_borders.chain(self_borders).collect();
borders.sort_unstable();
self.lint_overlapping_patterns(pcx, hir_id, overlaps);
self.lint_overlapping_range_endpoints(pcx, hir_id, overlaps);
// We're going to iterate through every adjacent pair of borders, making sure that
// each represents an interval of nonnegative length, and convert each such
@ -296,7 +296,7 @@ impl IntRange {
.collect()
}
fn lint_overlapping_patterns(
fn lint_overlapping_range_endpoints(
&self,
pcx: PatCtxt<'_, '_, '_>,
hir_id: Option<HirId>,
@ -304,22 +304,23 @@ impl IntRange {
) {
if let (true, Some(hir_id)) = (!overlaps.is_empty(), hir_id) {
pcx.cx.tcx.struct_span_lint_hir(
lint::builtin::OVERLAPPING_PATTERNS,
lint::builtin::OVERLAPPING_RANGE_ENDPOINTS,
hir_id,
pcx.span,
|lint| {
let mut err = lint.build("multiple patterns covering the same range");
err.span_label(pcx.span, "overlapping patterns");
let mut err = lint.build("multiple patterns overlap on their endpoints");
err.span_label(pcx.span, "overlapping range endpoints");
for (int_range, span) in overlaps {
// Use the real type for user display of the ranges:
err.span_label(
span,
&format!(
"this range overlaps on `{}`",
int_range.to_pat(pcx.cx.tcx, pcx.ty),
int_range.to_pat(pcx.cx.tcx, pcx.ty)
),
);
}
// FIXME: add note
err.emit();
},
);

View File

@ -1,5 +1,5 @@
// run-pass
#![allow(unused_imports, overlapping_patterns)]
#![allow(unused_imports, overlapping_range_endpoints)]
// pretty-expanded FIXME #23616
use m::{START, END};

View File

@ -1,5 +1,5 @@
// run-pass
#![allow(overlapping_patterns)]
#![allow(overlapping_range_endpoints)]
fn main() {
let x = 'a';

View File

@ -1,5 +1,5 @@
#![feature(exclusive_range_pattern)]
#![deny(overlapping_patterns)]
#![deny(overlapping_range_endpoints)]
macro_rules! m {
($s:expr, $t1:pat, $t2:pat) => {
@ -12,31 +12,31 @@ macro_rules! m {
}
fn main() {
m!(0u8, 20..=30, 30..=40); //~ ERROR multiple patterns covering the same range
m!(0u8, 30..=40, 20..=30); //~ ERROR multiple patterns covering the same range
m!(0u8, 20..=30, 30..=40); //~ ERROR multiple patterns overlap on their endpoints
m!(0u8, 30..=40, 20..=30); //~ ERROR multiple patterns overlap on their endpoints
m!(0u8, 20..=30, 31..=40);
m!(0u8, 20..=30, 29..=40);
m!(0u8, 20.. 30, 29..=40); //~ ERROR multiple patterns covering the same range
m!(0u8, 20.. 30, 29..=40); //~ ERROR multiple patterns overlap on their endpoints
m!(0u8, 20.. 30, 28..=40);
m!(0u8, 20.. 30, 30..=40);
m!(0u8, 20..=30, 30..=30);
m!(0u8, 20..=30, 30..=31); //~ ERROR multiple patterns covering the same range
m!(0u8, 20..=30, 30..=31); //~ ERROR multiple patterns overlap on their endpoints
m!(0u8, 20..=30, 29..=30);
m!(0u8, 20..=30, 20..=20);
m!(0u8, 20..=30, 20..=21);
m!(0u8, 20..=30, 19..=20); //~ ERROR multiple patterns covering the same range
m!(0u8, 20..=30, 19..=20); //~ ERROR multiple patterns overlap on their endpoints
m!(0u8, 20..=30, 20);
m!(0u8, 20..=30, 25);
m!(0u8, 20..=30, 30);
m!(0u8, 20.. 30, 29);
m!(0u8, 20, 20..=30); //~ ERROR multiple patterns covering the same range
m!(0u8, 20, 20..=30); //~ ERROR multiple patterns overlap on their endpoints
m!(0u8, 25, 20..=30);
m!(0u8, 30, 20..=30); //~ ERROR multiple patterns covering the same range
m!(0u8, 30, 20..=30); //~ ERROR multiple patterns overlap on their endpoints
match 0u8 {
0..=10 => {}
20..=30 => {}
10..=20 => {} //~ ERROR multiple patterns covering the same range
10..=20 => {} //~ ERROR multiple patterns overlap on their endpoints
_ => {}
}
match (0u8, true) {
@ -47,13 +47,13 @@ fn main() {
}
match (true, 0u8) {
(true, 0..=10) => {}
(true, 10..20) => {} //~ ERROR multiple patterns covering the same range
(true, 10..20) => {} //~ ERROR multiple patterns overlap on their endpoints
(false, 10..20) => {}
_ => {}
}
match Some(0u8) {
Some(0..=10) => {}
Some(10..20) => {} //~ ERROR multiple patterns covering the same range
Some(10..20) => {} //~ ERROR multiple patterns overlap on their endpoints
_ => {}
}
}

View File

@ -1,66 +1,66 @@
error: multiple patterns covering the same range
error: multiple patterns overlap on their endpoints
--> $DIR/overlapping_range_endpoints.rs:15:22
|
LL | m!(0u8, 20..=30, 30..=40);
| ------- ^^^^^^^ overlapping patterns
| ------- ^^^^^^^ overlapping range endpoints
| |
| this range overlaps on `30_u8`
|
note: the lint level is defined here
--> $DIR/overlapping_range_endpoints.rs:2:9
|
LL | #![deny(overlapping_patterns)]
| ^^^^^^^^^^^^^^^^^^^^
LL | #![deny(overlapping_range_endpoints)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: multiple patterns covering the same range
error: multiple patterns overlap on their endpoints
--> $DIR/overlapping_range_endpoints.rs:16:22
|
LL | m!(0u8, 30..=40, 20..=30);
| ------- ^^^^^^^ overlapping patterns
| ------- ^^^^^^^ overlapping range endpoints
| |
| this range overlaps on `30_u8`
error: multiple patterns covering the same range
error: multiple patterns overlap on their endpoints
--> $DIR/overlapping_range_endpoints.rs:19:22
|
LL | m!(0u8, 20.. 30, 29..=40);
| ------- ^^^^^^^ overlapping patterns
| ------- ^^^^^^^ overlapping range endpoints
| |
| this range overlaps on `29_u8`
error: multiple patterns covering the same range
error: multiple patterns overlap on their endpoints
--> $DIR/overlapping_range_endpoints.rs:23:22
|
LL | m!(0u8, 20..=30, 30..=31);
| ------- ^^^^^^^ overlapping patterns
| ------- ^^^^^^^ overlapping range endpoints
| |
| this range overlaps on `30_u8`
error: multiple patterns covering the same range
error: multiple patterns overlap on their endpoints
--> $DIR/overlapping_range_endpoints.rs:27:22
|
LL | m!(0u8, 20..=30, 19..=20);
| ------- ^^^^^^^ overlapping patterns
| ------- ^^^^^^^ overlapping range endpoints
| |
| this range overlaps on `20_u8`
error: multiple patterns covering the same range
error: multiple patterns overlap on their endpoints
--> $DIR/overlapping_range_endpoints.rs:32:17
|
LL | m!(0u8, 20, 20..=30);
| -- ^^^^^^^ overlapping patterns
| -- ^^^^^^^ overlapping range endpoints
| |
| this range overlaps on `20_u8`
error: multiple patterns covering the same range
error: multiple patterns overlap on their endpoints
--> $DIR/overlapping_range_endpoints.rs:34:17
|
LL | m!(0u8, 30, 20..=30);
| -- ^^^^^^^ overlapping patterns
| -- ^^^^^^^ overlapping range endpoints
| |
| this range overlaps on `30_u8`
error: multiple patterns covering the same range
error: multiple patterns overlap on their endpoints
--> $DIR/overlapping_range_endpoints.rs:39:9
|
LL | 0..=10 => {}
@ -68,23 +68,23 @@ LL | 0..=10 => {}
LL | 20..=30 => {}
| ------- this range overlaps on `20_u8`
LL | 10..=20 => {}
| ^^^^^^^ overlapping patterns
| ^^^^^^^ overlapping range endpoints
error: multiple patterns covering the same range
error: multiple patterns overlap on their endpoints
--> $DIR/overlapping_range_endpoints.rs:50:16
|
LL | (true, 0..=10) => {}
| ------ this range overlaps on `10_u8`
LL | (true, 10..20) => {}
| ^^^^^^ overlapping patterns
| ^^^^^^ overlapping range endpoints
error: multiple patterns covering the same range
error: multiple patterns overlap on their endpoints
--> $DIR/overlapping_range_endpoints.rs:56:14
|
LL | Some(0..=10) => {}
| ------ this range overlaps on `10_u8`
LL | Some(10..20) => {}
| ^^^^^^ overlapping patterns
| ^^^^^^ overlapping range endpoints
error: aborting due to 10 previous errors