Skip to content

Commit 53a3bfc

Browse files
authored
Rollup merge of #64007 - estebank:overlapping-patterns, r=matthewjasper
Add check for overlapping ranges to unreachable patterns lint Fix #63987.
2 parents e5b8c11 + 593cdcc commit 53a3bfc

17 files changed

+317
-115
lines changed

src/librustc/hir/mod.rs

+9
Original file line numberDiff line numberDiff line change
@@ -989,6 +989,15 @@ pub enum RangeEnd {
989989
Excluded,
990990
}
991991

992+
impl fmt::Display for RangeEnd {
993+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
994+
f.write_str(match self {
995+
RangeEnd::Included => "..=",
996+
RangeEnd::Excluded => "..",
997+
})
998+
}
999+
}
1000+
9921001
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)]
9931002
pub enum PatKind {
9941003
/// Represents a wildcard pattern (i.e., `_`).

src/librustc/lint/builtin.rs

+7
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

+1
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,

0 commit comments

Comments
 (0)