1
Fork 0

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, UNUSED_MUT,
UNREACHABLE_CODE, UNREACHABLE_CODE,
UNREACHABLE_PATTERNS, UNREACHABLE_PATTERNS,
OVERLAPPING_PATTERNS, OVERLAPPING_RANGE_ENDPOINTS,
UNUSED_MUST_USE, UNUSED_MUST_USE,
UNUSED_UNSAFE, UNUSED_UNSAFE,
PATH_STATEMENTS, 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("exceeding_bitshifts", "arithmetic_overflow");
store.register_renamed("redundant_semicolon", "redundant_semicolons"); store.register_renamed("redundant_semicolon", "redundant_semicolons");
store.register_renamed("intra_doc_link_resolution_failure", "broken_intra_doc_links"); 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("unknown_features", "replaced by an error");
store.register_removed("unsigned_negation", "replaced by negate_unsigned feature gate"); store.register_removed("unsigned_negation", "replaced by negate_unsigned feature gate");
store.register_removed("negate_unsigned", "cast a signed value instead"); store.register_removed("negate_unsigned", "cast a signed value instead");

View file

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

View file

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

View file

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

View file

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

View file

@ -1,5 +1,5 @@
#![feature(exclusive_range_pattern)] #![feature(exclusive_range_pattern)]
#![deny(overlapping_patterns)] #![deny(overlapping_range_endpoints)]
macro_rules! m { macro_rules! m {
($s:expr, $t1:pat, $t2:pat) => { ($s:expr, $t1:pat, $t2:pat) => {
@ -12,31 +12,31 @@ macro_rules! m {
} }
fn main() { fn main() {
m!(0u8, 20..=30, 30..=40); //~ 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 covering the same range m!(0u8, 30..=40, 20..=30); //~ ERROR multiple patterns overlap on their endpoints
m!(0u8, 20..=30, 31..=40); m!(0u8, 20..=30, 31..=40);
m!(0u8, 20..=30, 29..=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, 28..=40);
m!(0u8, 20.. 30, 30..=40); m!(0u8, 20.. 30, 30..=40);
m!(0u8, 20..=30, 30..=30); 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, 29..=30);
m!(0u8, 20..=30, 20..=20); m!(0u8, 20..=30, 20..=20);
m!(0u8, 20..=30, 20..=21); 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, 20);
m!(0u8, 20..=30, 25); m!(0u8, 20..=30, 25);
m!(0u8, 20..=30, 30); m!(0u8, 20..=30, 30);
m!(0u8, 20.. 30, 29); 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, 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 { match 0u8 {
0..=10 => {} 0..=10 => {}
20..=30 => {} 20..=30 => {}
10..=20 => {} //~ ERROR multiple patterns covering the same range 10..=20 => {} //~ ERROR multiple patterns overlap on their endpoints
_ => {} _ => {}
} }
match (0u8, true) { match (0u8, true) {
@ -47,13 +47,13 @@ fn main() {
} }
match (true, 0u8) { match (true, 0u8) {
(true, 0..=10) => {} (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) => {} (false, 10..20) => {}
_ => {} _ => {}
} }
match Some(0u8) { match Some(0u8) {
Some(0..=10) => {} 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 --> $DIR/overlapping_range_endpoints.rs:15:22
| |
LL | m!(0u8, 20..=30, 30..=40); LL | m!(0u8, 20..=30, 30..=40);
| ------- ^^^^^^^ overlapping patterns | ------- ^^^^^^^ overlapping range endpoints
| | | |
| this range overlaps on `30_u8` | this range overlaps on `30_u8`
| |
note: the lint level is defined here note: the lint level is defined here
--> $DIR/overlapping_range_endpoints.rs:2:9 --> $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 --> $DIR/overlapping_range_endpoints.rs:16:22
| |
LL | m!(0u8, 30..=40, 20..=30); LL | m!(0u8, 30..=40, 20..=30);
| ------- ^^^^^^^ overlapping patterns | ------- ^^^^^^^ overlapping range endpoints
| | | |
| this range overlaps on `30_u8` | 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 --> $DIR/overlapping_range_endpoints.rs:19:22
| |
LL | m!(0u8, 20.. 30, 29..=40); LL | m!(0u8, 20.. 30, 29..=40);
| ------- ^^^^^^^ overlapping patterns | ------- ^^^^^^^ overlapping range endpoints
| | | |
| this range overlaps on `29_u8` | 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 --> $DIR/overlapping_range_endpoints.rs:23:22
| |
LL | m!(0u8, 20..=30, 30..=31); LL | m!(0u8, 20..=30, 30..=31);
| ------- ^^^^^^^ overlapping patterns | ------- ^^^^^^^ overlapping range endpoints
| | | |
| this range overlaps on `30_u8` | 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 --> $DIR/overlapping_range_endpoints.rs:27:22
| |
LL | m!(0u8, 20..=30, 19..=20); LL | m!(0u8, 20..=30, 19..=20);
| ------- ^^^^^^^ overlapping patterns | ------- ^^^^^^^ overlapping range endpoints
| | | |
| this range overlaps on `20_u8` | 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 --> $DIR/overlapping_range_endpoints.rs:32:17
| |
LL | m!(0u8, 20, 20..=30); LL | m!(0u8, 20, 20..=30);
| -- ^^^^^^^ overlapping patterns | -- ^^^^^^^ overlapping range endpoints
| | | |
| this range overlaps on `20_u8` | 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 --> $DIR/overlapping_range_endpoints.rs:34:17
| |
LL | m!(0u8, 30, 20..=30); LL | m!(0u8, 30, 20..=30);
| -- ^^^^^^^ overlapping patterns | -- ^^^^^^^ overlapping range endpoints
| | | |
| this range overlaps on `30_u8` | 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 --> $DIR/overlapping_range_endpoints.rs:39:9
| |
LL | 0..=10 => {} LL | 0..=10 => {}
@ -68,23 +68,23 @@ LL | 0..=10 => {}
LL | 20..=30 => {} LL | 20..=30 => {}
| ------- this range overlaps on `20_u8` | ------- this range overlaps on `20_u8`
LL | 10..=20 => {} 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 --> $DIR/overlapping_range_endpoints.rs:50:16
| |
LL | (true, 0..=10) => {} LL | (true, 0..=10) => {}
| ------ this range overlaps on `10_u8` | ------ this range overlaps on `10_u8`
LL | (true, 10..20) => {} 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 --> $DIR/overlapping_range_endpoints.rs:56:14
| |
LL | Some(0..=10) => {} LL | Some(0..=10) => {}
| ------ this range overlaps on `10_u8` | ------ this range overlaps on `10_u8`
LL | Some(10..20) => {} LL | Some(10..20) => {}
| ^^^^^^ overlapping patterns | ^^^^^^ overlapping range endpoints
error: aborting due to 10 previous errors error: aborting due to 10 previous errors