From ec9116412ae48f28521d042cdf4244a28f0070a5 Mon Sep 17 00:00:00 2001 From: J-ZhengLi Date: Thu, 10 Mar 2022 09:44:25 +0800 Subject: [PATCH] rename lint to `needless_match` and change its lint group to "complexity" --- CHANGELOG.md | 2 +- clippy_lints/src/lib.register_all.rs | 2 +- clippy_lints/src/lib.register_complexity.rs | 1 + clippy_lints/src/lib.register_correctness.rs | 1 - clippy_lints/src/lib.register_lints.rs | 2 +- clippy_lints/src/matches/mod.rs | 12 +++++------ .../{nop_match.rs => needless_match.rs} | 6 +++--- tests/ui/manual_map_option.fixed | 2 +- tests/ui/manual_map_option.rs | 2 +- .../{nop_match.fixed => needless_match.fixed} | 2 +- tests/ui/{nop_match.rs => needless_match.rs} | 2 +- ...nop_match.stderr => needless_match.stderr} | 20 +++++++++---------- 12 files changed, 27 insertions(+), 27 deletions(-) rename clippy_lints/src/matches/{nop_match.rs => needless_match.rs} (98%) rename tests/ui/{nop_match.fixed => needless_match.fixed} (97%) rename tests/ui/{nop_match.rs => needless_match.rs} (98%) rename tests/ui/{nop_match.stderr => needless_match.stderr} (86%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 16fe9454634..bc52bf7ce01 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3327,6 +3327,7 @@ Released 2018-09-13 [`needless_for_each`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_for_each [`needless_late_init`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_late_init [`needless_lifetimes`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes +[`needless_match`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_match [`needless_option_as_deref`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_option_as_deref [`needless_pass_by_value`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_pass_by_value [`needless_question_mark`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_question_mark @@ -3348,7 +3349,6 @@ Released 2018-09-13 [`nonminimal_bool`]: https://rust-lang.github.io/rust-clippy/master/index.html#nonminimal_bool [`nonsensical_open_options`]: https://rust-lang.github.io/rust-clippy/master/index.html#nonsensical_open_options [`nonstandard_macro_braces`]: https://rust-lang.github.io/rust-clippy/master/index.html#nonstandard_macro_braces -[`nop_match`]: https://rust-lang.github.io/rust-clippy/master/index.html#nop_match [`not_unsafe_ptr_arg_deref`]: https://rust-lang.github.io/rust-clippy/master/index.html#not_unsafe_ptr_arg_deref [`octal_escapes`]: https://rust-lang.github.io/rust-clippy/master/index.html#octal_escapes [`ok_expect`]: https://rust-lang.github.io/rust-clippy/master/index.html#ok_expect diff --git a/clippy_lints/src/lib.register_all.rs b/clippy_lints/src/lib.register_all.rs index 01429bf7ea5..885d1034f21 100644 --- a/clippy_lints/src/lib.register_all.rs +++ b/clippy_lints/src/lib.register_all.rs @@ -134,7 +134,7 @@ store.register_group(true, "clippy::all", Some("clippy_all"), vec![ LintId::of(matches::MATCH_OVERLAPPING_ARM), LintId::of(matches::MATCH_REF_PATS), LintId::of(matches::MATCH_SINGLE_BINDING), - LintId::of(matches::NOP_MATCH), + LintId::of(matches::NEEDLESS_MATCH), LintId::of(matches::REDUNDANT_PATTERN_MATCHING), LintId::of(matches::SINGLE_MATCH), LintId::of(matches::WILDCARD_IN_OR_PATTERNS), diff --git a/clippy_lints/src/lib.register_complexity.rs b/clippy_lints/src/lib.register_complexity.rs index bd5ff613447..88db6c175d6 100644 --- a/clippy_lints/src/lib.register_complexity.rs +++ b/clippy_lints/src/lib.register_complexity.rs @@ -30,6 +30,7 @@ store.register_group(true, "clippy::complexity", Some("clippy_complexity"), vec! LintId::of(map_unit_fn::RESULT_MAP_UNIT_FN), LintId::of(matches::MATCH_AS_REF), LintId::of(matches::MATCH_SINGLE_BINDING), + LintId::of(matches::NEEDLESS_MATCH), LintId::of(matches::WILDCARD_IN_OR_PATTERNS), LintId::of(methods::BIND_INSTEAD_OF_MAP), LintId::of(methods::CLONE_ON_COPY), diff --git a/clippy_lints/src/lib.register_correctness.rs b/clippy_lints/src/lib.register_correctness.rs index 191fa96bdfd..18fe44282ed 100644 --- a/clippy_lints/src/lib.register_correctness.rs +++ b/clippy_lints/src/lib.register_correctness.rs @@ -37,7 +37,6 @@ store.register_group(true, "clippy::correctness", Some("clippy_correctness"), ve LintId::of(loops::NEVER_LOOP), LintId::of(loops::WHILE_IMMUTABLE_CONDITION), LintId::of(match_str_case_mismatch::MATCH_STR_CASE_MISMATCH), - LintId::of(matches::NOP_MATCH), LintId::of(mem_replace::MEM_REPLACE_WITH_UNINIT), LintId::of(methods::CLONE_DOUBLE_REF), LintId::of(methods::ITERATOR_STEP_BY_ZERO), diff --git a/clippy_lints/src/lib.register_lints.rs b/clippy_lints/src/lib.register_lints.rs index 2977a78f257..0d36fe702ef 100644 --- a/clippy_lints/src/lib.register_lints.rs +++ b/clippy_lints/src/lib.register_lints.rs @@ -253,7 +253,7 @@ store.register_lints(&[ matches::MATCH_SINGLE_BINDING, matches::MATCH_WILDCARD_FOR_SINGLE_VARIANTS, matches::MATCH_WILD_ERR_ARM, - matches::NOP_MATCH, + matches::NEEDLESS_MATCH, matches::REDUNDANT_PATTERN_MATCHING, matches::REST_PAT_IN_FULLY_BOUND_STRUCTS, matches::SINGLE_MATCH, diff --git a/clippy_lints/src/matches/mod.rs b/clippy_lints/src/matches/mod.rs index 7c29df0dfb4..ff85623acf4 100644 --- a/clippy_lints/src/matches/mod.rs +++ b/clippy_lints/src/matches/mod.rs @@ -16,7 +16,7 @@ mod match_same_arms; mod match_single_binding; mod match_wild_enum; mod match_wild_err_arm; -mod nop_match; +mod needless_match; mod overlapping_arms; mod redundant_pattern_match; mod rest_pat_in_fully_bound_struct; @@ -605,8 +605,8 @@ declare_clippy_lint! { /// } /// ``` #[clippy::version = "1.61.0"] - pub NOP_MATCH, - correctness, + pub NEEDLESS_MATCH, + complexity, "`match` or match-like `if let` that are unnecessary" } @@ -643,7 +643,7 @@ impl_lint_pass!(Matches => [ REDUNDANT_PATTERN_MATCHING, MATCH_LIKE_MATCHES_MACRO, MATCH_SAME_ARMS, - NOP_MATCH, + NEEDLESS_MATCH, ]); impl<'tcx> LateLintPass<'tcx> for Matches { @@ -667,7 +667,7 @@ impl<'tcx> LateLintPass<'tcx> for Matches { overlapping_arms::check(cx, ex, arms); match_wild_enum::check(cx, ex, arms); match_as_ref::check(cx, ex, arms, expr); - nop_match::check_match(cx, ex, arms); + needless_match::check_match(cx, ex, arms); if self.infallible_destructuring_match_linted { self.infallible_destructuring_match_linted = false; @@ -686,7 +686,7 @@ impl<'tcx> LateLintPass<'tcx> for Matches { match_like_matches::check(cx, expr); } redundant_pattern_match::check(cx, expr); - nop_match::check(cx, expr); + needless_match::check(cx, expr); } } diff --git a/clippy_lints/src/matches/nop_match.rs b/clippy_lints/src/matches/needless_match.rs similarity index 98% rename from clippy_lints/src/matches/nop_match.rs rename to clippy_lints/src/matches/needless_match.rs index f13ee27df47..8d209c6289c 100644 --- a/clippy_lints/src/matches/nop_match.rs +++ b/clippy_lints/src/matches/needless_match.rs @@ -1,4 +1,4 @@ -use super::NOP_MATCH; +use super::NEEDLESS_MATCH; use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_with_applicability; use clippy_utils::ty::is_type_diagnostic_item; @@ -30,7 +30,7 @@ pub(crate) fn check_match(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>]) let mut applicability = Applicability::MachineApplicable; span_lint_and_sugg( cx, - NOP_MATCH, + NEEDLESS_MATCH, match_expr.span, "this match expression is unnecessary", "replace it with", @@ -68,7 +68,7 @@ pub(crate) fn check(cx: &LateContext<'_>, ex: &Expr<'_>) { let mut applicability = Applicability::MachineApplicable; span_lint_and_sugg( cx, - NOP_MATCH, + NEEDLESS_MATCH, ex.span, "this if-let expression is unnecessary", "replace it with", diff --git a/tests/ui/manual_map_option.fixed b/tests/ui/manual_map_option.fixed index 6f71b5d3d32..fc6a7abca0e 100644 --- a/tests/ui/manual_map_option.fixed +++ b/tests/ui/manual_map_option.fixed @@ -148,7 +148,7 @@ fn main() { // #7077 let s = &String::new(); - #[allow(clippy::nop_match)] + #[allow(clippy::needless_match)] let _: Option<&str> = match Some(s) { Some(s) => Some(s), None => None, diff --git a/tests/ui/manual_map_option.rs b/tests/ui/manual_map_option.rs index f1b79f127a0..16508270f64 100644 --- a/tests/ui/manual_map_option.rs +++ b/tests/ui/manual_map_option.rs @@ -214,7 +214,7 @@ fn main() { // #7077 let s = &String::new(); - #[allow(clippy::nop_match)] + #[allow(clippy::needless_match)] let _: Option<&str> = match Some(s) { Some(s) => Some(s), None => None, diff --git a/tests/ui/nop_match.fixed b/tests/ui/needless_match.fixed similarity index 97% rename from tests/ui/nop_match.fixed rename to tests/ui/needless_match.fixed index 8875323a1bb..eb6494a4da6 100644 --- a/tests/ui/nop_match.fixed +++ b/tests/ui/needless_match.fixed @@ -1,5 +1,5 @@ // run-rustfix -#![warn(clippy::nop_match)] +#![warn(clippy::needless_match)] #![allow(clippy::manual_map)] #![allow(dead_code)] diff --git a/tests/ui/nop_match.rs b/tests/ui/needless_match.rs similarity index 98% rename from tests/ui/nop_match.rs rename to tests/ui/needless_match.rs index 19469a86022..43f1391d67c 100644 --- a/tests/ui/nop_match.rs +++ b/tests/ui/needless_match.rs @@ -1,5 +1,5 @@ // run-rustfix -#![warn(clippy::nop_match)] +#![warn(clippy::needless_match)] #![allow(clippy::manual_map)] #![allow(dead_code)] diff --git a/tests/ui/nop_match.stderr b/tests/ui/needless_match.stderr similarity index 86% rename from tests/ui/nop_match.stderr rename to tests/ui/needless_match.stderr index b7a1967bf5f..d11d4fd3322 100644 --- a/tests/ui/nop_match.stderr +++ b/tests/ui/needless_match.stderr @@ -1,5 +1,5 @@ error: this match expression is unnecessary - --> $DIR/nop_match.rs:15:18 + --> $DIR/needless_match.rs:15:18 | LL | let _: i32 = match x { | __________________^ @@ -10,10 +10,10 @@ LL | | _ => x, LL | | }; | |_____^ help: replace it with: `x` | - = note: `-D clippy::nop-match` implied by `-D warnings` + = note: `-D clippy::needless-match` implied by `-D warnings` error: this match expression is unnecessary - --> $DIR/nop_match.rs:24:21 + --> $DIR/needless_match.rs:24:21 | LL | let _: Choice = match se { | _____________________^ @@ -25,7 +25,7 @@ LL | | }; | |_____^ help: replace it with: `se` error: this match expression is unnecessary - --> $DIR/nop_match.rs:46:26 + --> $DIR/needless_match.rs:46:26 | LL | let _: Option = match x { | __________________________^ @@ -35,7 +35,7 @@ LL | | }; | |_____^ help: replace it with: `x` error: this match expression is unnecessary - --> $DIR/nop_match.rs:62:31 + --> $DIR/needless_match.rs:62:31 | LL | let _: Result = match Ok(1) { | _______________________________^ @@ -45,7 +45,7 @@ LL | | }; | |_____^ help: replace it with: `Ok(1)` error: this match expression is unnecessary - --> $DIR/nop_match.rs:66:31 + --> $DIR/needless_match.rs:66:31 | LL | let _: Result = match func_ret_err(0_i32) { | _______________________________^ @@ -55,25 +55,25 @@ LL | | }; | |_____^ help: replace it with: `func_ret_err(0_i32)` error: this if-let expression is unnecessary - --> $DIR/nop_match.rs:73:5 + --> $DIR/needless_match.rs:73:5 | LL | if let Some(a) = Some(1) { Some(a) } else { None } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `Some(1)` error: this if-let expression is unnecessary - --> $DIR/nop_match.rs:77:30 + --> $DIR/needless_match.rs:77:30 | LL | let _: Result<(), i32> = if let Err(e) = x { Err(e) } else { x }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `x` error: this if-let expression is unnecessary - --> $DIR/nop_match.rs:78:30 + --> $DIR/needless_match.rs:78:30 | LL | let _: Result<(), i32> = if let Ok(val) = x { Ok(val) } else { x }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `x` error: this if-let expression is unnecessary - --> $DIR/nop_match.rs:84:21 + --> $DIR/needless_match.rs:84:21 | LL | let _: Choice = if let Choice::A = x { | _____________________^