Skip to content

Commit

Permalink
rename lint to needless_match
Browse files Browse the repository at this point in the history
and change its lint group to "complexity"
  • Loading branch information
J-ZhengLi committed Mar 10, 2022
1 parent 750204e commit ec91164
Show file tree
Hide file tree
Showing 12 changed files with 27 additions and 27 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/lib.register_all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
1 change: 1 addition & 0 deletions clippy_lints/src/lib.register_complexity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
1 change: 0 additions & 1 deletion clippy_lints/src/lib.register_correctness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/lib.register_lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 6 additions & 6 deletions clippy_lints/src/matches/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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"
}

Expand Down Expand Up @@ -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 {
Expand All @@ -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;
Expand All @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/manual_map_option.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/manual_map_option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/nop_match.fixed → tests/ui/needless_match.fixed
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// run-rustfix
#![warn(clippy::nop_match)]
#![warn(clippy::needless_match)]
#![allow(clippy::manual_map)]
#![allow(dead_code)]

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/nop_match.rs → tests/ui/needless_match.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// run-rustfix
#![warn(clippy::nop_match)]
#![warn(clippy::needless_match)]
#![allow(clippy::manual_map)]
#![allow(dead_code)]

Expand Down
20 changes: 10 additions & 10 deletions tests/ui/nop_match.stderr → tests/ui/needless_match.stderr
Original file line number Diff line number Diff line change
@@ -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 {
| __________________^
Expand All @@ -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 {
| _____________________^
Expand All @@ -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<i32> = match x {
| __________________________^
Expand All @@ -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<i32, i32> = match Ok(1) {
| _______________________________^
Expand All @@ -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<i32, i32> = match func_ret_err(0_i32) {
| _______________________________^
Expand All @@ -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 {
| _____________________^
Expand Down

0 comments on commit ec91164

Please sign in to comment.