Skip to content

Commit 1740dda

Browse files
committed
fix match_like_matches_macro in clippy
1 parent 2e8a1be commit 1740dda

27 files changed

+91
-186
lines changed

clippy_lints/src/assign_ops.rs

+1
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

+1-4
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

+15-15
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

+1-4
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

+1-4
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

+2-10
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

+1-7
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

+6-5
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,6 @@ mod question_mark;
277277
mod ranges;
278278
mod redundant_clone;
279279
mod redundant_field_names;
280-
mod redundant_pattern_matching;
281280
mod redundant_pub_crate;
282281
mod redundant_static_lifetimes;
283282
mod reference;
@@ -623,11 +622,13 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
623622
&matches::INFALLIBLE_DESTRUCTURING_MATCH,
624623
&matches::MATCH_AS_REF,
625624
&matches::MATCH_BOOL,
625+
&matches::MATCH_LIKE_MATCHES_MACRO,
626626
&matches::MATCH_OVERLAPPING_ARM,
627627
&matches::MATCH_REF_PATS,
628628
&matches::MATCH_SINGLE_BINDING,
629629
&matches::MATCH_WILDCARD_FOR_SINGLE_VARIANTS,
630630
&matches::MATCH_WILD_ERR_ARM,
631+
&matches::REDUNDANT_PATTERN_MATCHING,
631632
&matches::REST_PAT_IN_FULLY_BOUND_STRUCTS,
632633
&matches::SINGLE_MATCH,
633634
&matches::SINGLE_MATCH_ELSE,
@@ -757,7 +758,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
757758
&ranges::REVERSED_EMPTY_RANGES,
758759
&redundant_clone::REDUNDANT_CLONE,
759760
&redundant_field_names::REDUNDANT_FIELD_NAMES,
760-
&redundant_pattern_matching::REDUNDANT_PATTERN_MATCHING,
761761
&redundant_pub_crate::REDUNDANT_PUB_CRATE,
762762
&redundant_static_lifetimes::REDUNDANT_STATIC_LIFETIMES,
763763
&reference::DEREF_ADDROF,
@@ -956,7 +956,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
956956
store.register_late_pass(|| box missing_doc::MissingDoc::new());
957957
store.register_late_pass(|| box missing_inline::MissingInline);
958958
store.register_late_pass(|| box if_let_some_result::OkIfLet);
959-
store.register_late_pass(|| box redundant_pattern_matching::RedundantPatternMatching);
960959
store.register_late_pass(|| box partialeq_ne_impl::PartialEqNeImpl);
961960
store.register_late_pass(|| box unused_io_amount::UnusedIoAmount);
962961
let enum_variant_size_threshold = conf.enum_variant_size_threshold;
@@ -1295,9 +1294,11 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
12951294
LintId::of(&map_unit_fn::RESULT_MAP_UNIT_FN),
12961295
LintId::of(&matches::INFALLIBLE_DESTRUCTURING_MATCH),
12971296
LintId::of(&matches::MATCH_AS_REF),
1297+
LintId::of(&matches::MATCH_LIKE_MATCHES_MACRO),
12981298
LintId::of(&matches::MATCH_OVERLAPPING_ARM),
12991299
LintId::of(&matches::MATCH_REF_PATS),
13001300
LintId::of(&matches::MATCH_SINGLE_BINDING),
1301+
LintId::of(&matches::REDUNDANT_PATTERN_MATCHING),
13011302
LintId::of(&matches::SINGLE_MATCH),
13021303
LintId::of(&matches::WILDCARD_IN_OR_PATTERNS),
13031304
LintId::of(&mem_discriminant::MEM_DISCRIMINANT_NON_ENUM),
@@ -1387,7 +1388,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
13871388
LintId::of(&ranges::REVERSED_EMPTY_RANGES),
13881389
LintId::of(&redundant_clone::REDUNDANT_CLONE),
13891390
LintId::of(&redundant_field_names::REDUNDANT_FIELD_NAMES),
1390-
LintId::of(&redundant_pattern_matching::REDUNDANT_PATTERN_MATCHING),
13911391
LintId::of(&redundant_static_lifetimes::REDUNDANT_STATIC_LIFETIMES),
13921392
LintId::of(&reference::DEREF_ADDROF),
13931393
LintId::of(&reference::REF_IN_DEREF),
@@ -1488,8 +1488,10 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
14881488
LintId::of(&manual_non_exhaustive::MANUAL_NON_EXHAUSTIVE),
14891489
LintId::of(&map_clone::MAP_CLONE),
14901490
LintId::of(&matches::INFALLIBLE_DESTRUCTURING_MATCH),
1491+
LintId::of(&matches::MATCH_LIKE_MATCHES_MACRO),
14911492
LintId::of(&matches::MATCH_OVERLAPPING_ARM),
14921493
LintId::of(&matches::MATCH_REF_PATS),
1494+
LintId::of(&matches::REDUNDANT_PATTERN_MATCHING),
14931495
LintId::of(&matches::SINGLE_MATCH),
14941496
LintId::of(&mem_replace::MEM_REPLACE_OPTION_WITH_NONE),
14951497
LintId::of(&mem_replace::MEM_REPLACE_WITH_DEFAULT),
@@ -1526,7 +1528,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
15261528
LintId::of(&ptr::PTR_ARG),
15271529
LintId::of(&question_mark::QUESTION_MARK),
15281530
LintId::of(&redundant_field_names::REDUNDANT_FIELD_NAMES),
1529-
LintId::of(&redundant_pattern_matching::REDUNDANT_PATTERN_MATCHING),
15301531
LintId::of(&redundant_static_lifetimes::REDUNDANT_STATIC_LIFETIMES),
15311532
LintId::of(&regex::TRIVIAL_REGEX),
15321533
LintId::of(&returns::NEEDLESS_RETURN),

