diff --git a/CHANGELOG.md b/CHANGELOG.md index d4ecdabeb..69694da15 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1241,7 +1241,6 @@ Released 2018-09-13 [`panicking_unwrap`]: https://rust-lang.github.io/rust-clippy/master/index.html#panicking_unwrap [`partialeq_ne_impl`]: https://rust-lang.github.io/rust-clippy/master/index.html#partialeq_ne_impl [`path_buf_push_overwrite`]: https://rust-lang.github.io/rust-clippy/master/index.html#path_buf_push_overwrite -[`pats_with_wild_match_arm`]: https://rust-lang.github.io/rust-clippy/master/index.html#pats_with_wild_match_arm [`possible_missing_comma`]: https://rust-lang.github.io/rust-clippy/master/index.html#possible_missing_comma [`precedence`]: https://rust-lang.github.io/rust-clippy/master/index.html#precedence [`print_literal`]: https://rust-lang.github.io/rust-clippy/master/index.html#print_literal @@ -1362,6 +1361,7 @@ Released 2018-09-13 [`while_let_on_iterator`]: https://rust-lang.github.io/rust-clippy/master/index.html#while_let_on_iterator [`wildcard_dependencies`]: https://rust-lang.github.io/rust-clippy/master/index.html#wildcard_dependencies [`wildcard_enum_match_arm`]: https://rust-lang.github.io/rust-clippy/master/index.html#wildcard_enum_match_arm +[`wildcard_in_or_patterns`]: https://rust-lang.github.io/rust-clippy/master/index.html#wildcard_in_or_patterns [`write_literal`]: https://rust-lang.github.io/rust-clippy/master/index.html#write_literal [`write_with_newline`]: https://rust-lang.github.io/rust-clippy/master/index.html#write_with_newline [`writeln_empty_string`]: https://rust-lang.github.io/rust-clippy/master/index.html#writeln_empty_string diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index a009bab57..518b6ee61 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -597,10 +597,10 @@ pub fn register_plugins(store: &mut lint::LintStore, sess: &Session, conf: &Conf &matches::MATCH_OVERLAPPING_ARM, &matches::MATCH_REF_PATS, &matches::MATCH_WILD_ERR_ARM, - &matches::PATS_WITH_WILD_MATCH_ARM, &matches::SINGLE_MATCH, &matches::SINGLE_MATCH_ELSE, &matches::WILDCARD_ENUM_MATCH_ARM, + &matches::WILDCARD_IN_OR_PATTERNS, &mem_discriminant::MEM_DISCRIMINANT_NON_ENUM, &mem_forget::MEM_FORGET, &mem_replace::MEM_REPLACE_OPTION_WITH_NONE, @@ -1188,8 +1188,8 @@ pub fn register_plugins(store: &mut lint::LintStore, sess: &Session, conf: &Conf LintId::of(&matches::MATCH_OVERLAPPING_ARM), LintId::of(&matches::MATCH_REF_PATS), LintId::of(&matches::MATCH_WILD_ERR_ARM), - LintId::of(&matches::PATS_WITH_WILD_MATCH_ARM), LintId::of(&matches::SINGLE_MATCH), + LintId::of(&matches::WILDCARD_IN_OR_PATTERNS), LintId::of(&mem_discriminant::MEM_DISCRIMINANT_NON_ENUM), LintId::of(&mem_replace::MEM_REPLACE_OPTION_WITH_NONE), LintId::of(&mem_replace::MEM_REPLACE_WITH_DEFAULT), @@ -1463,7 +1463,7 @@ pub fn register_plugins(store: &mut lint::LintStore, sess: &Session, conf: &Conf LintId::of(&map_unit_fn::OPTION_MAP_UNIT_FN), LintId::of(&map_unit_fn::RESULT_MAP_UNIT_FN), LintId::of(&matches::MATCH_AS_REF), - LintId::of(&matches::PATS_WITH_WILD_MATCH_ARM), + LintId::of(&matches::WILDCARD_IN_OR_PATTERNS), LintId::of(&methods::CHARS_NEXT_CMP), LintId::of(&methods::CLONE_ON_COPY), LintId::of(&methods::FILTER_NEXT), diff --git a/clippy_lints/src/matches.rs b/clippy_lints/src/matches.rs index 2347a0619..2e25b7236 100644 --- a/clippy_lints/src/matches.rs +++ b/clippy_lints/src/matches.rs @@ -238,7 +238,7 @@ declare_clippy_lint! { /// "bar" | _ => {}, /// } /// ``` - pub PATS_WITH_WILD_MATCH_ARM, + pub WILDCARD_IN_OR_PATTERNS, complexity, "a wildcard pattern used with others patterns in same match arm" } @@ -252,7 +252,7 @@ declare_lint_pass!(Matches => [ MATCH_WILD_ERR_ARM, MATCH_AS_REF, WILDCARD_ENUM_MATCH_ARM, - PATS_WITH_WILD_MATCH_ARM + WILDCARD_IN_OR_PATTERNS ]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Matches { @@ -267,7 +267,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Matches { check_wild_err_arm(cx, ex, arms); check_wild_enum_match(cx, ex, arms); check_match_as_ref(cx, ex, arms, expr); - check_pats_wild_match(cx, ex, arms); + check_wild_in_or_pats(cx, ex, arms); } if let ExprKind::Match(ref ex, ref arms, _) = expr.kind { check_match_ref_pats(cx, ex, arms, expr); @@ -686,7 +686,7 @@ fn check_match_as_ref(cx: &LateContext<'_, '_>, ex: &Expr<'_>, arms: &[Arm<'_>], } } -fn check_pats_wild_match(cx: &LateContext<'_, '_>, ex: &Expr<'_>, arms: &[Arm<'_>]) { +fn check_wild_in_or_pats(cx: &LateContext<'_, '_>, ex: &Expr<'_>, arms: &[Arm<'_>]) { let mut is_non_exhaustive_enum = false; let ty = cx.tables.expr_ty(ex); if ty.is_enum() { @@ -703,7 +703,7 @@ fn check_pats_wild_match(cx: &LateContext<'_, '_>, ex: &Expr<'_>, arms: &[Arm<'_ if fields.len() > 1 && fields.iter().any(is_wild) { span_lint_and_then( cx, - PATS_WITH_WILD_MATCH_ARM, + WILDCARD_IN_OR_PATTERNS, arm.pat.span, "wildcard pattern covers any other pattern as it will match anyway.", |db| { diff --git a/src/lintlist/mod.rs b/src/lintlist/mod.rs index 34bf4749d..399f3483a 100644 --- a/src/lintlist/mod.rs +++ b/src/lintlist/mod.rs @@ -1568,13 +1568,6 @@ pub const ALL_LINTS: [Lint; 345] = [ deprecation: None, module: "path_buf_push_overwrite", }, - Lint { - name: "pats_with_wild_match_arm", - group: "complexity", - desc: "a wildcard pattern used with others patterns in same match arm", - deprecation: None, - module: "matches", - }, Lint { name: "possible_missing_comma", group: "correctness", @@ -2352,6 +2345,13 @@ pub const ALL_LINTS: [Lint; 345] = [ deprecation: None, module: "matches", }, + Lint { + name: "wildcard_in_or_patterns", + group: "complexity", + desc: "a wildcard pattern used with others patterns in same match arm", + deprecation: None, + module: "matches", + }, Lint { name: "write_literal", group: "style", diff --git a/tests/ui/pats_with_wild_match_arm.fixed b/tests/ui/wild_in_or_pats.fixed similarity index 93% rename from tests/ui/pats_with_wild_match_arm.fixed rename to tests/ui/wild_in_or_pats.fixed index daa34af94..40d4a6e8f 100644 --- a/tests/ui/pats_with_wild_match_arm.fixed +++ b/tests/ui/wild_in_or_pats.fixed @@ -1,6 +1,6 @@ // run-rustfix -#![warn(clippy::pats_with_wild_match_arm)] +#![warn(clippy::wildcard_in_or_patterns)] fn main() { match "foo" { diff --git a/tests/ui/pats_with_wild_match_arm.rs b/tests/ui/wild_in_or_pats.rs similarity index 94% rename from tests/ui/pats_with_wild_match_arm.rs rename to tests/ui/wild_in_or_pats.rs index 0410cecb5..569871db9 100644 --- a/tests/ui/pats_with_wild_match_arm.rs +++ b/tests/ui/wild_in_or_pats.rs @@ -1,6 +1,6 @@ // run-rustfix -#![warn(clippy::pats_with_wild_match_arm)] +#![warn(clippy::wildcard_in_or_patterns)] fn main() { match "foo" { diff --git a/tests/ui/pats_with_wild_match_arm.stderr b/tests/ui/wild_in_or_pats.stderr similarity index 76% rename from tests/ui/pats_with_wild_match_arm.stderr rename to tests/ui/wild_in_or_pats.stderr index 215d0b2e4..45ae31db2 100644 --- a/tests/ui/pats_with_wild_match_arm.stderr +++ b/tests/ui/wild_in_or_pats.stderr @@ -1,25 +1,25 @@ error: wildcard pattern covers any other pattern as it will match anyway. - --> $DIR/pats_with_wild_match_arm.rs:10:9 + --> $DIR/wild_in_or_pats.rs:10:9 | LL | "bar" | _ => { | ^^^^^^^^^ help: consider replacing with wildcard pattern only: `_` | - = note: `-D clippy::pats-with-wild-match-arm` implied by `-D warnings` + = note: `-D clippy::wildcard-in-or-patterns` implied by `-D warnings` error: wildcard pattern covers any other pattern as it will match anyway. - --> $DIR/pats_with_wild_match_arm.rs:18:9 + --> $DIR/wild_in_or_pats.rs:18:9 | LL | "bar" | "bar2" | _ => { | ^^^^^^^^^^^^^^^^^^ help: consider replacing with wildcard pattern only: `_` error: wildcard pattern covers any other pattern as it will match anyway. - --> $DIR/pats_with_wild_match_arm.rs:26:9 + --> $DIR/wild_in_or_pats.rs:26:9 | LL | _ | "bar" | _ => { | ^^^^^^^^^^^^^ help: consider replacing with wildcard pattern only: `_` error: wildcard pattern covers any other pattern as it will match anyway. - --> $DIR/pats_with_wild_match_arm.rs:34:9 + --> $DIR/wild_in_or_pats.rs:34:9 | LL | _ | "bar" => { | ^^^^^^^^^ help: consider replacing with wildcard pattern only: `_` diff --git a/tests/ui/wildcard_enum_match_arm.fixed b/tests/ui/wildcard_enum_match_arm.fixed index f46320e03..2aa24ea11 100644 --- a/tests/ui/wildcard_enum_match_arm.fixed +++ b/tests/ui/wildcard_enum_match_arm.fixed @@ -6,7 +6,7 @@ unused_variables, dead_code, clippy::single_match, - clippy::pats_with_wild_match_arm + clippy::wildcard_in_or_patterns )] use std::io::ErrorKind; diff --git a/tests/ui/wildcard_enum_match_arm.rs b/tests/ui/wildcard_enum_match_arm.rs index 508d0e0bb..07c93feaf 100644 --- a/tests/ui/wildcard_enum_match_arm.rs +++ b/tests/ui/wildcard_enum_match_arm.rs @@ -6,7 +6,7 @@ unused_variables, dead_code, clippy::single_match, - clippy::pats_with_wild_match_arm + clippy::wildcard_in_or_patterns )] use std::io::ErrorKind;