Skip to content

Commit 6639659

Browse files
committed
fix match_like_matches_macro in clippy
1 parent 2956167 commit 6639659

27 files changed

+90
-186
lines changed

clippy_lints/src/assign_ops.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ fn is_commutative(op: hir::BinOpKind) -> bool {
237237
use rustc_hir::BinOpKind::{
238238
Add, And, BitAnd, BitOr, BitXor, Div, Eq, Ge, Gt, Le, Lt, Mul, Ne, Or, Rem, Shl, Shr, Sub,
239239
};
240+
#[allow(clippy::match_like_matches_macro)]
240241
match op {
241242
Add | Mul | And | Or | BitXor | BitAnd | BitOr | Eq | Ne => true,
242243
Sub | Div | Rem | Shl | Shr | Lt | Le | Ge | Gt => false,

clippy_lints/src/comparison_chain.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,5 @@ impl<'tcx> LateLintPass<'tcx> for ComparisonChain {
122122
}
123123

124124
fn kind_is_cmp(kind: BinOpKind) -> bool {
125-
match kind {
126-
BinOpKind::Lt | BinOpKind::Gt | BinOpKind::Eq => true,
127-
_ => false,
128-
}
125+
matches!(kind, BinOpKind::Lt | BinOpKind::Gt | BinOpKind::Eq)
129126
}

clippy_lints/src/eq_op.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -214,20 +214,20 @@ impl<'tcx> LateLintPass<'tcx> for EqOp {
214214
}
215215

216216
fn is_valid_operator(op: BinOp) -> bool {
217-
match op.node {
217+
matches!(
218+
op.node,
218219
BinOpKind::Sub
219-
| BinOpKind::Div
220-
| BinOpKind::Eq
221-
| BinOpKind::Lt
222-
| BinOpKind::Le
223-
| BinOpKind::Gt
224-
| BinOpKind::Ge
225-
| BinOpKind::Ne
226-
| BinOpKind::And
227-
| BinOpKind::Or
228-
| BinOpKind::BitXor
229-
| BinOpKind::BitAnd
230-
| BinOpKind::BitOr => true,
231-
_ => false,
232-
}
220+
| BinOpKind::Div
221+
| BinOpKind::Eq
222+
| BinOpKind::Lt
223+
| BinOpKind::Le
224+
| BinOpKind::Gt
225+
| BinOpKind::Ge
226+
| BinOpKind::Ne
227+
| BinOpKind::And
228+
| BinOpKind::Or
229+
| BinOpKind::BitXor
230+
| BinOpKind::BitAnd
231+
| BinOpKind::BitOr
232+
)
233233
}

clippy_lints/src/escape.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,7 @@ fn is_argument(map: rustc_middle::hir::map::Map<'_>, id: HirId) -> bool {
105105
_ => return false,
106106
}
107107

108-
match map.find(map.get_parent_node(id)) {
109-
Some(Node::Param(_)) => true,
110-
_ => false,
111-
}
108+
matches!(map.find(map.get_parent_node(id)), Some(Node::Param(_)))
112109
}
113110

114111
impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {

clippy_lints/src/eta_reduction.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,7 @@ fn get_ufcs_type_name(cx: &LateContext<'_>, method_def_id: def_id::DefId, self_a
175175
fn match_borrow_depth(lhs: Ty<'_>, rhs: Ty<'_>) -> bool {
176176
match (&lhs.kind, &rhs.kind) {
177177
(ty::Ref(_, t1, mut1), ty::Ref(_, t2, mut2)) => mut1 == mut2 && match_borrow_depth(&t1, &t2),
178-
(l, r) => match (l, r) {
179-
(ty::Ref(_, _, _), _) | (_, ty::Ref(_, _, _)) => false,
180-
(_, _) => true,
181-
},
178+
(l, r) => !matches!((l, r), (ty::Ref(_, _, _), _) | (_, ty::Ref(_, _, _))),
182179
}
183180
}
184181

clippy_lints/src/formatting.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -305,18 +305,10 @@ fn check_missing_else(cx: &EarlyContext<'_>, first: &Expr, second: &Expr) {
305305
}
306306

307307
fn is_block(expr: &Expr) -> bool {
308-
if let ExprKind::Block(..) = expr.kind {
309-
true
310-
} else {
311-
false
312-
}
308+
matches!(expr.kind, ExprKind::Block(..))
313309
}
314310

315311
/// Check if the expression is an `if` or `if let`
316312
fn is_if(expr: &Expr) -> bool {
317-
if let ExprKind::If(..) = expr.kind {
318-
true
319-
} else {
320-
false
321-
}
313+
matches!(expr.kind, ExprKind::If(..))
322314
}

clippy_lints/src/functions.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -645,13 +645,7 @@ fn is_mutated_static(cx: &LateContext<'_>, e: &hir::Expr<'_>) -> bool {
645645
use hir::ExprKind::{Field, Index, Path};
646646

647647
match e.kind {
648-
Path(ref qpath) => {
649-
if let Res::Local(_) = qpath_res(cx, qpath, e.hir_id) {
650-
false
651-
} else {
652-
true
653-
}
654-
},
648+
Path(ref qpath) => !matches!(qpath_res(cx, qpath, e.hir_id), Res::Local(_)),
655649
Field(ref inner, _) | Index(ref inner, _) => is_mutated_static(cx, inner),
656650
_ => false,
657651
}

clippy_lints/src/lib.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,6 @@ mod question_mark;
276276
mod ranges;
277277
mod redundant_clone;
278278
mod redundant_field_names;
279-
mod redundant_pattern_matching;
280279
mod redundant_pub_crate;
281280
mod redundant_static_lifetimes;
282281
mod reference;
@@ -622,11 +621,13 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
622621
&matches::INFALLIBLE_DESTRUCTURING_MATCH,
623622
&matches::MATCH_AS_REF,
624623
&matches::MATCH_BOOL,
624+
&matches::MATCH_LIKE_MATCHES_MACRO,
625625
&matches::MATCH_OVERLAPPING_ARM,
626626
&matches::MATCH_REF_PATS,
627627
&matches::MATCH_SINGLE_BINDING,
628628
&matches::MATCH_WILDCARD_FOR_SINGLE_VARIANTS,
629629
&matches::MATCH_WILD_ERR_ARM,
630+
&matches::REDUNDANT_PATTERN_MATCHING,
630631
&matches::REST_PAT_IN_FULLY_BOUND_STRUCTS,
631632
&matches::SINGLE_MATCH,
632633
&matches::SINGLE_MATCH_ELSE,
@@ -755,7 +756,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
755756
&ranges::REVERSED_EMPTY_RANGES,
756757
&redundant_clone::REDUNDANT_CLONE,
757758
&redundant_field_names::REDUNDANT_FIELD_NAMES,
758-
&redundant_pattern_matching::REDUNDANT_PATTERN_MATCHING,
759759
&redundant_pub_crate::REDUNDANT_PUB_CRATE,
760760
&redundant_static_lifetimes::REDUNDANT_STATIC_LIFETIMES,
761761
&reference::DEREF_ADDROF,
@@ -954,7 +954,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
954954
store.register_late_pass(|| box missing_doc::MissingDoc::new());
955955
store.register_late_pass(|| box missing_inline::MissingInline);
956956
store.register_late_pass(|| box if_let_some_result::OkIfLet);
957-
store.register_late_pass(|| box redundant_pattern_matching::RedundantPatternMatching);
958957
store.register_late_pass(|| box partialeq_ne_impl::PartialEqNeImpl);
959958
store.register_late_pass(|| box unused_io_amount::UnusedIoAmount);
960959
let enum_variant_size_threshold = conf.enum_variant_size_threshold;
@@ -1291,9 +1290,11 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
12911290
LintId::of(&map_unit_fn::RESULT_MAP_UNIT_FN),
12921291
LintId::of(&matches::INFALLIBLE_DESTRUCTURING_MATCH),
12931292
LintId::of(&matches::MATCH_AS_REF),
1293+
LintId::of(&matches::MATCH_LIKE_MATCHES_MACRO),
12941294
LintId::of(&matches::MATCH_OVERLAPPING_ARM),
12951295
LintId::of(&matches::MATCH_REF_PATS),
12961296
LintId::of(&matches::MATCH_SINGLE_BINDING),
1297+
LintId::of(&matches::REDUNDANT_PATTERN_MATCHING),
12971298
LintId::of(&matches::SINGLE_MATCH),
12981299
LintId::of(&matches::WILDCARD_IN_OR_PATTERNS),
12991300
LintId::of(&mem_discriminant::MEM_DISCRIMINANT_NON_ENUM),
@@ -1383,7 +1384,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
13831384
LintId::of(&ranges::REVERSED_EMPTY_RANGES),
13841385
LintId::of(&redundant_clone::REDUNDANT_CLONE),
13851386
LintId::of(&redundant_field_names::REDUNDANT_FIELD_NAMES),
1386-
LintId::of(&redundant_pattern_matching::REDUNDANT_PATTERN_MATCHING),
13871387
LintId::of(&redundant_static_lifetimes::REDUNDANT_STATIC_LIFETIMES),
13881388
LintId::of(&reference::DEREF_ADDROF),
13891389
LintId::of(&reference::REF_IN_DEREF),
@@ -1484,8 +1484,10 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
14841484
LintId::of(&manual_non_exhaustive::MANUAL_NON_EXHAUSTIVE),
14851485
LintId::of(&map_clone::MAP_CLONE),
14861486
LintId::of(&matches::INFALLIBLE_DESTRUCTURING_MATCH),
1487+
LintId::of(&matches::MATCH_LIKE_MATCHES_MACRO),
14871488
LintId::of(&matches::MATCH_OVERLAPPING_ARM),
14881489
LintId::of(&matches::MATCH_REF_PATS),
1490+
LintId::of(&matches::REDUNDANT_PATTERN_MATCHING),
14891491
LintId::of(&matches::SINGLE_MATCH),
14901492
LintId::of(&mem_replace::MEM_REPLACE_OPTION_WITH_NONE),
14911493
LintId::of(&mem_replace::MEM_REPLACE_WITH_DEFAULT),
@@ -1522,7 +1524,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
15221524
LintId::of(&ptr::PTR_ARG),
15231525
LintId::of(&question_mark::QUESTION_MARK),
15241526
LintId::of(&redundant_field_names::REDUNDANT_FIELD_NAMES),
1525-
LintId::of(&redundant_pattern_matching::REDUNDANT_PATTERN_MATCHING),
15261527
LintId::of(&redundant_static_lifetimes::REDUNDANT_STATIC_LIFETIMES),
15271528
LintId::of(&regex::TRIVIAL_REGEX),
15281529
LintId::of(&returns::NEEDLESS_RETURN),

clippy_lints/src/lifetimes.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,10 @@ fn check_fn_inner<'tcx>(
129129
}
130130

131131
let mut bounds_lts = Vec::new();
132-
let types = generics.params.iter().filter(|param| match param.kind {
133-
GenericParamKind::Type { .. } => true,
134-
_ => false,
135-
});
132+
let types = generics
133+
.params
134+
.iter()
135+
.filter(|param| matches!(param.kind, GenericParamKind::Type { .. }));
136136
for typ in types {
137137
for bound in typ.bounds {
138138
let mut visitor = RefVisitor::new(cx);
@@ -337,10 +337,10 @@ impl<'a, 'tcx> RefVisitor<'a, 'tcx> {
337337
fn collect_anonymous_lifetimes(&mut self, qpath: &QPath<'_>, ty: &Ty<'_>) {
338338
if let Some(ref last_path_segment) = last_path_segment(qpath).args {
339339
if !last_path_segment.parenthesized
340-
&& !last_path_segment.args.iter().any(|arg| match arg {
341-
GenericArg::Lifetime(_) => true,
342-
_ => false,
343-
})
340+
&& !last_path_segment
341+
.args
342+
.iter()
343+
.any(|arg| matches!(arg, GenericArg::Lifetime(_)))
344344
{
345345
let hir_id = ty.hir_id;
346346
match self.cx.qpath_res(qpath, hir_id) {

clippy_lints/src/loops.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2105,17 +2105,11 @@ fn var_def_id(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option<HirId> {
21052105
}
21062106

21072107
fn is_loop(expr: &Expr<'_>) -> bool {
2108-
match expr.kind {
2109-
ExprKind::Loop(..) => true,
2110-
_ => false,
2111-
}
2108+
matches!(expr.kind, ExprKind::Loop(..))
21122109
}
21132110

21142111
fn is_conditional(expr: &Expr<'_>) -> bool {
2115-
match expr.kind {
2116-
ExprKind::Match(..) => true,
2117-
_ => false,
2118-
}
2112+
matches!(expr.kind, ExprKind::Match(..))
21192113
}
21202114

21212115
fn is_nested(cx: &LateContext<'_>, match_expr: &Expr<'_>, iter_expr: &Expr<'_>) -> bool {

0 commit comments

Comments
 (0)