Skip to content

Commit 702d822

Browse files
committed
fix match_like_matches_macro in clippy
1 parent 2956167 commit 702d822

26 files changed

+88
-179
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
@@ -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

+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
@@ -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 {

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
@@ -700,12 +700,7 @@ fn in_attributes_expansion(expr: &Expr<'_>) -> bool {
700700
use rustc_span::hygiene::MacroKind;
701701
if expr.span.from_expansion() {
702702
let data = expr.span.ctxt().outer_expn_data();
703-
704-
if let ExpnKind::Macro(MacroKind::Attr, _) = data.kind {
705-
true
706-
} else {
707-
false
708-
}
703+
matches!(data.kind, ExpnKind::Macro(MacroKind::Attr, _))
709704
} else {
710705
false
711706
}

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)