Skip to content

Commit

Permalink
Rollup merge of rust-lang#64007 - estebank:overlapping-patterns, r=ma…
Browse files Browse the repository at this point in the history
…tthewjasper

Add check for overlapping ranges to unreachable patterns lint

Fix rust-lang#63987.
  • Loading branch information
Centril committed Oct 19, 2019
2 parents e5b8c11 + 593cdcc commit 53a3bfc
Show file tree
Hide file tree
Showing 17 changed files with 317 additions and 115 deletions.
9 changes: 9 additions & 0 deletions src/librustc/hir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -989,6 +989,15 @@ pub enum RangeEnd {
Excluded,
}

impl fmt::Display for RangeEnd {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(match self {
RangeEnd::Included => "..=",
RangeEnd::Excluded => "..",
})
}
}

#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)]
pub enum PatKind {
/// Represents a wildcard pattern (i.e., `_`).
Expand Down
7 changes: 7 additions & 0 deletions src/librustc/lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ declare_lint! {
"detects unreachable patterns"
}

declare_lint! {
pub OVERLAPPING_PATTERNS,
Warn,
"detects overlapping patterns"
}

declare_lint! {
pub UNUSED_MACROS,
Warn,
Expand Down Expand Up @@ -423,6 +429,7 @@ declare_lint_pass! {
DEAD_CODE,
UNREACHABLE_CODE,
UNREACHABLE_PATTERNS,
OVERLAPPING_PATTERNS,
UNUSED_MACROS,
WARNINGS,
UNUSED_FEATURES,
Expand Down
1 change: 1 addition & 0 deletions src/librustc_lint/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading

0 comments on commit 53a3bfc

Please sign in to comment.