Skip to content

Commit d1a50ff

Browse files
committed
Rename the overlapping_patterns lint to overlapping_range_endpoints
1 parent 06ca6bb commit d1a50ff

File tree

7 files changed

+52
-51
lines changed

7 files changed

+52
-51
lines changed

compiler/rustc_lint/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ fn register_builtins(store: &mut LintStore, no_interleave_lints: bool) {
283283
UNUSED_MUT,
284284
UNREACHABLE_CODE,
285285
UNREACHABLE_PATTERNS,
286-
OVERLAPPING_PATTERNS,
286+
OVERLAPPING_RANGE_ENDPOINTS,
287287
UNUSED_MUST_USE,
288288
UNUSED_UNSAFE,
289289
PATH_STATEMENTS,
@@ -335,6 +335,7 @@ fn register_builtins(store: &mut LintStore, no_interleave_lints: bool) {
335335
store.register_renamed("exceeding_bitshifts", "arithmetic_overflow");
336336
store.register_renamed("redundant_semicolon", "redundant_semicolons");
337337
store.register_renamed("intra_doc_link_resolution_failure", "broken_intra_doc_links");
338+
store.register_renamed("overlapping_patterns", "overlapping_range_endpoints");
338339
store.register_removed("unknown_features", "replaced by an error");
339340
store.register_removed("unsigned_negation", "replaced by negate_unsigned feature gate");
340341
store.register_removed("negate_unsigned", "cast a signed value instead");

compiler/rustc_lint_defs/src/builtin.rs

+8-9
Original file line numberDiff line numberDiff line change
@@ -588,8 +588,8 @@ declare_lint! {
588588
}
589589

590590
declare_lint! {
591-
/// The `overlapping_patterns` lint detects `match` arms that have
592-
/// [range patterns] that overlap.
591+
/// The `overlapping_range_endpoints` lint detects `match` arms that have [range patterns] that
592+
/// overlap on their endpoints.
593593
///
594594
/// [range patterns]: https://doc.rust-lang.org/nightly/reference/patterns.html#range-patterns
595595
///
@@ -607,13 +607,12 @@ declare_lint! {
607607
///
608608
/// ### Explanation
609609
///
610-
/// It is likely a mistake to have range patterns in a match expression
611-
/// that overlap. Check that the beginning and end values are what you
612-
/// expect, and keep in mind that with `..=` the left and right bounds are
613-
/// inclusive.
614-
pub OVERLAPPING_PATTERNS,
610+
/// It is likely a mistake to have range patterns in a match expression that overlap in this
611+
/// way. Check that the beginning and end values are what you expect, and keep in mind that
612+
/// with `..=` the left and right bounds are inclusive.
613+
pub OVERLAPPING_RANGE_ENDPOINTS,
615614
Warn,
616-
"detects overlapping patterns"
615+
"detects range patterns with overlapping endpoints"
617616
}
618617

619618
declare_lint! {
@@ -2765,7 +2764,7 @@ declare_lint_pass! {
27652764
DEAD_CODE,
27662765
UNREACHABLE_CODE,
27672766
UNREACHABLE_PATTERNS,
2768-
OVERLAPPING_PATTERNS,
2767+
OVERLAPPING_RANGE_ENDPOINTS,
27692768
BINDINGS_WITH_VARIANT_NAME,
27702769
UNUSED_MACROS,
27712770
WARNINGS,

compiler/rustc_mir_build/src/thir/pattern/deconstruct_pat.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ impl IntRange {
273273
let mut borders: Vec<_> = row_borders.chain(self_borders).collect();
274274
borders.sort_unstable();
275275

276-
self.lint_overlapping_patterns(pcx, hir_id, overlaps);
276+
self.lint_overlapping_range_endpoints(pcx, hir_id, overlaps);
277277

278278
// We're going to iterate through every adjacent pair of borders, making sure that
279279
// each represents an interval of nonnegative length, and convert each such
@@ -296,30 +296,31 @@ impl IntRange {
296296
.collect()
297297
}
298298

299-
fn lint_overlapping_patterns(
299+
fn lint_overlapping_range_endpoints(
300300
&self,
301301
pcx: PatCtxt<'_, '_, '_>,
302302
hir_id: Option<HirId>,
303303
overlaps: Vec<(IntRange, Span)>,
304304
) {
305305
if let (true, Some(hir_id)) = (!overlaps.is_empty(), hir_id) {
306306
pcx.cx.tcx.struct_span_lint_hir(
307-
lint::builtin::OVERLAPPING_PATTERNS,
307+
lint::builtin::OVERLAPPING_RANGE_ENDPOINTS,
308308
hir_id,
309309
pcx.span,
310310
|lint| {
311-
let mut err = lint.build("multiple patterns covering the same range");
312-
err.span_label(pcx.span, "overlapping patterns");
311+
let mut err = lint.build("multiple patterns overlap on their endpoints");
312+
err.span_label(pcx.span, "overlapping range endpoints");
313313
for (int_range, span) in overlaps {
314314
// Use the real type for user display of the ranges:
315315
err.span_label(
316316
span,
317317
&format!(
318318
"this range overlaps on `{}`",
319-
int_range.to_pat(pcx.cx.tcx, pcx.ty),
319+
int_range.to_pat(pcx.cx.tcx, pcx.ty)
320320
),
321321
);
322322
}
323+
// FIXME: add note
323324
err.emit();
324325
},
325326
);

src/test/ui/issues/issue-21475.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// run-pass
2-
#![allow(unused_imports, overlapping_patterns)]
2+
#![allow(unused_imports, overlapping_range_endpoints)]
33
// pretty-expanded FIXME #23616
44

55
use m::{START, END};

src/test/ui/issues/issue-26251.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// run-pass
2-
#![allow(overlapping_patterns)]
2+
#![allow(overlapping_range_endpoints)]
33

44
fn main() {
55
let x = 'a';
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#![feature(exclusive_range_pattern)]
2-
#![deny(overlapping_patterns)]
2+
#![deny(overlapping_range_endpoints)]
33

44
macro_rules! m {
55
($s:expr, $t1:pat, $t2:pat) => {
@@ -12,31 +12,31 @@ macro_rules! m {
1212
}
1313

1414
fn main() {
15-
m!(0u8, 20..=30, 30..=40); //~ ERROR multiple patterns covering the same range
16-
m!(0u8, 30..=40, 20..=30); //~ ERROR multiple patterns covering the same range
15+
m!(0u8, 20..=30, 30..=40); //~ ERROR multiple patterns overlap on their endpoints
16+
m!(0u8, 30..=40, 20..=30); //~ ERROR multiple patterns overlap on their endpoints
1717
m!(0u8, 20..=30, 31..=40);
1818
m!(0u8, 20..=30, 29..=40);
19-
m!(0u8, 20.. 30, 29..=40); //~ ERROR multiple patterns covering the same range
19+
m!(0u8, 20.. 30, 29..=40); //~ ERROR multiple patterns overlap on their endpoints
2020
m!(0u8, 20.. 30, 28..=40);
2121
m!(0u8, 20.. 30, 30..=40);
2222
m!(0u8, 20..=30, 30..=30);
23-
m!(0u8, 20..=30, 30..=31); //~ ERROR multiple patterns covering the same range
23+
m!(0u8, 20..=30, 30..=31); //~ ERROR multiple patterns overlap on their endpoints
2424
m!(0u8, 20..=30, 29..=30);
2525
m!(0u8, 20..=30, 20..=20);
2626
m!(0u8, 20..=30, 20..=21);
27-
m!(0u8, 20..=30, 19..=20); //~ ERROR multiple patterns covering the same range
27+
m!(0u8, 20..=30, 19..=20); //~ ERROR multiple patterns overlap on their endpoints
2828
m!(0u8, 20..=30, 20);
2929
m!(0u8, 20..=30, 25);
3030
m!(0u8, 20..=30, 30);
3131
m!(0u8, 20.. 30, 29);
32-
m!(0u8, 20, 20..=30); //~ ERROR multiple patterns covering the same range
32+
m!(0u8, 20, 20..=30); //~ ERROR multiple patterns overlap on their endpoints
3333
m!(0u8, 25, 20..=30);
34-
m!(0u8, 30, 20..=30); //~ ERROR multiple patterns covering the same range
34+
m!(0u8, 30, 20..=30); //~ ERROR multiple patterns overlap on their endpoints
3535

3636
match 0u8 {
3737
0..=10 => {}
3838
20..=30 => {}
39-
10..=20 => {} //~ ERROR multiple patterns covering the same range
39+
10..=20 => {} //~ ERROR multiple patterns overlap on their endpoints
4040
_ => {}
4141
}
4242
match (0u8, true) {
@@ -47,13 +47,13 @@ fn main() {
4747
}
4848
match (true, 0u8) {
4949
(true, 0..=10) => {}
50-
(true, 10..20) => {} //~ ERROR multiple patterns covering the same range
50+
(true, 10..20) => {} //~ ERROR multiple patterns overlap on their endpoints
5151
(false, 10..20) => {}
5252
_ => {}
5353
}
5454
match Some(0u8) {
5555
Some(0..=10) => {}
56-
Some(10..20) => {} //~ ERROR multiple patterns covering the same range
56+
Some(10..20) => {} //~ ERROR multiple patterns overlap on their endpoints
5757
_ => {}
5858
}
5959
}
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,90 @@
1-
error: multiple patterns covering the same range
1+
error: multiple patterns overlap on their endpoints
22
--> $DIR/overlapping_range_endpoints.rs:15:22
33
|
44
LL | m!(0u8, 20..=30, 30..=40);
5-
| ------- ^^^^^^^ overlapping patterns
5+
| ------- ^^^^^^^ overlapping range endpoints
66
| |
77
| this range overlaps on `30_u8`
88
|
99
note: the lint level is defined here
1010
--> $DIR/overlapping_range_endpoints.rs:2:9
1111
|
12-
LL | #![deny(overlapping_patterns)]
13-
| ^^^^^^^^^^^^^^^^^^^^
12+
LL | #![deny(overlapping_range_endpoints)]
13+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
1414

15-
error: multiple patterns covering the same range
15+
error: multiple patterns overlap on their endpoints
1616
--> $DIR/overlapping_range_endpoints.rs:16:22
1717
|
1818
LL | m!(0u8, 30..=40, 20..=30);
19-
| ------- ^^^^^^^ overlapping patterns
19+
| ------- ^^^^^^^ overlapping range endpoints
2020
| |
2121
| this range overlaps on `30_u8`
2222

23-
error: multiple patterns covering the same range
23+
error: multiple patterns overlap on their endpoints
2424
--> $DIR/overlapping_range_endpoints.rs:19:22
2525
|
2626
LL | m!(0u8, 20.. 30, 29..=40);
27-
| ------- ^^^^^^^ overlapping patterns
27+
| ------- ^^^^^^^ overlapping range endpoints
2828
| |
2929
| this range overlaps on `29_u8`
3030

31-
error: multiple patterns covering the same range
31+
error: multiple patterns overlap on their endpoints
3232
--> $DIR/overlapping_range_endpoints.rs:23:22
3333
|
3434
LL | m!(0u8, 20..=30, 30..=31);
35-
| ------- ^^^^^^^ overlapping patterns
35+
| ------- ^^^^^^^ overlapping range endpoints
3636
| |
3737
| this range overlaps on `30_u8`
3838

39-
error: multiple patterns covering the same range
39+
error: multiple patterns overlap on their endpoints
4040
--> $DIR/overlapping_range_endpoints.rs:27:22
4141
|
4242
LL | m!(0u8, 20..=30, 19..=20);
43-
| ------- ^^^^^^^ overlapping patterns
43+
| ------- ^^^^^^^ overlapping range endpoints
4444
| |
4545
| this range overlaps on `20_u8`
4646

47-
error: multiple patterns covering the same range
47+
error: multiple patterns overlap on their endpoints
4848
--> $DIR/overlapping_range_endpoints.rs:32:17
4949
|
5050
LL | m!(0u8, 20, 20..=30);
51-
| -- ^^^^^^^ overlapping patterns
51+
| -- ^^^^^^^ overlapping range endpoints
5252
| |
5353
| this range overlaps on `20_u8`
5454

55-
error: multiple patterns covering the same range
55+
error: multiple patterns overlap on their endpoints
5656
--> $DIR/overlapping_range_endpoints.rs:34:17
5757
|
5858
LL | m!(0u8, 30, 20..=30);
59-
| -- ^^^^^^^ overlapping patterns
59+
| -- ^^^^^^^ overlapping range endpoints
6060
| |
6161
| this range overlaps on `30_u8`
6262

63-
error: multiple patterns covering the same range
63+
error: multiple patterns overlap on their endpoints
6464
--> $DIR/overlapping_range_endpoints.rs:39:9
6565
|
6666
LL | 0..=10 => {}
6767
| ------ this range overlaps on `10_u8`
6868
LL | 20..=30 => {}
6969
| ------- this range overlaps on `20_u8`
7070
LL | 10..=20 => {}
71-
| ^^^^^^^ overlapping patterns
71+
| ^^^^^^^ overlapping range endpoints
7272

73-
error: multiple patterns covering the same range
73+
error: multiple patterns overlap on their endpoints
7474
--> $DIR/overlapping_range_endpoints.rs:50:16
7575
|
7676
LL | (true, 0..=10) => {}
7777
| ------ this range overlaps on `10_u8`
7878
LL | (true, 10..20) => {}
79-
| ^^^^^^ overlapping patterns
79+
| ^^^^^^ overlapping range endpoints
8080

81-
error: multiple patterns covering the same range
81+
error: multiple patterns overlap on their endpoints
8282
--> $DIR/overlapping_range_endpoints.rs:56:14
8383
|
8484
LL | Some(0..=10) => {}
8585
| ------ this range overlaps on `10_u8`
8686
LL | Some(10..20) => {}
87-
| ^^^^^^ overlapping patterns
87+
| ^^^^^^ overlapping range endpoints
8888

8989
error: aborting due to 10 previous errors
9090

0 commit comments

Comments
 (0)