Skip to content

Commit e86579d

Browse files
committed
dogfood unnested_or_patterns
1 parent bf43c53 commit e86579d

File tree

9 files changed

+48
-70
lines changed

9 files changed

+48
-70
lines changed

clippy_lints/src/formatting.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,8 @@ declare_lint_pass!(Formatting => [
112112
impl EarlyLintPass for Formatting {
113113
fn check_block(&mut self, cx: &EarlyContext<'_>, block: &Block) {
114114
for w in block.stmts.windows(2) {
115-
match (&w[0].kind, &w[1].kind) {
116-
(&StmtKind::Expr(ref first), &StmtKind::Expr(ref second))
117-
| (&StmtKind::Expr(ref first), &StmtKind::Semi(ref second)) => {
118-
check_missing_else(cx, first, second);
119-
},
120-
_ => (),
115+
if let (StmtKind::Expr(first), StmtKind::Expr(second) | StmtKind::Semi(second)) = (&w[0].kind, &w[1].kind) {
116+
check_missing_else(cx, first, second);
121117
}
122118
}
123119
}

clippy_lints/src/methods/manual_saturating_arithmetic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ pub fn lint(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, args: &[&[hir::Expr<
5757
);
5858
} else {
5959
match (mm, arith) {
60-
(MinMax::Max, "add") | (MinMax::Max, "mul") | (MinMax::Min, "sub") => (),
60+
(MinMax::Max, "add" | "mul") | (MinMax::Min, "sub") => (),
6161
_ => return,
6262
}
6363

clippy_lints/src/methods/mod.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,9 +1327,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Methods {
13271327
lint_search_is_some(cx, expr, "rposition", arg_lists[1], arg_lists[0], method_spans[1])
13281328
},
13291329
["extend", ..] => lint_extend(cx, expr, arg_lists[0]),
1330-
["as_ptr", "unwrap"] | ["as_ptr", "expect"] => {
1331-
lint_cstring_as_ptr(cx, expr, &arg_lists[1][0], &arg_lists[0][0])
1332-
},
1330+
["as_ptr", "unwrap" | "expect"] => lint_cstring_as_ptr(cx, expr, &arg_lists[1][0], &arg_lists[0][0]),
13331331
["nth", "iter"] => lint_iter_nth(cx, expr, &arg_lists, false),
13341332
["nth", "iter_mut"] => lint_iter_nth(cx, expr, &arg_lists, true),
13351333
["nth", ..] => lint_iter_nth_zero(cx, expr, arg_lists[0]),
@@ -1342,12 +1340,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Methods {
13421340
["filter_map", ..] => unnecessary_filter_map::lint(cx, expr, arg_lists[0]),
13431341
["count", "map"] => lint_suspicious_map(cx, expr),
13441342
["assume_init"] => lint_maybe_uninit(cx, &arg_lists[0][0], expr),
1345-
["unwrap_or", arith @ "checked_add"]
1346-
| ["unwrap_or", arith @ "checked_sub"]
1347-
| ["unwrap_or", arith @ "checked_mul"] => {
1343+
["unwrap_or", arith @ ("checked_add" | "checked_sub" | "checked_mul")] => {
13481344
manual_saturating_arithmetic::lint(cx, expr, &arg_lists, &arith["checked_".len()..])
13491345
},
1350-
["add"] | ["offset"] | ["sub"] | ["wrapping_offset"] | ["wrapping_add"] | ["wrapping_sub"] => {
1346+
["add" | "offset" | "sub" | "wrapping_offset" | "wrapping_add" | "wrapping_sub"] => {
13511347
check_pointer_offset(cx, expr, arg_lists[0])
13521348
},
13531349
["is_file", ..] => lint_filetype_is_file(cx, expr, arg_lists[0]),
@@ -1736,8 +1732,7 @@ fn lint_expect_fun_call(
17361732
hir::ExprKind::Call(fun, _) => {
17371733
if let hir::ExprKind::Path(ref p) = fun.kind {
17381734
match cx.tables.qpath_res(p, fun.hir_id) {
1739-
hir::def::Res::Def(hir::def::DefKind::Fn, def_id)
1740-
| hir::def::Res::Def(hir::def::DefKind::AssocFn, def_id) => matches!(
1735+
hir::def::Res::Def(hir::def::DefKind::Fn | hir::def::DefKind::AssocFn, def_id) => matches!(
17411736
cx.tcx.fn_sig(def_id).output().skip_binder().kind,
17421737
ty::Ref(ty::ReStatic, ..)
17431738
),

clippy_lints/src/misc.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -248,17 +248,14 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MiscLints {
248248
return;
249249
}
250250
for arg in iter_input_pats(decl, body) {
251-
match arg.pat.kind {
252-
PatKind::Binding(BindingAnnotation::Ref, ..) | PatKind::Binding(BindingAnnotation::RefMut, ..) => {
253-
span_lint(
254-
cx,
255-
TOPLEVEL_REF_ARG,
256-
arg.pat.span,
257-
"`ref` directly on a function argument is ignored. Consider using a reference type \
258-
instead.",
259-
);
260-
},
261-
_ => {},
251+
if let PatKind::Binding(BindingAnnotation::Ref | BindingAnnotation::RefMut, ..) = arg.pat.kind {
252+
span_lint(
253+
cx,
254+
TOPLEVEL_REF_ARG,
255+
arg.pat.span,
256+
"`ref` directly on a function argument is ignored. \
257+
Consider using a reference type instead.",
258+
);
262259
}
263260
}
264261
}

clippy_lints/src/no_effect.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ fn reduce_expression<'a>(cx: &LateContext<'_, '_>, expr: &'a Expr<'a>) -> Option
147147
if let ExprKind::Path(ref qpath) = callee.kind {
148148
let res = qpath_res(cx, qpath, callee.hir_id);
149149
match res {
150-
Res::Def(DefKind::Struct, ..) | Res::Def(DefKind::Variant, ..) | Res::Def(DefKind::Ctor(..), _)
150+
Res::Def(DefKind::Struct | DefKind::Variant | DefKind::Ctor(..), ..)
151151
if !has_drop(cx, cx.tables.expr_ty(expr)) =>
152152
{
153153
Some(args.iter().collect())

clippy_lints/src/suspicious_trait_impl.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for SuspiciousImpl {
6969
let mut parent_expr = cx.tcx.hir().get_parent_node(expr.hir_id);
7070
while parent_expr != hir::CRATE_HIR_ID {
7171
if let hir::Node::Expr(e) = cx.tcx.hir().get(parent_expr) {
72-
match e.kind {
73-
hir::ExprKind::Binary(..)
74-
| hir::ExprKind::Unary(hir::UnOp::UnNot, _)
75-
| hir::ExprKind::Unary(hir::UnOp::UnNeg, _) => return,
76-
_ => {},
72+
if let hir::ExprKind::Binary(..) | hir::ExprKind::Unary(hir::UnOp::UnNot | hir::UnOp::UnNeg, _) =
73+
e.kind
74+
{
75+
return;
7776
}
7877
}
7978
parent_expr = cx.tcx.hir().get_parent_node(parent_expr);
@@ -188,11 +187,8 @@ impl<'a, 'tcx> Visitor<'tcx> for BinaryExprVisitor {
188187
type Map = Map<'tcx>;
189188

190189
fn visit_expr(&mut self, expr: &'tcx hir::Expr<'_>) {
191-
match expr.kind {
192-
hir::ExprKind::Binary(..)
193-
| hir::ExprKind::Unary(hir::UnOp::UnNot, _)
194-
| hir::ExprKind::Unary(hir::UnOp::UnNeg, _) => self.in_binary_expr = true,
195-
_ => {},
190+
if let hir::ExprKind::Binary(..) | hir::ExprKind::Unary(hir::UnOp::UnNot | hir::UnOp::UnNeg, _) = expr.kind {
191+
self.in_binary_expr = true
196192
}
197193

198194
walk_expr(self, expr);

clippy_lints/src/transmute.rs

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute {
311311
e.span,
312312
&format!("transmute from a type (`{}`) to itself", from_ty),
313313
),
314-
(&ty::Ref(_, rty, rty_mutbl), &ty::RawPtr(ptr_ty)) => span_lint_and_then(
314+
(ty::Ref(_, rty, rty_mutbl), ty::RawPtr(ptr_ty)) => span_lint_and_then(
315315
cx,
316316
USELESS_TRANSMUTE,
317317
e.span,
@@ -320,10 +320,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute {
320320
if let Some(arg) = sugg::Sugg::hir_opt(cx, &args[0]) {
321321
let rty_and_mut = ty::TypeAndMut {
322322
ty: rty,
323-
mutbl: rty_mutbl,
323+
mutbl: *rty_mutbl,
324324
};
325325

326-
let sugg = if ptr_ty == rty_and_mut {
326+
let sugg = if *ptr_ty == rty_and_mut {
327327
arg.as_ty(to_ty)
328328
} else {
329329
arg.as_ty(cx.tcx.mk_ptr(rty_and_mut)).as_ty(to_ty)
@@ -333,7 +333,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute {
333333
}
334334
},
335335
),
336-
(&ty::Int(_), &ty::RawPtr(_)) | (&ty::Uint(_), &ty::RawPtr(_)) => span_lint_and_then(
336+
(ty::Int(_) | ty::Uint(_), ty::RawPtr(_)) => span_lint_and_then(
337337
cx,
338338
USELESS_TRANSMUTE,
339339
e.span,
@@ -349,16 +349,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute {
349349
}
350350
},
351351
),
352-
(&ty::Float(_), &ty::Ref(..))
353-
| (&ty::Float(_), &ty::RawPtr(_))
354-
| (&ty::Char, &ty::Ref(..))
355-
| (&ty::Char, &ty::RawPtr(_)) => span_lint(
352+
(ty::Float(_) | ty::Char, ty::Ref(..) | ty::RawPtr(_)) => span_lint(
356353
cx,
357354
WRONG_TRANSMUTE,
358355
e.span,
359356
&format!("transmute from a `{}` to a pointer", from_ty),
360357
),
361-
(&ty::RawPtr(from_ptr), _) if from_ptr.ty == to_ty => span_lint(
358+
(ty::RawPtr(from_ptr), _) if from_ptr.ty == to_ty => span_lint(
362359
cx,
363360
CROSSPOINTER_TRANSMUTE,
364361
e.span,
@@ -367,7 +364,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute {
367364
from_ty, to_ty
368365
),
369366
),
370-
(_, &ty::RawPtr(to_ptr)) if to_ptr.ty == from_ty => span_lint(
367+
(_, ty::RawPtr(to_ptr)) if to_ptr.ty == from_ty => span_lint(
371368
cx,
372369
CROSSPOINTER_TRANSMUTE,
373370
e.span,
@@ -376,7 +373,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute {
376373
from_ty, to_ty
377374
),
378375
),
379-
(&ty::RawPtr(from_pty), &ty::Ref(_, to_ref_ty, mutbl)) => span_lint_and_then(
376+
(ty::RawPtr(from_pty), ty::Ref(_, to_ref_ty, mutbl)) => span_lint_and_then(
380377
cx,
381378
TRANSMUTE_PTR_TO_REF,
382379
e.span,
@@ -387,13 +384,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute {
387384
),
388385
|db| {
389386
let arg = sugg::Sugg::hir(cx, &args[0], "..");
390-
let (deref, cast) = if mutbl == Mutability::Mut {
387+
let (deref, cast) = if *mutbl == Mutability::Mut {
391388
("&mut *", "*mut")
392389
} else {
393390
("&*", "*const")
394391
};
395392

396-
let arg = if from_pty.ty == to_ref_ty {
393+
let arg = if from_pty.ty == *to_ref_ty {
397394
arg
398395
} else {
399396
arg.as_ty(&format!("{} {}", cast, get_type_snippet(cx, qpath, to_ref_ty)))
@@ -407,7 +404,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute {
407404
);
408405
},
409406
),
410-
(&ty::Int(ast::IntTy::I32), &ty::Char) | (&ty::Uint(ast::UintTy::U32), &ty::Char) => {
407+
(ty::Int(ast::IntTy::I32) | ty::Uint(ast::UintTy::U32), &ty::Char) => {
411408
span_lint_and_then(
412409
cx,
413410
TRANSMUTE_INT_TO_CHAR,
@@ -429,13 +426,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute {
429426
},
430427
)
431428
},
432-
(&ty::Ref(_, ty_from, from_mutbl), &ty::Ref(_, ty_to, to_mutbl)) => {
429+
(ty::Ref(_, ty_from, from_mutbl), ty::Ref(_, ty_to, to_mutbl)) => {
433430
if_chain! {
434431
if let (&ty::Slice(slice_ty), &ty::Str) = (&ty_from.kind, &ty_to.kind);
435432
if let ty::Uint(ast::UintTy::U8) = slice_ty.kind;
436433
if from_mutbl == to_mutbl;
437434
then {
438-
let postfix = if from_mutbl == Mutability::Mut {
435+
let postfix = if *from_mutbl == Mutability::Mut {
439436
"_mut"
440437
} else {
441438
""
@@ -469,13 +466,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute {
469466
|db| if let Some(arg) = sugg::Sugg::hir_opt(cx, &args[0]) {
470467
let ty_from_and_mut = ty::TypeAndMut {
471468
ty: ty_from,
472-
mutbl: from_mutbl
469+
mutbl: *from_mutbl
473470
};
474-
let ty_to_and_mut = ty::TypeAndMut { ty: ty_to, mutbl: to_mutbl };
471+
let ty_to_and_mut = ty::TypeAndMut { ty: ty_to, mutbl: *to_mutbl };
475472
let sugg_paren = arg
476473
.as_ty(cx.tcx.mk_ptr(ty_from_and_mut))
477474
.as_ty(cx.tcx.mk_ptr(ty_to_and_mut));
478-
let sugg = if to_mutbl == Mutability::Mut {
475+
let sugg = if *to_mutbl == Mutability::Mut {
479476
sugg_paren.mut_addr_deref()
480477
} else {
481478
sugg_paren.addr_deref()
@@ -492,19 +489,19 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute {
492489
}
493490
}
494491
},
495-
(&ty::RawPtr(_), &ty::RawPtr(to_ty)) => span_lint_and_then(
492+
(ty::RawPtr(_), ty::RawPtr(to_ty)) => span_lint_and_then(
496493
cx,
497494
TRANSMUTE_PTR_TO_PTR,
498495
e.span,
499496
"transmute from a pointer to a pointer",
500497
|db| {
501498
if let Some(arg) = sugg::Sugg::hir_opt(cx, &args[0]) {
502-
let sugg = arg.as_ty(cx.tcx.mk_ptr(to_ty));
499+
let sugg = arg.as_ty(cx.tcx.mk_ptr(*to_ty));
503500
db.span_suggestion(e.span, "try", sugg.to_string(), Applicability::Unspecified);
504501
}
505502
},
506503
),
507-
(&ty::Int(ast::IntTy::I8), &ty::Bool) | (&ty::Uint(ast::UintTy::U8), &ty::Bool) => {
504+
(ty::Int(ast::IntTy::I8) | ty::Uint(ast::UintTy::U8), ty::Bool) => {
508505
span_lint_and_then(
509506
cx,
510507
TRANSMUTE_INT_TO_BOOL,
@@ -522,7 +519,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute {
522519
},
523520
)
524521
},
525-
(&ty::Int(_), &ty::Float(_)) | (&ty::Uint(_), &ty::Float(_)) => span_lint_and_then(
522+
(ty::Int(_) | ty::Uint(_), ty::Float(_)) => span_lint_and_then(
526523
cx,
527524
TRANSMUTE_INT_TO_FLOAT,
528525
e.span,
@@ -545,7 +542,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute {
545542
);
546543
},
547544
),
548-
(&ty::Float(float_ty), &ty::Int(_)) | (&ty::Float(float_ty), &ty::Uint(_)) => span_lint_and_then(
545+
(ty::Float(float_ty), ty::Int(_) | ty::Uint(_)) => span_lint_and_then(
549546
cx,
550547
TRANSMUTE_FLOAT_TO_INT,
551548
e.span,
@@ -589,7 +586,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute {
589586
);
590587
},
591588
),
592-
(&ty::Adt(ref from_adt, ref from_substs), &ty::Adt(ref to_adt, ref to_substs)) => {
589+
(ty::Adt(from_adt, from_substs), ty::Adt(to_adt, to_substs)) => {
593590
if from_adt.did != to_adt.did ||
594591
!COLLECTIONS.iter().any(|path| match_def_path(cx, to_adt.did, path)) {
595592
return;

clippy_lints/src/unwrap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ fn collect_unwrap_info<'a, 'tcx>(
8686
) -> Vec<UnwrapInfo<'tcx>> {
8787
if let ExprKind::Binary(op, left, right) = &expr.kind {
8888
match (invert, op.node) {
89-
(false, BinOpKind::And) | (false, BinOpKind::BitAnd) | (true, BinOpKind::Or) | (true, BinOpKind::BitOr) => {
89+
(false, BinOpKind::And | BinOpKind::BitAnd) | (true, BinOpKind::Or | BinOpKind::BitOr) => {
9090
let mut unwrap_info = collect_unwrap_info(cx, left, invert);
9191
unwrap_info.append(&mut collect_unwrap_info(cx, right, invert));
9292
return unwrap_info;

clippy_lints/src/utils/mod.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#[macro_use]
22
pub mod sym;
33

4+
#[allow(clippy::module_name_repetitions)]
45
pub mod ast_utils;
56
pub mod attrs;
67
pub mod author;
@@ -80,7 +81,7 @@ pub fn in_constant(cx: &LateContext<'_, '_>, id: HirId) -> bool {
8081
let parent_id = cx.tcx.hir().get_parent_item(id);
8182
match cx.tcx.hir().get(parent_id) {
8283
Node::Item(&Item {
83-
kind: ItemKind::Const(..),
84+
kind: ItemKind::Const(..) | ItemKind::Static(..),
8485
..
8586
})
8687
| Node::TraitItem(&TraitItem {
@@ -91,11 +92,7 @@ pub fn in_constant(cx: &LateContext<'_, '_>, id: HirId) -> bool {
9192
kind: ImplItemKind::Const(..),
9293
..
9394
})
94-
| Node::AnonConst(_)
95-
| Node::Item(&Item {
96-
kind: ItemKind::Static(..),
97-
..
98-
}) => true,
95+
| Node::AnonConst(_) => true,
9996
Node::Item(&Item {
10097
kind: ItemKind::Fn(ref sig, ..),
10198
..

0 commit comments

Comments
 (0)