clippy_lints/src/lifetimes.rs

+8-8
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

+2-8
Original file line numberDiff line numberDiff line change
@@ -2091,17 +2091,11 @@ fn var_def_id(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option<HirId> {
20912091
}
20922092

20932093
fn is_loop(expr: &Expr<'_>) -> bool {
2094-
match expr.kind {
2095-
ExprKind::Loop(..) => true,
2096-
_ => false,
2097-
}
2094+
matches!(expr.kind, ExprKind::Loop(..))
20982095
}
20992096

21002097
fn is_conditional(expr: &Expr<'_>) -> bool {
2101-
match expr.kind {
2102-
ExprKind::Match(..) => true,
2103-
_ => false,
2104-
}
2098+
matches!(expr.kind, ExprKind::Match(..))
21052099
}
21062100

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

clippy_lints/src/methods/mod.rs

+5-11
Original file line numberDiff line numberDiff line change
@@ -1844,10 +1844,10 @@ fn lint_expect_fun_call(
18441844
ty::Ref(ty::ReStatic, ..)
18451845
)
18461846
}),
1847-
hir::ExprKind::Path(ref p) => match cx.qpath_res(p, arg.hir_id) {
1848-
hir::def::Res::Def(hir::def::DefKind::Const | hir::def::DefKind::Static, _) => true,
1849-
_ => false,
1850-
},
1847+
hir::ExprKind::Path(ref p) => matches!(
1848+
cx.qpath_res(p, arg.hir_id),
1849+
hir::def::Res::Def(hir::def::DefKind::Const | hir::def::DefKind::Static, _)
1850+
),
18511851
_ => false,
18521852
}
18531853
}
@@ -2028,13 +2028,7 @@ fn lint_clone_on_copy(cx: &LateContext<'_>, expr: &hir::Expr<'_>, arg: &hir::Exp
20282028
.tables()
20292029
.expr_adjustments(arg)
20302030
.iter()
2031-
.filter(|adj| {
2032-
if let ty::adjustment::Adjust::Deref(_) = adj.kind {
2033-
true
2034-
} else {
2035-
false
2036-
}
2037-
})
2031+
.filter(|adj| matches!(adj.kind, ty::adjustment::Adjust::Deref(_)))
20382032
.count();
20392033
let derefs: String = iter::repeat('*').take(deref_count).collect();
20402034
snip = Some(("try dereferencing it", format!("{}{}", derefs, snippet)));

clippy_lints/src/misc.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -694,12 +694,7 @@ fn in_attributes_expansion(expr: &Expr<'_>) -> bool {
694694
use rustc_span::hygiene::MacroKind;
695695
if expr.span.from_expansion() {
696696
let data = expr.span.ctxt().outer_expn_data();
697-
698-
if let ExpnKind::Macro(MacroKind::Attr, _) = data.kind {
699-
true
700-
} else {
701-
false
702-
}
697+
matches!(data.kind, ExpnKind::Macro(MacroKind::Attr, _))
703698
} else {
704699
false
705700
}

clippy_lints/src/misc_early.rs

+6-12
Original file line numberDiff line numberDiff line change
@@ -641,28 +641,22 @@ fn check_unneeded_wildcard_pattern(cx: &EarlyContext<'_>, pat: &Pat) {
641641
);
642642
}
643643

644-
#[allow(clippy::trivially_copy_pass_by_ref)]
645-
fn is_wild<P: std::ops::Deref<Target = Pat>>(pat: &&P) -> bool {
646-
if let PatKind::Wild = pat.kind {
647-
true
648-
} else {
649-
false
650-
}
651-
}
652-
653644
if let Some(rest_index) = patterns.iter().position(|pat| pat.is_rest()) {
654645
if let Some((left_index, left_pat)) = patterns[..rest_index]
655646
.iter()
656647
.rev()
657-
.take_while(is_wild)
648+
.take_while(|pat| matches!(pat.kind, PatKind::Wild))
658649
.enumerate()
659650
.last()
660651
{
661652
span_lint(cx, left_pat.span.until(patterns[rest_index].span), left_index == 0);
662653
}
663654

664-
if let Some((right_index, right_pat)) =
665-
patterns[rest_index + 1..].iter().take_while(is_wild).enumerate().last()
655+
if let Some((right_index, right_pat)) = patterns[rest_index + 1..]
656+
.iter()
657+
.take_while(|pat| matches!(pat.kind, PatKind::Wild))
658+
.enumerate()
659+
.last()
666660
{
667661
span_lint(
668662
cx,

clippy_lints/src/missing_inline.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,11 @@ fn check_missing_inline_attrs(cx: &LateContext<'_>, attrs: &[ast::Attribute], sp
7171
fn is_executable(cx: &LateContext<'_>) -> bool {
7272
use rustc_session::config::CrateType;
7373

74-
cx.tcx.sess.crate_types().iter().any(|t: &CrateType| match t {
75-
CrateType::Executable => true,
76-
_ => false,
77-
})
74+
cx.tcx
75+
.sess
76+
.crate_types()
77+
.iter()
78+
.any(|t: &CrateType| matches!(t, CrateType::Executable))
7879
}
7980

8081
declare_lint_pass!(MissingInline => [MISSING_INLINE_IN_PUBLIC_ITEMS]);

clippy_lints/src/new_without_default.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,12 @@ impl<'tcx> LateLintPass<'tcx> for NewWithoutDefault {
8080
// can't be implemented for unsafe new
8181
return;
8282
}
83-
if impl_item.generics.params.iter().any(|gen| match gen.kind {
84-
hir::GenericParamKind::Type { .. } => true,
85-
_ => false,
86-
}) {
83+
if impl_item
84+
.generics
85+
.params
86+
.iter()
87+
.any(|gen| matches!(gen.kind, hir::GenericParamKind::Type { .. }))
88+
{
8789
// when the result of `new()` depends on a type parameter we should not require
8890
// an
8991
// impl of `Default`

clippy_lints/src/non_copy_const.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -238,10 +238,10 @@ impl<'tcx> LateLintPass<'tcx> for NonCopyConst {
238238

239239
let ty = if needs_check_adjustment {
240240
let adjustments = cx.tables().expr_adjustments(dereferenced_expr);
241-
if let Some(i) = adjustments.iter().position(|adj| match adj.kind {
242-
Adjust::Borrow(_) | Adjust::Deref(_) => true,
243-
_ => false,
244-
}) {
241+
if let Some(i) = adjustments
242+
.iter()
243+
.position(|adj| matches!(adj.kind, Adjust::Borrow(_) | Adjust::Deref(_)))
244+
{
245245
if i == 0 {
246246
cx.tables().expr_ty(dereferenced_expr)
247247
} else {

clippy_lints/src/precedence.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -148,17 +148,11 @@ fn is_arith_expr(expr: &Expr) -> bool {
148148
#[must_use]
149149
fn is_bit_op(op: BinOpKind) -> bool {
150150
use rustc_ast::ast::BinOpKind::{BitAnd, BitOr, BitXor, Shl, Shr};
151-
match op {
152-
BitXor | BitAnd | BitOr | Shl | Shr => true,
153-
_ => false,
154-
}
151+
matches!(op, BitXor | BitAnd | BitOr | Shl | Shr)
155152
}
156153

157154
#[must_use]
158155
fn is_arith_op(op: BinOpKind) -> bool {
159156
use rustc_ast::ast::BinOpKind::{Add, Div, Mul, Rem, Sub};
160-
match op {
161-
Add | Sub | Mul | Div | Rem => true,
162-
_ => false,
163-
}
157+
matches!(op, Add | Sub | Mul | Div | Rem)
164158
}

0 commit comments

Comments
 (0)