Skip to content

Commit 78f158e

Browse files
Centrilflip1995
authored andcommitted
dogfood unnested_or_patterns
1 parent 7b6dc7b commit 78f158e

File tree

9 files changed

+44
-64
lines changed

9 files changed

+44
-64
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
@@ -1403,9 +1403,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Methods {
14031403
lint_search_is_some(cx, expr, "rposition", arg_lists[1], arg_lists[0], method_spans[1])
14041404
},
14051405
["extend", ..] => lint_extend(cx, expr, arg_lists[0]),
1406-
["as_ptr", "unwrap"] | ["as_ptr", "expect"] => {
1407-
lint_cstring_as_ptr(cx, expr, &arg_lists[1][0], &arg_lists[0][0])
1408-
},
1406+
["as_ptr", "unwrap" | "expect"] => lint_cstring_as_ptr(cx, expr, &arg_lists[1][0], &arg_lists[0][0]),
14091407
["nth", "iter"] => lint_iter_nth(cx, expr, &arg_lists, false),
14101408
["nth", "iter_mut"] => lint_iter_nth(cx, expr, &arg_lists, true),
14111409
["nth", ..] => lint_iter_nth_zero(cx, expr, arg_lists[0]),
@@ -1418,12 +1416,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Methods {
14181416
["filter_map", ..] => unnecessary_filter_map::lint(cx, expr, arg_lists[0]),
14191417
["count", "map"] => lint_suspicious_map(cx, expr),
14201418
["assume_init"] => lint_maybe_uninit(cx, &arg_lists[0][0], expr),
1421-
["unwrap_or", arith @ "checked_add"]
1422-
| ["unwrap_or", arith @ "checked_sub"]
1423-
| ["unwrap_or", arith @ "checked_mul"] => {
1419+
["unwrap_or", arith @ ("checked_add" | "checked_sub" | "checked_mul")] => {
14241420
manual_saturating_arithmetic::lint(cx, expr, &arg_lists, &arith["checked_".len()..])
14251421
},
1426-
["add"] | ["offset"] | ["sub"] | ["wrapping_offset"] | ["wrapping_add"] | ["wrapping_sub"] => {
1422+
["add" | "offset" | "sub" | "wrapping_offset" | "wrapping_add" | "wrapping_sub"] => {
14271423
check_pointer_offset(cx, expr, arg_lists[0])
14281424
},
14291425
["is_file", ..] => lint_filetype_is_file(cx, expr, arg_lists[0]),
@@ -1829,8 +1825,7 @@ fn lint_expect_fun_call(
18291825
hir::ExprKind::Call(fun, _) => {
18301826
if let hir::ExprKind::Path(ref p) = fun.kind {
18311827
match cx.tables.qpath_res(p, fun.hir_id) {
1832-
hir::def::Res::Def(hir::def::DefKind::Fn, def_id)
1833-
| hir::def::Res::Def(hir::def::DefKind::AssocFn, def_id) => matches!(
1828+
hir::def::Res::Def(hir::def::DefKind::Fn | hir::def::DefKind::AssocFn, def_id) => matches!(
18341829
cx.tcx.fn_sig(def_id).output().skip_binder().kind,
18351830
ty::Ref(ty::ReStatic, ..)
18361831
),

clippy_lints/src/misc.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -275,17 +275,14 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MiscLints {
275275
return;
276276
}
277277
for arg in iter_input_pats(decl, body) {
278-
match arg.pat.kind {
279-
PatKind::Binding(BindingAnnotation::Ref, ..) | PatKind::Binding(BindingAnnotation::RefMut, ..) => {
280-
span_lint(
281-
cx,
282-
TOPLEVEL_REF_ARG,
283-
arg.pat.span,
284-
"`ref` directly on a function argument is ignored. Consider using a reference type \
285-
instead.",
286-
);
287-
},
288-
_ => {},
278+
if let PatKind::Binding(BindingAnnotation::Ref | BindingAnnotation::RefMut, ..) = arg.pat.kind {
279+
span_lint(
280+
cx,
281+
TOPLEVEL_REF_ARG,
282+
arg.pat.span,
283+
"`ref` directly on a function argument is ignored. \
284+
Consider using a reference type instead.",
285+
);
289286
}
290287
}
291288
}

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: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for SuspiciousImpl {
7171
if let hir::Node::Expr(e) = cx.tcx.hir().get(parent_expr) {
7272
match e.kind {
7373
hir::ExprKind::Binary(..)
74-
| hir::ExprKind::Unary(hir::UnOp::UnNot, _)
75-
| hir::ExprKind::Unary(hir::UnOp::UnNeg, _)
74+
| hir::ExprKind::Unary(hir::UnOp::UnNot | hir::UnOp::UnNeg, _)
7675
| hir::ExprKind::AssignOp(..) => return,
7776
_ => {},
7877
}
@@ -191,8 +190,7 @@ impl<'a, 'tcx> Visitor<'tcx> for BinaryExprVisitor {
191190
fn visit_expr(&mut self, expr: &'tcx hir::Expr<'_>) {
192191
match expr.kind {
193192
hir::ExprKind::Binary(..)
194-
| hir::ExprKind::Unary(hir::UnOp::UnNot, _)
195-
| hir::ExprKind::Unary(hir::UnOp::UnNeg, _)
193+
| hir::ExprKind::Unary(hir::UnOp::UnNot | hir::UnOp::UnNeg, _)
196194
| hir::ExprKind::AssignOp(..) => self.in_binary_expr = true,
197195
_ => {},
198196
}

clippy_lints/src/transmute.rs

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

327-
let sugg = if ptr_ty == rty_and_mut {
327+
let sugg = if *ptr_ty == rty_and_mut {
328328
arg.as_ty(to_ty)
329329
} else {
330330
arg.as_ty(cx.tcx.mk_ptr(rty_and_mut)).as_ty(to_ty)
@@ -334,7 +334,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute {
334334
}
335335
},
336336
),
337-
(&ty::Int(_), &ty::RawPtr(_)) | (&ty::Uint(_), &ty::RawPtr(_)) => span_lint_and_then(
337+
(ty::Int(_) | ty::Uint(_), ty::RawPtr(_)) => span_lint_and_then(
338338
cx,
339339
USELESS_TRANSMUTE,
340340
e.span,
@@ -350,16 +350,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute {
350350
}
351351
},
352352
),
353-
(&ty::Float(_), &ty::Ref(..))
354-
| (&ty::Float(_), &ty::RawPtr(_))
355-
| (&ty::Char, &ty::Ref(..))
356-
| (&ty::Char, &ty::RawPtr(_)) => span_lint(
353+
(ty::Float(_) | ty::Char, ty::Ref(..) | ty::RawPtr(_)) => span_lint(
357354
cx,
358355
WRONG_TRANSMUTE,
359356
e.span,
360357
&format!("transmute from a `{}` to a pointer", from_ty),
361358
),
362-
(&ty::RawPtr(from_ptr), _) if from_ptr.ty == to_ty => span_lint(
359+
(ty::RawPtr(from_ptr), _) if from_ptr.ty == to_ty => span_lint(
363360
cx,
364361
CROSSPOINTER_TRANSMUTE,
365362
e.span,
@@ -368,7 +365,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute {
368365
from_ty, to_ty
369366
),
370367
),
371-
(_, &ty::RawPtr(to_ptr)) if to_ptr.ty == from_ty => span_lint(
368+
(_, ty::RawPtr(to_ptr)) if to_ptr.ty == from_ty => span_lint(
372369
cx,
373370
CROSSPOINTER_TRANSMUTE,
374371
e.span,
@@ -377,7 +374,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute {
377374
from_ty, to_ty
378375
),
379376
),
380-
(&ty::RawPtr(from_pty), &ty::Ref(_, to_ref_ty, mutbl)) => span_lint_and_then(
377+
(ty::RawPtr(from_pty), ty::Ref(_, to_ref_ty, mutbl)) => span_lint_and_then(
381378
cx,
382379
TRANSMUTE_PTR_TO_REF,
383380
e.span,
@@ -388,13 +385,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute {
388385
),
389386
|diag| {
390387
let arg = sugg::Sugg::hir(cx, &args[0], "..");
391-
let (deref, cast) = if mutbl == Mutability::Mut {
388+
let (deref, cast) = if *mutbl == Mutability::Mut {
392389
("&mut *", "*mut")
393390
} else {
394391
("&*", "*const")
395392
};
396393

397-
let arg = if from_pty.ty == to_ref_ty {
394+
let arg = if from_pty.ty == *to_ref_ty {
398395
arg
399396
} else {
400397
arg.as_ty(&format!("{} {}", cast, get_type_snippet(cx, qpath, to_ref_ty)))
@@ -408,7 +405,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute {
408405
);
409406
},
410407
),
411-
(&ty::Int(ast::IntTy::I32), &ty::Char) | (&ty::Uint(ast::UintTy::U32), &ty::Char) => {
408+
(ty::Int(ast::IntTy::I32) | ty::Uint(ast::UintTy::U32), &ty::Char) => {
412409
span_lint_and_then(
413410
cx,
414411
TRANSMUTE_INT_TO_CHAR,
@@ -430,13 +427,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute {
430427
},
431428
)
432429
},
433-
(&ty::Ref(_, ty_from, from_mutbl), &ty::Ref(_, ty_to, to_mutbl)) => {
430+
(ty::Ref(_, ty_from, from_mutbl), ty::Ref(_, ty_to, to_mutbl)) => {
434431
if_chain! {
435432
if let (&ty::Slice(slice_ty), &ty::Str) = (&ty_from.kind, &ty_to.kind);
436433
if let ty::Uint(ast::UintTy::U8) = slice_ty.kind;
437434
if from_mutbl == to_mutbl;
438435
then {
439-
let postfix = if from_mutbl == Mutability::Mut {
436+
let postfix = if *from_mutbl == Mutability::Mut {
440437
"_mut"
441438
} else {
442439
""
@@ -465,13 +462,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute {
465462
|diag| if let Some(arg) = sugg::Sugg::hir_opt(cx, &args[0]) {
466463
let ty_from_and_mut = ty::TypeAndMut {
467464
ty: ty_from,
468-
mutbl: from_mutbl
465+
mutbl: *from_mutbl
469466
};
470-
let ty_to_and_mut = ty::TypeAndMut { ty: ty_to, mutbl: to_mutbl };
467+
let ty_to_and_mut = ty::TypeAndMut { ty: ty_to, mutbl: *to_mutbl };
471468
let sugg_paren = arg
472469
.as_ty(cx.tcx.mk_ptr(ty_from_and_mut))
473470
.as_ty(cx.tcx.mk_ptr(ty_to_and_mut));
474-
let sugg = if to_mutbl == Mutability::Mut {
471+
let sugg = if *to_mutbl == Mutability::Mut {
475472
sugg_paren.mut_addr_deref()
476473
} else {
477474
sugg_paren.addr_deref()
@@ -488,19 +485,19 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute {
488485
}
489486
}
490487
},
491-
(&ty::RawPtr(_), &ty::RawPtr(to_ty)) => span_lint_and_then(
488+
(ty::RawPtr(_), ty::RawPtr(to_ty)) => span_lint_and_then(
492489
cx,
493490
TRANSMUTE_PTR_TO_PTR,
494491
e.span,
495492
"transmute from a pointer to a pointer",
496493
|diag| {
497494
if let Some(arg) = sugg::Sugg::hir_opt(cx, &args[0]) {
498-
let sugg = arg.as_ty(cx.tcx.mk_ptr(to_ty));
495+
let sugg = arg.as_ty(cx.tcx.mk_ptr(*to_ty));
499496
diag.span_suggestion(e.span, "try", sugg.to_string(), Applicability::Unspecified);
500497
}
501498
},
502499
),
503-
(&ty::Int(ast::IntTy::I8), &ty::Bool) | (&ty::Uint(ast::UintTy::U8), &ty::Bool) => {
500+
(ty::Int(ast::IntTy::I8) | ty::Uint(ast::UintTy::U8), ty::Bool) => {
504501
span_lint_and_then(
505502
cx,
506503
TRANSMUTE_INT_TO_BOOL,
@@ -518,7 +515,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute {
518515
},
519516
)
520517
},
521-
(&ty::Int(_), &ty::Float(_)) | (&ty::Uint(_), &ty::Float(_)) => span_lint_and_then(
518+
(ty::Int(_) | ty::Uint(_), ty::Float(_)) => span_lint_and_then(
522519
cx,
523520
TRANSMUTE_INT_TO_FLOAT,
524521
e.span,
@@ -541,7 +538,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute {
541538
);
542539
},
543540
),
544-
(&ty::Float(float_ty), &ty::Int(_)) | (&ty::Float(float_ty), &ty::Uint(_)) => span_lint_and_then(
541+
(ty::Float(float_ty), ty::Int(_) | ty::Uint(_)) => span_lint_and_then(
545542
cx,
546543
TRANSMUTE_FLOAT_TO_INT,
547544
e.span,
@@ -585,7 +582,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute {
585582
);
586583
},
587584
),
588-
(&ty::Adt(ref from_adt, ref from_substs), &ty::Adt(ref to_adt, ref to_substs)) => {
585+
(ty::Adt(from_adt, from_substs), ty::Adt(to_adt, to_substs)) => {
589586
if from_adt.did != to_adt.did ||
590587
!COLLECTIONS.iter().any(|path| match_def_path(cx, to_adt.did, path)) {
591588
return;

clippy_lints/src/unwrap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ fn collect_unwrap_info<'a, 'tcx>(
101101

102102
if let ExprKind::Binary(op, left, right) = &expr.kind {
103103
match (invert, op.node) {
104-
(false, BinOpKind::And) | (false, BinOpKind::BitAnd) | (true, BinOpKind::Or) | (true, BinOpKind::BitOr) => {
104+
(false, BinOpKind::And | BinOpKind::BitAnd) | (true, BinOpKind::Or | BinOpKind::BitOr) => {
105105
let mut unwrap_info = collect_unwrap_info(cx, left, branch, invert);
106106
unwrap_info.append(&mut collect_unwrap_info(cx, right, branch, invert));
107107
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;
@@ -73,7 +74,7 @@ pub fn in_constant(cx: &LateContext<'_, '_>, id: HirId) -> bool {
7374
let parent_id = cx.tcx.hir().get_parent_item(id);
7475
match cx.tcx.hir().get(parent_id) {
7576
Node::Item(&Item {
76-
kind: ItemKind::Const(..),
77+
kind: ItemKind::Const(..) | ItemKind::Static(..),
7778
..
7879
})
7980
| Node::TraitItem(&TraitItem {
@@ -84,11 +85,7 @@ pub fn in_constant(cx: &LateContext<'_, '_>, id: HirId) -> bool {
8485
kind: ImplItemKind::Const(..),
8586
..
8687
})
87-
| Node::AnonConst(_)
88-
| Node::Item(&Item {
89-
kind: ItemKind::Static(..),
90-
..
91-
}) => true,
88+
| Node::AnonConst(_) => true,
9289
Node::Item(&Item {
9390
kind: ItemKind::Fn(ref sig, ..),
9491
..

0 commit comments

Comments
 (0)