From e2636729ec6f1c9ba4e071699488d1089756c7c6 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Fri, 27 Dec 2019 16:12:26 +0900 Subject: [PATCH] Rustup to rust-lang/rust#66936 --- clippy_lints/src/approx_const.rs | 6 +- clippy_lints/src/arithmetic.rs | 4 +- clippy_lints/src/assertions_on_constants.rs | 6 +- clippy_lints/src/assign_ops.rs | 16 +- clippy_lints/src/attrs.rs | 4 +- clippy_lints/src/bit_mask.rs | 6 +- clippy_lints/src/blacklisted_name.rs | 2 +- clippy_lints/src/block_in_if_condition.rs | 6 +- clippy_lints/src/booleans.rs | 20 +- clippy_lints/src/bytecount.rs | 6 +- clippy_lints/src/checked_conversions.rs | 30 +-- clippy_lints/src/cognitive_complexity.rs | 2 +- clippy_lints/src/comparison_chain.rs | 2 +- clippy_lints/src/consts.rs | 14 +- clippy_lints/src/copies.rs | 39 ++-- clippy_lints/src/default_trait_access.rs | 2 +- clippy_lints/src/double_comparison.rs | 4 +- clippy_lints/src/drop_forget_ref.rs | 2 +- clippy_lints/src/duration_subsec.rs | 2 +- clippy_lints/src/entry.rs | 12 +- clippy_lints/src/eq_op.rs | 2 +- clippy_lints/src/erasing_op.rs | 4 +- clippy_lints/src/eta_reduction.rs | 16 +- clippy_lints/src/eval_order_dependence.rs | 26 +-- clippy_lints/src/excessive_precision.rs | 2 +- clippy_lints/src/exit.rs | 2 +- clippy_lints/src/explicit_write.rs | 12 +- clippy_lints/src/fallible_impl_from.rs | 2 +- clippy_lints/src/format.rs | 14 +- clippy_lints/src/functions.rs | 18 +- clippy_lints/src/get_last_with_len.rs | 2 +- clippy_lints/src/identity_conversion.rs | 4 +- clippy_lints/src/identity_op.rs | 4 +- clippy_lints/src/implicit_return.rs | 6 +- clippy_lints/src/indexing_slicing.rs | 2 +- .../src/infallible_destructuring_match.rs | 2 +- clippy_lints/src/infinite_iter.rs | 6 +- clippy_lints/src/integer_division.rs | 4 +- clippy_lints/src/large_stack_arrays.rs | 2 +- clippy_lints/src/len_zero.rs | 8 +- clippy_lints/src/let_if_seq.rs | 10 +- clippy_lints/src/let_underscore.rs | 2 +- clippy_lints/src/loops.rs | 156 +++++++-------- clippy_lints/src/main_recursion.rs | 2 +- clippy_lints/src/map_clone.rs | 4 +- clippy_lints/src/map_unit_fn.rs | 16 +- clippy_lints/src/matches.rs | 54 +++--- clippy_lints/src/mem_discriminant.rs | 2 +- clippy_lints/src/mem_forget.rs | 2 +- clippy_lints/src/mem_replace.rs | 2 +- .../src/methods/inefficient_to_string.rs | 2 +- .../methods/manual_saturating_arithmetic.rs | 8 +- clippy_lints/src/methods/mod.rs | 178 +++++++++++------- .../src/methods/option_map_unwrap_or.rs | 6 +- .../src/methods/unnecessary_filter_map.rs | 10 +- clippy_lints/src/minmax.rs | 10 +- clippy_lints/src/misc.rs | 22 +-- clippy_lints/src/mul_add.rs | 9 +- clippy_lints/src/mut_key.rs | 2 +- clippy_lints/src/mut_mut.rs | 4 +- clippy_lints/src/mut_reference.rs | 9 +- clippy_lints/src/mutable_debug_assertion.rs | 6 +- clippy_lints/src/mutex_atomic.rs | 2 +- clippy_lints/src/needless_bool.rs | 14 +- clippy_lints/src/needless_borrow.rs | 4 +- clippy_lints/src/needless_borrowed_ref.rs | 2 +- clippy_lints/src/needless_update.rs | 2 +- clippy_lints/src/neg_cmp_op_on_partial_ord.rs | 2 +- clippy_lints/src/neg_multiply.rs | 4 +- clippy_lints/src/no_effect.rs | 6 +- clippy_lints/src/non_copy_const.rs | 2 +- clippy_lints/src/ok_if_let.rs | 2 +- clippy_lints/src/open_options.rs | 4 +- .../src/overflow_check_conditional.rs | 2 +- clippy_lints/src/panic_unimplemented.rs | 6 +- clippy_lints/src/path_buf_push_overwrite.rs | 2 +- clippy_lints/src/ptr.rs | 4 +- clippy_lints/src/ptr_offset_with_cast.rs | 16 +- clippy_lints/src/question_mark.rs | 21 +-- clippy_lints/src/ranges.rs | 10 +- .../src/redundant_pattern_matching.rs | 15 +- clippy_lints/src/regex.rs | 14 +- clippy_lints/src/replace_consts.rs | 2 +- clippy_lints/src/shadow.rs | 24 +-- .../src/slow_vector_initialization.rs | 30 +-- clippy_lints/src/strings.rs | 8 +- clippy_lints/src/suspicious_trait_impl.rs | 6 +- clippy_lints/src/swap.rs | 10 +- clippy_lints/src/temporary_assignment.rs | 4 +- clippy_lints/src/to_digit_is_some.rs | 2 +- clippy_lints/src/transmute.rs | 2 +- clippy_lints/src/transmuting_null.rs | 4 +- clippy_lints/src/try_err.rs | 6 +- clippy_lints/src/types.rs | 70 +++---- clippy_lints/src/unicode.rs | 2 +- clippy_lints/src/unused_io_amount.rs | 4 +- clippy_lints/src/unwrap.rs | 8 +- clippy_lints/src/utils/author.rs | 14 +- clippy_lints/src/utils/comparisons.rs | 6 +- clippy_lints/src/utils/higher.rs | 30 +-- clippy_lints/src/utils/hir_utils.rs | 53 +++--- clippy_lints/src/utils/inspector.rs | 32 ++-- clippy_lints/src/utils/internal_lints.rs | 6 +- clippy_lints/src/utils/mod.rs | 68 ++++--- clippy_lints/src/utils/ptr.rs | 4 +- clippy_lints/src/utils/sugg.rs | 10 +- clippy_lints/src/utils/usage.rs | 8 +- clippy_lints/src/vec.rs | 2 +- clippy_lints/src/zero_div_zero.rs | 2 +- 109 files changed, 735 insertions(+), 655 deletions(-) diff --git a/clippy_lints/src/approx_const.rs b/clippy_lints/src/approx_const.rs index a35f7b450902..68582ecddf75 100644 --- a/clippy_lints/src/approx_const.rs +++ b/clippy_lints/src/approx_const.rs @@ -60,14 +60,14 @@ const KNOWN_CONSTS: [(f64, &str, usize); 16] = [ declare_lint_pass!(ApproxConstant => [APPROX_CONSTANT]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ApproxConstant { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) { + fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) { if let ExprKind::Lit(lit) = &e.kind { check_lit(cx, &lit.node, e); } } } -fn check_lit(cx: &LateContext<'_, '_>, lit: &LitKind, e: &Expr) { +fn check_lit(cx: &LateContext<'_, '_>, lit: &LitKind, e: &Expr<'_>) { match *lit { LitKind::Float(s, LitFloatType::Suffixed(fty)) => match fty { FloatTy::F32 => check_known_consts(cx, e, s, "f32"), @@ -78,7 +78,7 @@ fn check_lit(cx: &LateContext<'_, '_>, lit: &LitKind, e: &Expr) { } } -fn check_known_consts(cx: &LateContext<'_, '_>, e: &Expr, s: symbol::Symbol, module: &str) { +fn check_known_consts(cx: &LateContext<'_, '_>, e: &Expr<'_>, s: symbol::Symbol, module: &str) { let s = s.as_str(); if s.parse::().is_ok() { for &(constant, name, min_digits) in &KNOWN_CONSTS { diff --git a/clippy_lints/src/arithmetic.rs b/clippy_lints/src/arithmetic.rs index 7653ba43459f..cff9a590e121 100644 --- a/clippy_lints/src/arithmetic.rs +++ b/clippy_lints/src/arithmetic.rs @@ -54,7 +54,7 @@ pub struct Arithmetic { impl_lint_pass!(Arithmetic => [INTEGER_ARITHMETIC, FLOAT_ARITHMETIC]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Arithmetic { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) { + fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr<'_>) { if self.expr_span.is_some() { return; } @@ -107,7 +107,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Arithmetic { } } - fn check_expr_post(&mut self, _: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) { + fn check_expr_post(&mut self, _: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr<'_>) { if Some(expr.span) == self.expr_span { self.expr_span = None; } diff --git a/clippy_lints/src/assertions_on_constants.rs b/clippy_lints/src/assertions_on_constants.rs index 874fff1f0814..6c24ccfc3231 100644 --- a/clippy_lints/src/assertions_on_constants.rs +++ b/clippy_lints/src/assertions_on_constants.rs @@ -33,7 +33,7 @@ declare_clippy_lint! { declare_lint_pass!(AssertionsOnConstants => [ASSERTIONS_ON_CONSTANTS]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssertionsOnConstants { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) { + fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) { let lint_true = || { span_help_and_lint( cx, @@ -110,7 +110,7 @@ enum AssertKind { /// ``` /// /// where `message` is any expression and `c` is a constant bool. -fn match_assert_with_message<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) -> Option { +fn match_assert_with_message<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) -> Option { if_chain! { if let ExprKind::Match(ref expr, ref arms, _) = expr.kind; // matches { let _t = expr; _t } @@ -124,7 +124,7 @@ fn match_assert_with_message<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx E if let LitKind::Bool(true) = lit.node; // arm 1 block if let ExprKind::Block(ref block, _) = arms[0].body.kind; - if block.stmts.len() == 0; + if block.stmts.is_empty(); if let Some(block_expr) = &block.expr; if let ExprKind::Block(ref inner_block, _) = block_expr.kind; if let Some(begin_panic_call) = &inner_block.expr; diff --git a/clippy_lints/src/assign_ops.rs b/clippy_lints/src/assign_ops.rs index 1daaa6662bbc..5fd6e7ffd59f 100644 --- a/clippy_lints/src/assign_ops.rs +++ b/clippy_lints/src/assign_ops.rs @@ -59,7 +59,7 @@ declare_lint_pass!(AssignOps => [ASSIGN_OP_PATTERN, MISREFACTORED_ASSIGN_OP]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps { #[allow(clippy::too_many_lines)] - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) { + fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr<'_>) { match &expr.kind { hir::ExprKind::AssignOp(op, lhs, rhs) => { if let hir::ExprKind::Binary(binop, l, r) = &rhs.kind { @@ -79,7 +79,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps { hir::ExprKind::Assign(assignee, e, _) => { if let hir::ExprKind::Binary(op, l, r) = &e.kind { #[allow(clippy::cognitive_complexity)] - let lint = |assignee: &hir::Expr, rhs: &hir::Expr| { + let lint = |assignee: &hir::Expr<'_>, rhs: &hir::Expr<'_>| { let ty = cx.tables.expr_ty(assignee); let rty = cx.tables.expr_ty(rhs); macro_rules! ops { @@ -190,11 +190,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps { fn lint_misrefactored_assign_op( cx: &LateContext<'_, '_>, - expr: &hir::Expr, + expr: &hir::Expr<'_>, op: hir::BinOp, - rhs: &hir::Expr, - assignee: &hir::Expr, - rhs_other: &hir::Expr, + rhs: &hir::Expr<'_>, + assignee: &hir::Expr<'_>, + rhs_other: &hir::Expr<'_>, ) { span_lint_and_then( cx, @@ -240,13 +240,13 @@ fn is_commutative(op: hir::BinOpKind) -> bool { } struct ExprVisitor<'a, 'tcx> { - assignee: &'a hir::Expr, + assignee: &'a hir::Expr<'a>, counter: u8, cx: &'a LateContext<'a, 'tcx>, } impl<'a, 'tcx> Visitor<'tcx> for ExprVisitor<'a, 'tcx> { - fn visit_expr(&mut self, expr: &'tcx hir::Expr) { + fn visit_expr(&mut self, expr: &'tcx hir::Expr<'_>) { if SpanlessEq::new(self.cx).ignore_fn().eq_expr(self.assignee, expr) { self.counter += 1; } diff --git a/clippy_lints/src/attrs.rs b/clippy_lints/src/attrs.rs index 410da312a5c0..7b41acf392ec 100644 --- a/clippy_lints/src/attrs.rs +++ b/clippy_lints/src/attrs.rs @@ -380,7 +380,7 @@ fn is_relevant_trait(cx: &LateContext<'_, '_>, item: &TraitItem<'_>) -> bool { } } -fn is_relevant_block(cx: &LateContext<'_, '_>, tables: &ty::TypeckTables<'_>, block: &Block) -> bool { +fn is_relevant_block(cx: &LateContext<'_, '_>, tables: &ty::TypeckTables<'_>, block: &Block<'_>) -> bool { if let Some(stmt) = block.stmts.first() { match &stmt.kind { StmtKind::Local(_) => true, @@ -392,7 +392,7 @@ fn is_relevant_block(cx: &LateContext<'_, '_>, tables: &ty::TypeckTables<'_>, bl } } -fn is_relevant_expr(cx: &LateContext<'_, '_>, tables: &ty::TypeckTables<'_>, expr: &Expr) -> bool { +fn is_relevant_expr(cx: &LateContext<'_, '_>, tables: &ty::TypeckTables<'_>, expr: &Expr<'_>) -> bool { match &expr.kind { ExprKind::Block(block, _) => is_relevant_block(cx, tables, block), ExprKind::Ret(Some(e)) => is_relevant_expr(cx, tables, e), diff --git a/clippy_lints/src/bit_mask.rs b/clippy_lints/src/bit_mask.rs index e75220908ece..0d8329c65918 100644 --- a/clippy_lints/src/bit_mask.rs +++ b/clippy_lints/src/bit_mask.rs @@ -112,7 +112,7 @@ impl BitMask { impl_lint_pass!(BitMask => [BAD_BIT_MASK, INEFFECTIVE_BIT_MASK, VERBOSE_BIT_MASK]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BitMask { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) { + fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) { if let ExprKind::Binary(cmp, left, right) = &e.kind { if cmp.node.is_comparison() { if let Some(cmp_opt) = fetch_int_literal(cx, right) { @@ -165,7 +165,7 @@ fn invert_cmp(cmp: BinOpKind) -> BinOpKind { } } -fn check_compare(cx: &LateContext<'_, '_>, bit_op: &Expr, cmp_op: BinOpKind, cmp_value: u128, span: Span) { +fn check_compare(cx: &LateContext<'_, '_>, bit_op: &Expr<'_>, cmp_op: BinOpKind, cmp_value: u128, span: Span) { if let ExprKind::Binary(op, left, right) = &bit_op.kind { if op.node != BinOpKind::BitAnd && op.node != BinOpKind::BitOr { return; @@ -319,7 +319,7 @@ fn check_ineffective_gt(cx: &LateContext<'_, '_>, span: Span, m: u128, c: u128, } } -fn fetch_int_literal(cx: &LateContext<'_, '_>, lit: &Expr) -> Option { +fn fetch_int_literal(cx: &LateContext<'_, '_>, lit: &Expr<'_>) -> Option { match constant(cx, cx.tables, lit)?.0 { Constant::Int(n) => Some(n), _ => None, diff --git a/clippy_lints/src/blacklisted_name.rs b/clippy_lints/src/blacklisted_name.rs index d7dafa2a78c9..c3ea889cfa9a 100644 --- a/clippy_lints/src/blacklisted_name.rs +++ b/clippy_lints/src/blacklisted_name.rs @@ -37,7 +37,7 @@ impl BlacklistedName { impl_lint_pass!(BlacklistedName => [BLACKLISTED_NAME]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BlacklistedName { - fn check_pat(&mut self, cx: &LateContext<'a, 'tcx>, pat: &'tcx Pat) { + fn check_pat(&mut self, cx: &LateContext<'a, 'tcx>, pat: &'tcx Pat<'_>) { if let PatKind::Binding(.., ident, _) = pat.kind { if self.blacklist.contains(&ident.name.to_string()) { span_lint( diff --git a/clippy_lints/src/block_in_if_condition.rs b/clippy_lints/src/block_in_if_condition.rs index 1f2158ba05db..18b150391562 100644 --- a/clippy_lints/src/block_in_if_condition.rs +++ b/clippy_lints/src/block_in_if_condition.rs @@ -46,12 +46,12 @@ declare_clippy_lint! { declare_lint_pass!(BlockInIfCondition => [BLOCK_IN_IF_CONDITION_EXPR, BLOCK_IN_IF_CONDITION_STMT]); struct ExVisitor<'a, 'tcx> { - found_block: Option<&'tcx Expr>, + found_block: Option<&'tcx Expr<'tcx>>, cx: &'a LateContext<'a, 'tcx>, } impl<'a, 'tcx> Visitor<'tcx> for ExVisitor<'a, 'tcx> { - fn visit_expr(&mut self, expr: &'tcx Expr) { + fn visit_expr(&mut self, expr: &'tcx Expr<'tcx>) { if let ExprKind::Closure(_, _, eid, _, _) = expr.kind { let body = self.cx.tcx.hir().body(eid); let ex = &body.value; @@ -72,7 +72,7 @@ const COMPLEX_BLOCK_MESSAGE: &str = "in an 'if' condition, avoid complex blocks instead, move the block or closure higher and bind it with a 'let'"; impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BlockInIfCondition { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { + fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { if in_external_macro(cx.sess(), expr.span) { return; } diff --git a/clippy_lints/src/booleans.rs b/clippy_lints/src/booleans.rs index 8767b92b4351..d63dca2cac7d 100644 --- a/clippy_lints/src/booleans.rs +++ b/clippy_lints/src/booleans.rs @@ -75,12 +75,12 @@ struct NonminimalBoolVisitor<'a, 'tcx> { use quine_mc_cluskey::Bool; struct Hir2Qmm<'a, 'tcx, 'v> { - terminals: Vec<&'v Expr>, + terminals: Vec<&'v Expr<'v>>, cx: &'a LateContext<'a, 'tcx>, } impl<'a, 'tcx, 'v> Hir2Qmm<'a, 'tcx, 'v> { - fn extract(&mut self, op: BinOpKind, a: &[&'v Expr], mut v: Vec) -> Result, String> { + fn extract(&mut self, op: BinOpKind, a: &[&'v Expr<'_>], mut v: Vec) -> Result, String> { for a in a { if let ExprKind::Binary(binop, lhs, rhs) = &a.kind { if binop.node == op { @@ -93,7 +93,7 @@ impl<'a, 'tcx, 'v> Hir2Qmm<'a, 'tcx, 'v> { Ok(v) } - fn run(&mut self, e: &'v Expr) -> Result { + fn run(&mut self, e: &'v Expr<'_>) -> Result { fn negate(bin_op_kind: BinOpKind) -> Option { match bin_op_kind { BinOpKind::Eq => Some(BinOpKind::Ne), @@ -154,7 +154,7 @@ impl<'a, 'tcx, 'v> Hir2Qmm<'a, 'tcx, 'v> { } struct SuggestContext<'a, 'tcx, 'v> { - terminals: &'v [&'v Expr], + terminals: &'v [&'v Expr<'v>], cx: &'a LateContext<'a, 'tcx>, output: String, } @@ -222,7 +222,7 @@ impl<'a, 'tcx, 'v> SuggestContext<'a, 'tcx, 'v> { } } -fn simplify_not(cx: &LateContext<'_, '_>, expr: &Expr) -> Option { +fn simplify_not(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> Option { match &expr.kind { ExprKind::Binary(binop, lhs, rhs) => { if !implements_ord(cx, lhs) { @@ -266,7 +266,7 @@ fn simplify_not(cx: &LateContext<'_, '_>, expr: &Expr) -> Option { } } -fn suggest(cx: &LateContext<'_, '_>, suggestion: &Bool, terminals: &[&Expr]) -> String { +fn suggest(cx: &LateContext<'_, '_>, suggestion: &Bool, terminals: &[&Expr<'_>]) -> String { let mut suggest_context = SuggestContext { terminals, cx, @@ -332,7 +332,7 @@ fn terminal_stats(b: &Bool) -> Stats { } impl<'a, 'tcx> NonminimalBoolVisitor<'a, 'tcx> { - fn bool_expr(&self, e: &'tcx Expr) { + fn bool_expr(&self, e: &'tcx Expr<'_>) { let mut h2q = Hir2Qmm { terminals: Vec::new(), cx: self.cx, @@ -437,7 +437,7 @@ impl<'a, 'tcx> NonminimalBoolVisitor<'a, 'tcx> { } impl<'a, 'tcx> Visitor<'tcx> for NonminimalBoolVisitor<'a, 'tcx> { - fn visit_expr(&mut self, e: &'tcx Expr) { + fn visit_expr(&mut self, e: &'tcx Expr<'_>) { if in_macro(e.span) { return; } @@ -460,7 +460,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NonminimalBoolVisitor<'a, 'tcx> { } } -fn implements_ord<'a, 'tcx>(cx: &'a LateContext<'a, 'tcx>, expr: &Expr) -> bool { +fn implements_ord<'a, 'tcx>(cx: &'a LateContext<'a, 'tcx>, expr: &Expr<'_>) -> bool { let ty = cx.tables.expr_ty(expr); get_trait_def_id(cx, &paths::ORD).map_or(false, |id| implements_trait(cx, ty, id, &[])) } @@ -470,7 +470,7 @@ struct NotSimplificationVisitor<'a, 'tcx> { } impl<'a, 'tcx> Visitor<'tcx> for NotSimplificationVisitor<'a, 'tcx> { - fn visit_expr(&mut self, expr: &'tcx Expr) { + fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { if let ExprKind::Unary(UnNot, inner) = &expr.kind { if let Some(suggestion) = simplify_not(self.cx, inner) { span_lint_and_sugg( diff --git a/clippy_lints/src/bytecount.rs b/clippy_lints/src/bytecount.rs index 4c0a4bdcae12..9a0e56240f11 100644 --- a/clippy_lints/src/bytecount.rs +++ b/clippy_lints/src/bytecount.rs @@ -36,7 +36,7 @@ declare_clippy_lint! { declare_lint_pass!(ByteCount => [NAIVE_BYTECOUNT]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ByteCount { - fn check_expr(&mut self, cx: &LateContext<'_, '_>, expr: &Expr) { + fn check_expr(&mut self, cx: &LateContext<'_, '_>, expr: &Expr<'_>) { if_chain! { if let ExprKind::MethodCall(ref count, _, ref count_args) = expr.kind; if count.ident.name == sym!(count); @@ -96,11 +96,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ByteCount { } } -fn check_arg(name: Name, arg: Name, needle: &Expr) -> bool { +fn check_arg(name: Name, arg: Name, needle: &Expr<'_>) -> bool { name == arg && !contains_name(name, needle) } -fn get_path_name(expr: &Expr) -> Option { +fn get_path_name(expr: &Expr<'_>) -> Option { match expr.kind { ExprKind::Box(ref e) | ExprKind::AddrOf(BorrowKind::Ref, _, ref e) | ExprKind::Unary(UnOp::UnDeref, ref e) => { get_path_name(e) diff --git a/clippy_lints/src/checked_conversions.rs b/clippy_lints/src/checked_conversions.rs index abd44974fa7b..af07cbea46f1 100644 --- a/clippy_lints/src/checked_conversions.rs +++ b/clippy_lints/src/checked_conversions.rs @@ -42,7 +42,7 @@ declare_clippy_lint! { declare_lint_pass!(CheckedConversions => [CHECKED_CONVERSIONS]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CheckedConversions { - fn check_expr(&mut self, cx: &LateContext<'_, '_>, item: &Expr) { + fn check_expr(&mut self, cx: &LateContext<'_, '_>, item: &Expr<'_>) { let result = if_chain! { if !in_external_macro(cx.sess(), item.span); if let ExprKind::Binary(op, ref left, ref right) = &item.kind; @@ -84,12 +84,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CheckedConversions { /// Searches for a single check from unsigned to _ is done /// todo: check for case signed -> larger unsigned == only x >= 0 -fn single_check(expr: &Expr) -> Option> { +fn single_check<'tcx>(expr: &'tcx Expr<'tcx>) -> Option> { check_upper_bound(expr).filter(|cv| cv.cvt == ConversionType::FromUnsigned) } /// Searches for a combination of upper & lower bound checks -fn double_check<'a>(cx: &LateContext<'_, '_>, left: &'a Expr, right: &'a Expr) -> Option> { +fn double_check<'a>(cx: &LateContext<'_, '_>, left: &'a Expr<'_>, right: &'a Expr<'_>) -> Option> { let upper_lower = |l, r| { let upper = check_upper_bound(l); let lower = check_lower_bound(r); @@ -104,7 +104,7 @@ fn double_check<'a>(cx: &LateContext<'_, '_>, left: &'a Expr, right: &'a Expr) - #[derive(Clone, Debug)] struct Conversion<'a> { cvt: ConversionType, - expr_to_cast: &'a Expr, + expr_to_cast: &'a Expr<'a>, to_type: Option<&'a str>, } @@ -141,7 +141,7 @@ impl<'a> Conversion<'a> { } /// Try to construct a new conversion if the conversion type is valid - fn try_new(expr_to_cast: &'a Expr, from_type: &str, to_type: &'a str) -> Option> { + fn try_new(expr_to_cast: &'a Expr<'_>, from_type: &str, to_type: &'a str) -> Option> { ConversionType::try_new(from_type, to_type).map(|cvt| Conversion { cvt, expr_to_cast, @@ -150,7 +150,7 @@ impl<'a> Conversion<'a> { } /// Construct a new conversion without type constraint - fn new_any(expr_to_cast: &'a Expr) -> Conversion<'a> { + fn new_any(expr_to_cast: &'a Expr<'_>) -> Conversion<'a> { Conversion { cvt: ConversionType::SignedToUnsigned, expr_to_cast, @@ -180,7 +180,7 @@ impl ConversionType { } /// Check for `expr <= (to_type::max_value() as from_type)` -fn check_upper_bound(expr: &Expr) -> Option> { +fn check_upper_bound<'tcx>(expr: &'tcx Expr<'tcx>) -> Option> { if_chain! { if let ExprKind::Binary(ref op, ref left, ref right) = &expr.kind; if let Some((candidate, check)) = normalize_le_ge(op, left, right); @@ -195,8 +195,8 @@ fn check_upper_bound(expr: &Expr) -> Option> { } /// Check for `expr >= 0|(to_type::min_value() as from_type)` -fn check_lower_bound(expr: &Expr) -> Option> { - fn check_function<'a>(candidate: &'a Expr, check: &'a Expr) -> Option> { +fn check_lower_bound<'tcx>(expr: &'tcx Expr<'tcx>) -> Option> { + fn check_function<'a>(candidate: &'a Expr<'a>, check: &'a Expr<'a>) -> Option> { (check_lower_bound_zero(candidate, check)).or_else(|| (check_lower_bound_min(candidate, check))) } @@ -209,7 +209,7 @@ fn check_lower_bound(expr: &Expr) -> Option> { } /// Check for `expr >= 0` -fn check_lower_bound_zero<'a>(candidate: &'a Expr, check: &'a Expr) -> Option> { +fn check_lower_bound_zero<'a>(candidate: &'a Expr<'_>, check: &'a Expr<'_>) -> Option> { if_chain! { if let ExprKind::Lit(ref lit) = &check.kind; if let LitKind::Int(0, _) = &lit.node; @@ -223,7 +223,7 @@ fn check_lower_bound_zero<'a>(candidate: &'a Expr, check: &'a Expr) -> Option= (to_type::min_value() as from_type)` -fn check_lower_bound_min<'a>(candidate: &'a Expr, check: &'a Expr) -> Option> { +fn check_lower_bound_min<'a>(candidate: &'a Expr<'_>, check: &'a Expr<'_>) -> Option> { if let Some((from, to)) = get_types_from_cast(check, MIN_VALUE, SINTS) { Conversion::try_new(candidate, from, to) } else { @@ -232,9 +232,9 @@ fn check_lower_bound_min<'a>(candidate: &'a Expr, check: &'a Expr) -> Option(expr: &'a Expr, func: &'a str, types: &'a [&str]) -> Option<(&'a str, &'a str)> { +fn get_types_from_cast<'a>(expr: &'a Expr<'_>, func: &'a str, types: &'a [&str]) -> Option<(&'a str, &'a str)> { // `to_type::maxmin_value() as from_type` - let call_from_cast: Option<(&Expr, &str)> = if_chain! { + let call_from_cast: Option<(&Expr<'_>, &str)> = if_chain! { // to_type::maxmin_value(), from_type if let ExprKind::Cast(ref limit, ref from_type) = &expr.kind; if let TyKind::Path(ref from_type_path) = &from_type.kind; @@ -248,7 +248,7 @@ fn get_types_from_cast<'a>(expr: &'a Expr, func: &'a str, types: &'a [&str]) -> }; // `from_type::from(to_type::maxmin_value())` - let limit_from: Option<(&Expr, &str)> = call_from_cast.or_else(|| { + let limit_from: Option<(&Expr<'_>, &str)> = call_from_cast.or_else(|| { if_chain! { // `from_type::from, to_type::maxmin_value()` if let ExprKind::Call(ref from_func, ref args) = &expr.kind; @@ -327,7 +327,7 @@ fn transpose(lhs: Option, rhs: Option) -> Option<(T, U)> { } /// Will return the expressions as if they were expr1 <= expr2 -fn normalize_le_ge<'a>(op: &BinOp, left: &'a Expr, right: &'a Expr) -> Option<(&'a Expr, &'a Expr)> { +fn normalize_le_ge<'a>(op: &BinOp, left: &'a Expr<'a>, right: &'a Expr<'a>) -> Option<(&'a Expr<'a>, &'a Expr<'a>)> { match op.node { BinOpKind::Le => Some((left, right)), BinOpKind::Ge => Some((right, left)), diff --git a/clippy_lints/src/cognitive_complexity.rs b/clippy_lints/src/cognitive_complexity.rs index a0cb1d633b94..37c1283db8dc 100644 --- a/clippy_lints/src/cognitive_complexity.rs +++ b/clippy_lints/src/cognitive_complexity.rs @@ -141,7 +141,7 @@ struct CCHelper { } impl<'tcx> Visitor<'tcx> for CCHelper { - fn visit_expr(&mut self, e: &'tcx Expr) { + fn visit_expr(&mut self, e: &'tcx Expr<'_>) { walk_expr(self, e); match e.kind { ExprKind::Match(_, ref arms, _) => { diff --git a/clippy_lints/src/comparison_chain.rs b/clippy_lints/src/comparison_chain.rs index 9cbd30542b6b..0ee8bb199295 100644 --- a/clippy_lints/src/comparison_chain.rs +++ b/clippy_lints/src/comparison_chain.rs @@ -54,7 +54,7 @@ declare_clippy_lint! { declare_lint_pass!(ComparisonChain => [COMPARISON_CHAIN]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ComparisonChain { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { + fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { if expr.span.from_expansion() { return; } diff --git a/clippy_lints/src/consts.rs b/clippy_lints/src/consts.rs index f1e488a7e6d6..29a087bba113 100644 --- a/clippy_lints/src/consts.rs +++ b/clippy_lints/src/consts.rs @@ -178,7 +178,7 @@ pub fn lit_to_constant(lit: &LitKind, ty: Option>) -> Constant { pub fn constant<'c, 'cc>( lcx: &LateContext<'c, 'cc>, tables: &'c ty::TypeckTables<'cc>, - e: &Expr, + e: &Expr<'_>, ) -> Option<(Constant, bool)> { let mut cx = ConstEvalLateContext { lcx, @@ -193,7 +193,7 @@ pub fn constant<'c, 'cc>( pub fn constant_simple<'c, 'cc>( lcx: &LateContext<'c, 'cc>, tables: &'c ty::TypeckTables<'cc>, - e: &Expr, + e: &Expr<'_>, ) -> Option { constant(lcx, tables, e).and_then(|(cst, res)| if res { None } else { Some(cst) }) } @@ -222,7 +222,7 @@ pub struct ConstEvalLateContext<'a, 'tcx> { impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> { /// Simple constant folding: Insert an expression, get a constant or none. - pub fn expr(&mut self, e: &Expr) -> Option { + pub fn expr(&mut self, e: &Expr<'_>) -> Option { if let Some((ref cond, ref then, otherwise)) = higher::if_block(&e) { return self.ifthenelse(cond, then, otherwise); } @@ -315,7 +315,7 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> { /// Create `Some(Vec![..])` of all constants, unless there is any /// non-constant part. - fn multi(&mut self, vec: &[Expr]) -> Option> { + fn multi(&mut self, vec: &[Expr<'_>]) -> Option> { vec.iter().map(|elem| self.expr(elem)).collect::>() } @@ -348,7 +348,7 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> { } /// A block can only yield a constant if it only has one constant expression. - fn block(&mut self, block: &Block) -> Option { + fn block(&mut self, block: &Block<'_>) -> Option { if block.stmts.is_empty() { block.expr.as_ref().and_then(|b| self.expr(b)) } else { @@ -356,7 +356,7 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> { } } - fn ifthenelse(&mut self, cond: &Expr, then: &Expr, otherwise: Option<&Expr>) -> Option { + fn ifthenelse(&mut self, cond: &Expr<'_>, then: &Expr<'_>, otherwise: Option<&Expr<'_>>) -> Option { if let Some(Constant::Bool(b)) = self.expr(cond) { if b { self.expr(&*then) @@ -368,7 +368,7 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> { } } - fn binop(&mut self, op: BinOp, left: &Expr, right: &Expr) -> Option { + fn binop(&mut self, op: BinOp, left: &Expr<'_>, right: &Expr<'_>) -> Option { let l = self.expr(left)?; let r = self.expr(right); match (l, r) { diff --git a/clippy_lints/src/copies.rs b/clippy_lints/src/copies.rs index 0c352e5a60f1..e5f770539c33 100644 --- a/clippy_lints/src/copies.rs +++ b/clippy_lints/src/copies.rs @@ -153,7 +153,7 @@ declare_clippy_lint! { declare_lint_pass!(CopyAndPaste => [IFS_SAME_COND, SAME_FUNCTIONS_IN_IF_CONDITION, IF_SAME_THEN_ELSE, MATCH_SAME_ARMS]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CopyAndPaste { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { + fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { if !expr.span.from_expansion() { // skip ifs directly in else, it will be checked in the parent if if let Some(expr) = get_parent_expr(cx, expr) { @@ -174,8 +174,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CopyAndPaste { } /// Implementation of `IF_SAME_THEN_ELSE`. -fn lint_same_then_else(cx: &LateContext<'_, '_>, blocks: &[&Block]) { - let eq: &dyn Fn(&&Block, &&Block) -> bool = &|&lhs, &rhs| -> bool { SpanlessEq::new(cx).eq_block(lhs, rhs) }; +fn lint_same_then_else(cx: &LateContext<'_, '_>, blocks: &[&Block<'_>]) { + let eq: &dyn Fn(&&Block<'_>, &&Block<'_>) -> bool = + &|&lhs, &rhs| -> bool { SpanlessEq::new(cx).eq_block(lhs, rhs) }; if let Some((i, j)) = search_same_sequenced(blocks, eq) { span_note_and_lint( @@ -190,14 +191,14 @@ fn lint_same_then_else(cx: &LateContext<'_, '_>, blocks: &[&Block]) { } /// Implementation of `IFS_SAME_COND`. -fn lint_same_cond(cx: &LateContext<'_, '_>, conds: &[&Expr]) { - let hash: &dyn Fn(&&Expr) -> u64 = &|expr| -> u64 { +fn lint_same_cond(cx: &LateContext<'_, '_>, conds: &[&Expr<'_>]) { + let hash: &dyn Fn(&&Expr<'_>) -> u64 = &|expr| -> u64 { let mut h = SpanlessHash::new(cx, cx.tables); h.hash_expr(expr); h.finish() }; - let eq: &dyn Fn(&&Expr, &&Expr) -> bool = + let eq: &dyn Fn(&&Expr<'_>, &&Expr<'_>) -> bool = &|&lhs, &rhs| -> bool { SpanlessEq::new(cx).ignore_fn().eq_expr(lhs, rhs) }; for (i, j) in search_same(conds, hash, eq) { @@ -213,14 +214,14 @@ fn lint_same_cond(cx: &LateContext<'_, '_>, conds: &[&Expr]) { } /// Implementation of `SAME_FUNCTIONS_IN_IF_CONDITION`. -fn lint_same_fns_in_if_cond(cx: &LateContext<'_, '_>, conds: &[&Expr]) { - let hash: &dyn Fn(&&Expr) -> u64 = &|expr| -> u64 { +fn lint_same_fns_in_if_cond(cx: &LateContext<'_, '_>, conds: &[&Expr<'_>]) { + let hash: &dyn Fn(&&Expr<'_>) -> u64 = &|expr| -> u64 { let mut h = SpanlessHash::new(cx, cx.tables); h.hash_expr(expr); h.finish() }; - let eq: &dyn Fn(&&Expr, &&Expr) -> bool = &|&lhs, &rhs| -> bool { + let eq: &dyn Fn(&&Expr<'_>, &&Expr<'_>) -> bool = &|&lhs, &rhs| -> bool { // Do not spawn warning if `IFS_SAME_COND` already produced it. if SpanlessEq::new(cx).ignore_fn().eq_expr(lhs, rhs) { return false; @@ -241,7 +242,7 @@ fn lint_same_fns_in_if_cond(cx: &LateContext<'_, '_>, conds: &[&Expr]) { } /// Implementation of `MATCH_SAME_ARMS`. -fn lint_match_arms<'tcx>(cx: &LateContext<'_, 'tcx>, expr: &Expr) { +fn lint_match_arms<'tcx>(cx: &LateContext<'_, 'tcx>, expr: &Expr<'_>) { fn same_bindings<'tcx>( cx: &LateContext<'_, 'tcx>, lhs: &FxHashMap>, @@ -254,13 +255,13 @@ fn lint_match_arms<'tcx>(cx: &LateContext<'_, 'tcx>, expr: &Expr) { } if let ExprKind::Match(_, ref arms, MatchSource::Normal) = expr.kind { - let hash = |&(_, arm): &(usize, &Arm)| -> u64 { + let hash = |&(_, arm): &(usize, &Arm<'_>)| -> u64 { let mut h = SpanlessHash::new(cx, cx.tables); h.hash_expr(&arm.body); h.finish() }; - let eq = |&(lindex, lhs): &(usize, &Arm), &(rindex, rhs): &(usize, &Arm)| -> bool { + let eq = |&(lindex, lhs): &(usize, &Arm<'_>), &(rindex, rhs): &(usize, &Arm<'_>)| -> bool { let min_index = usize::min(lindex, rindex); let max_index = usize::max(lindex, rindex); @@ -272,7 +273,7 @@ fn lint_match_arms<'tcx>(cx: &LateContext<'_, 'tcx>, expr: &Expr) { same_bindings(cx, &bindings(cx, &lhs.pat), &bindings(cx, &rhs.pat)) }; - let indexed_arms: Vec<(usize, &Arm)> = arms.iter().enumerate().collect(); + let indexed_arms: Vec<(usize, &Arm<'_>)> = arms.iter().enumerate().collect(); for (&(_, i), &(_, j)) in search_same(&indexed_arms, hash, eq) { span_lint_and_then( cx, @@ -313,11 +314,11 @@ fn lint_match_arms<'tcx>(cx: &LateContext<'_, 'tcx>, expr: &Expr) { } /// Returns the list of bindings in a pattern. -fn bindings<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, pat: &Pat) -> FxHashMap> { - fn bindings_impl<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, pat: &Pat, map: &mut FxHashMap>) { +fn bindings<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, pat: &Pat<'_>) -> FxHashMap> { + fn bindings_impl<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, pat: &Pat<'_>, map: &mut FxHashMap>) { match pat.kind { PatKind::Box(ref pat) | PatKind::Ref(ref pat, _) => bindings_impl(cx, pat, map), - PatKind::TupleStruct(_, ref pats, _) => { + PatKind::TupleStruct(_, pats, _) => { for pat in pats { bindings_impl(cx, pat, map); } @@ -330,17 +331,17 @@ fn bindings<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, pat: &Pat) -> FxHashMap { + PatKind::Or(fields) | PatKind::Tuple(fields, _) => { for pat in fields { bindings_impl(cx, pat, map); } }, - PatKind::Struct(_, ref fields, _) => { + PatKind::Struct(_, fields, _) => { for pat in fields { bindings_impl(cx, &pat.pat, map); } }, - PatKind::Slice(ref lhs, ref mid, ref rhs) => { + PatKind::Slice(lhs, ref mid, rhs) => { for pat in lhs { bindings_impl(cx, pat, map); } diff --git a/clippy_lints/src/default_trait_access.rs b/clippy_lints/src/default_trait_access.rs index 3fa2ede84717..ceacd41e0de8 100644 --- a/clippy_lints/src/default_trait_access.rs +++ b/clippy_lints/src/default_trait_access.rs @@ -32,7 +32,7 @@ declare_clippy_lint! { declare_lint_pass!(DefaultTraitAccess => [DEFAULT_TRAIT_ACCESS]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DefaultTraitAccess { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { + fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { if_chain! { if let ExprKind::Call(ref path, ..) = expr.kind; if !any_parent_is_automatically_derived(cx.tcx, expr.hir_id); diff --git a/clippy_lints/src/double_comparison.rs b/clippy_lints/src/double_comparison.rs index e7abc3c91384..5cadf41fd1b9 100644 --- a/clippy_lints/src/double_comparison.rs +++ b/clippy_lints/src/double_comparison.rs @@ -40,7 +40,7 @@ declare_lint_pass!(DoubleComparisons => [DOUBLE_COMPARISONS]); impl<'a, 'tcx> DoubleComparisons { #[allow(clippy::similar_names)] - fn check_binop(cx: &LateContext<'a, 'tcx>, op: BinOpKind, lhs: &'tcx Expr, rhs: &'tcx Expr, span: Span) { + fn check_binop(cx: &LateContext<'a, 'tcx>, op: BinOpKind, lhs: &'tcx Expr<'_>, rhs: &'tcx Expr<'_>, span: Span) { let (lkind, llhs, lrhs, rkind, rlhs, rrhs) = match (&lhs.kind, &rhs.kind) { (ExprKind::Binary(lb, llhs, lrhs), ExprKind::Binary(rb, rlhs, rrhs)) => { (lb.node, llhs, lrhs, rb.node, rlhs, rrhs) @@ -88,7 +88,7 @@ impl<'a, 'tcx> DoubleComparisons { } impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DoubleComparisons { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { + fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { if let ExprKind::Binary(ref kind, ref lhs, ref rhs) = expr.kind { Self::check_binop(cx, kind.node, lhs, rhs, expr.span); } diff --git a/clippy_lints/src/drop_forget_ref.rs b/clippy_lints/src/drop_forget_ref.rs index 7b049ed5d41f..a0619f02df1b 100644 --- a/clippy_lints/src/drop_forget_ref.rs +++ b/clippy_lints/src/drop_forget_ref.rs @@ -110,7 +110,7 @@ const FORGET_COPY_SUMMARY: &str = "calls to `std::mem::forget` with a value that declare_lint_pass!(DropForgetRef => [DROP_REF, FORGET_REF, DROP_COPY, FORGET_COPY]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DropForgetRef { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { + fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { if_chain! { if let ExprKind::Call(ref path, ref args) = expr.kind; if let ExprKind::Path(ref qpath) = path.kind; diff --git a/clippy_lints/src/duration_subsec.rs b/clippy_lints/src/duration_subsec.rs index d5661e6223d6..cf8d0f542ad0 100644 --- a/clippy_lints/src/duration_subsec.rs +++ b/clippy_lints/src/duration_subsec.rs @@ -34,7 +34,7 @@ declare_clippy_lint! { declare_lint_pass!(DurationSubsec => [DURATION_SUBSEC]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DurationSubsec { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { + fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { if_chain! { if let ExprKind::Binary(Spanned { node: BinOpKind::Div, .. }, ref left, ref right) = expr.kind; if let ExprKind::MethodCall(ref method_path, _ , ref args) = left.kind; diff --git a/clippy_lints/src/entry.rs b/clippy_lints/src/entry.rs index 4403ef45ca33..1d935d2a448e 100644 --- a/clippy_lints/src/entry.rs +++ b/clippy_lints/src/entry.rs @@ -53,7 +53,7 @@ declare_clippy_lint! { declare_lint_pass!(HashMapPass => [MAP_ENTRY]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for HashMapPass { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { + fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { if let Some((ref check, ref then_block, ref else_block)) = higher::if_block(&expr) { if let ExprKind::Unary(UnOp::UnNot, ref check) = check.kind { if let Some((ty, map, key)) = check_cond(cx, check) { @@ -100,8 +100,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for HashMapPass { fn check_cond<'a, 'tcx, 'b>( cx: &'a LateContext<'a, 'tcx>, - check: &'b Expr, -) -> Option<(&'static str, &'b Expr, &'b Expr)> { + check: &'b Expr<'b>, +) -> Option<(&'static str, &'b Expr<'b>, &'b Expr<'b>)> { if_chain! { if let ExprKind::MethodCall(ref path, _, ref params) = check.kind; if params.len() >= 2; @@ -130,13 +130,13 @@ struct InsertVisitor<'a, 'tcx, 'b> { cx: &'a LateContext<'a, 'tcx>, span: Span, ty: &'static str, - map: &'b Expr, - key: &'b Expr, + map: &'b Expr<'b>, + key: &'b Expr<'b>, sole_expr: bool, } impl<'a, 'tcx, 'b> Visitor<'tcx> for InsertVisitor<'a, 'tcx, 'b> { - fn visit_expr(&mut self, expr: &'tcx Expr) { + fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { if_chain! { if let ExprKind::MethodCall(ref path, _, ref params) = expr.kind; if params.len() == 3; diff --git a/clippy_lints/src/eq_op.rs b/clippy_lints/src/eq_op.rs index 392fb0a6bf44..90b1b2d92cb5 100644 --- a/clippy_lints/src/eq_op.rs +++ b/clippy_lints/src/eq_op.rs @@ -49,7 +49,7 @@ declare_lint_pass!(EqOp => [EQ_OP, OP_REF]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp { #[allow(clippy::similar_names, clippy::too_many_lines)] - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) { + fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) { if let ExprKind::Binary(op, ref left, ref right) = e.kind { if e.span.from_expansion() { return; diff --git a/clippy_lints/src/erasing_op.rs b/clippy_lints/src/erasing_op.rs index 4fa0a232e232..6e10e0c1aa91 100644 --- a/clippy_lints/src/erasing_op.rs +++ b/clippy_lints/src/erasing_op.rs @@ -31,7 +31,7 @@ declare_clippy_lint! { declare_lint_pass!(ErasingOp => [ERASING_OP]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ErasingOp { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) { + fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) { if e.span.from_expansion() { return; } @@ -48,7 +48,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ErasingOp { } } -fn check(cx: &LateContext<'_, '_>, e: &Expr, span: Span) { +fn check(cx: &LateContext<'_, '_>, e: &Expr<'_>, span: Span) { if let Some(Constant::Int(0)) = constant_simple(cx, cx.tables, e) { span_lint( cx, diff --git a/clippy_lints/src/eta_reduction.rs b/clippy_lints/src/eta_reduction.rs index 0abe757e3597..acaa432137d0 100644 --- a/clippy_lints/src/eta_reduction.rs +++ b/clippy_lints/src/eta_reduction.rs @@ -61,13 +61,13 @@ declare_clippy_lint! { declare_lint_pass!(EtaReduction => [REDUNDANT_CLOSURE, REDUNDANT_CLOSURE_FOR_METHOD_CALLS]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EtaReduction { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { + fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { if in_external_macro(cx.sess(), expr.span) { return; } match expr.kind { - ExprKind::Call(_, ref args) | ExprKind::MethodCall(_, _, ref args) => { + ExprKind::Call(_, args) | ExprKind::MethodCall(_, _, args) => { for arg in args { check_closure(cx, arg) } @@ -77,7 +77,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EtaReduction { } } -fn check_closure(cx: &LateContext<'_, '_>, expr: &Expr) { +fn check_closure(cx: &LateContext<'_, '_>, expr: &Expr<'_>) { if let ExprKind::Closure(_, ref decl, eid, _, _) = expr.kind { let body = cx.tcx.hir().body(eid); let ex = &body.value; @@ -99,7 +99,7 @@ fn check_closure(cx: &LateContext<'_, '_>, expr: &Expr) { if !type_is_unsafe_function(cx, fn_ty); - if compare_inputs(&mut iter_input_pats(decl, body), &mut args.into_iter()); + if compare_inputs(&mut iter_input_pats(decl, body), &mut args.iter()); then { span_lint_and_then(cx, REDUNDANT_CLOSURE, expr.span, "redundant closure found", |db| { @@ -127,7 +127,7 @@ fn check_closure(cx: &LateContext<'_, '_>, expr: &Expr) { let method_def_id = cx.tables.type_dependent_def_id(ex.hir_id).unwrap(); if !type_is_unsafe_function(cx, cx.tcx.type_of(method_def_id)); - if compare_inputs(&mut iter_input_pats(decl, body), &mut args.into_iter()); + if compare_inputs(&mut iter_input_pats(decl, body), &mut args.iter()); if let Some(name) = get_ufcs_type_name(cx, method_def_id, &args[0]); @@ -146,7 +146,7 @@ fn check_closure(cx: &LateContext<'_, '_>, expr: &Expr) { } /// Tries to determine the type for universal function call to be used instead of the closure -fn get_ufcs_type_name(cx: &LateContext<'_, '_>, method_def_id: def_id::DefId, self_arg: &Expr) -> Option { +fn get_ufcs_type_name(cx: &LateContext<'_, '_>, method_def_id: def_id::DefId, self_arg: &Expr<'_>) -> Option { let expected_type_of_self = &cx.tcx.fn_sig(method_def_id).inputs_and_output().skip_binder()[0]; let actual_type_of_self = &cx.tables.node_type(self_arg.hir_id); @@ -200,8 +200,8 @@ fn get_type_name(cx: &LateContext<'_, '_>, ty: Ty<'_>) -> String { } fn compare_inputs( - closure_inputs: &mut dyn Iterator, - call_args: &mut dyn Iterator, + closure_inputs: &mut dyn Iterator>, + call_args: &mut dyn Iterator>, ) -> bool { for (closure_input, function_arg) in closure_inputs.zip(call_args) { if let PatKind::Binding(_, _, ident, _) = closure_input.pat.kind { diff --git a/clippy_lints/src/eval_order_dependence.rs b/clippy_lints/src/eval_order_dependence.rs index 7bf37f9d479d..27ede8bdfdbf 100644 --- a/clippy_lints/src/eval_order_dependence.rs +++ b/clippy_lints/src/eval_order_dependence.rs @@ -59,7 +59,7 @@ declare_clippy_lint! { declare_lint_pass!(EvalOrderDependence => [EVAL_ORDER_DEPENDENCE, DIVERGING_SUB_EXPRESSION]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EvalOrderDependence { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { + fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { // Find a write to a local variable. match expr.kind { ExprKind::Assign(ref lhs, ..) | ExprKind::AssignOp(_, ref lhs, _) => { @@ -82,7 +82,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EvalOrderDependence { _ => {}, } } - fn check_stmt(&mut self, cx: &LateContext<'a, 'tcx>, stmt: &'tcx Stmt) { + fn check_stmt(&mut self, cx: &LateContext<'a, 'tcx>, stmt: &'tcx Stmt<'_>) { match stmt.kind { StmtKind::Local(ref local) => { if let Local { init: Some(ref e), .. } = **local { @@ -100,10 +100,10 @@ struct DivergenceVisitor<'a, 'tcx> { } impl<'a, 'tcx> DivergenceVisitor<'a, 'tcx> { - fn maybe_walk_expr(&mut self, e: &'tcx Expr) { + fn maybe_walk_expr(&mut self, e: &'tcx Expr<'_>) { match e.kind { ExprKind::Closure(..) => {}, - ExprKind::Match(ref e, ref arms, _) => { + ExprKind::Match(ref e, arms, _) => { self.visit_expr(e); for arm in arms { if let Some(ref guard) = arm.guard { @@ -118,13 +118,13 @@ impl<'a, 'tcx> DivergenceVisitor<'a, 'tcx> { _ => walk_expr(self, e), } } - fn report_diverging_sub_expr(&mut self, e: &Expr) { + fn report_diverging_sub_expr(&mut self, e: &Expr<'_>) { span_lint(self.cx, DIVERGING_SUB_EXPRESSION, e.span, "sub-expression diverges"); } } impl<'a, 'tcx> Visitor<'tcx> for DivergenceVisitor<'a, 'tcx> { - fn visit_expr(&mut self, e: &'tcx Expr) { + fn visit_expr(&mut self, e: &'tcx Expr<'_>) { match e.kind { ExprKind::Continue(_) | ExprKind::Break(_, _) | ExprKind::Ret(_) => self.report_diverging_sub_expr(e), ExprKind::Call(ref func, _) => { @@ -153,7 +153,7 @@ impl<'a, 'tcx> Visitor<'tcx> for DivergenceVisitor<'a, 'tcx> { } self.maybe_walk_expr(e); } - fn visit_block(&mut self, _: &'tcx Block) { + fn visit_block(&mut self, _: &'tcx Block<'_>) { // don't continue over blocks, LateLintPass already does that } fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> { @@ -214,7 +214,7 @@ enum StopEarly { Stop, } -fn check_expr<'a, 'tcx>(vis: &mut ReadVisitor<'a, 'tcx>, expr: &'tcx Expr) -> StopEarly { +fn check_expr<'a, 'tcx>(vis: &mut ReadVisitor<'a, 'tcx>, expr: &'tcx Expr<'_>) -> StopEarly { if expr.hir_id == vis.last_expr.hir_id { return StopEarly::KeepGoing; } @@ -261,7 +261,7 @@ fn check_expr<'a, 'tcx>(vis: &mut ReadVisitor<'a, 'tcx>, expr: &'tcx Expr) -> St StopEarly::KeepGoing } -fn check_stmt<'a, 'tcx>(vis: &mut ReadVisitor<'a, 'tcx>, stmt: &'tcx Stmt) -> StopEarly { +fn check_stmt<'a, 'tcx>(vis: &mut ReadVisitor<'a, 'tcx>, stmt: &'tcx Stmt<'_>) -> StopEarly { match stmt.kind { StmtKind::Expr(ref expr) | StmtKind::Semi(ref expr) => check_expr(vis, expr), // If the declaration is of a local variable, check its initializer @@ -281,14 +281,14 @@ struct ReadVisitor<'a, 'tcx> { var: HirId, /// The expressions where the write to the variable occurred (for reporting /// in the lint). - write_expr: &'tcx Expr, + write_expr: &'tcx Expr<'tcx>, /// The last (highest in the AST) expression we've checked, so we know not /// to recheck it. - last_expr: &'tcx Expr, + last_expr: &'tcx Expr<'tcx>, } impl<'a, 'tcx> Visitor<'tcx> for ReadVisitor<'a, 'tcx> { - fn visit_expr(&mut self, expr: &'tcx Expr) { + fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { if expr.hir_id == self.last_expr.hir_id { return; } @@ -343,7 +343,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ReadVisitor<'a, 'tcx> { } /// Returns `true` if `expr` is the LHS of an assignment, like `expr = ...`. -fn is_in_assignment_position(cx: &LateContext<'_, '_>, expr: &Expr) -> bool { +fn is_in_assignment_position(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool { if let Some(parent) = get_parent_expr(cx, expr) { if let ExprKind::Assign(ref lhs, ..) = parent.kind { return lhs.hir_id == expr.hir_id; diff --git a/clippy_lints/src/excessive_precision.rs b/clippy_lints/src/excessive_precision.rs index 633cd2de8fc5..f6dd026335c7 100644 --- a/clippy_lints/src/excessive_precision.rs +++ b/clippy_lints/src/excessive_precision.rs @@ -40,7 +40,7 @@ declare_clippy_lint! { declare_lint_pass!(ExcessivePrecision => [EXCESSIVE_PRECISION]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ExcessivePrecision { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) { + fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr<'_>) { if_chain! { let ty = cx.tables.expr_ty(expr); if let ty::Float(fty) = ty.kind; diff --git a/clippy_lints/src/exit.rs b/clippy_lints/src/exit.rs index 42139f1c7b89..6acc4fa1f4a0 100644 --- a/clippy_lints/src/exit.rs +++ b/clippy_lints/src/exit.rs @@ -26,7 +26,7 @@ declare_clippy_lint! { declare_lint_pass!(Exit => [EXIT]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Exit { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) { + fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) { if_chain! { if let ExprKind::Call(ref path_expr, ref _args) = e.kind; if let ExprKind::Path(ref path) = path_expr.kind; diff --git a/clippy_lints/src/explicit_write.rs b/clippy_lints/src/explicit_write.rs index 9ebda4f1184a..46655ca0003e 100644 --- a/clippy_lints/src/explicit_write.rs +++ b/clippy_lints/src/explicit_write.rs @@ -30,18 +30,18 @@ declare_clippy_lint! { declare_lint_pass!(ExplicitWrite => [EXPLICIT_WRITE]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ExplicitWrite { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { + fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { if_chain! { // match call to unwrap if let ExprKind::MethodCall(ref unwrap_fun, _, ref unwrap_args) = expr.kind; if unwrap_fun.ident.name == sym!(unwrap); // match call to write_fmt - if unwrap_args.len() > 0; - if let ExprKind::MethodCall(ref write_fun, _, ref write_args) = + if !unwrap_args.is_empty(); + if let ExprKind::MethodCall(ref write_fun, _, write_args) = unwrap_args[0].kind; if write_fun.ident.name == sym!(write_fmt); // match calls to std::io::stdout() / std::io::stderr () - if write_args.len() > 0; + if !write_args.is_empty(); if let Some(dest_name) = if match_function_call(cx, &write_args[0], &paths::STDOUT).is_some() { Some("stdout") } else if match_function_call(cx, &write_args[0], &paths::STDERR).is_some() { @@ -130,12 +130,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ExplicitWrite { } // Extract the output string from the given `write_args`. -fn write_output_string(write_args: &HirVec) -> Option { +fn write_output_string(write_args: &[Expr<'_>]) -> Option { if_chain! { // Obtain the string that should be printed if write_args.len() > 1; if let ExprKind::Call(_, ref output_args) = write_args[1].kind; - if output_args.len() > 0; + if !output_args.is_empty(); if let ExprKind::AddrOf(BorrowKind::Ref, _, ref output_string_expr) = output_args[0].kind; if let ExprKind::Array(ref string_exprs) = output_string_expr.kind; // we only want to provide an automatic suggestion for simple (non-format) strings diff --git a/clippy_lints/src/fallible_impl_from.rs b/clippy_lints/src/fallible_impl_from.rs index d0ffc6c8eed9..91dbee39a02a 100644 --- a/clippy_lints/src/fallible_impl_from.rs +++ b/clippy_lints/src/fallible_impl_from.rs @@ -57,7 +57,7 @@ fn lint_impl_body<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, impl_span: Span, impl_it } impl<'a, 'tcx> Visitor<'tcx> for FindPanicUnwrap<'a, 'tcx> { - fn visit_expr(&mut self, expr: &'tcx Expr) { + fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { // check for `begin_panic` if_chain! { if let ExprKind::Call(ref func_expr, _) = expr.kind; diff --git a/clippy_lints/src/format.rs b/clippy_lints/src/format.rs index 052684818fc1..9f7a11332c36 100644 --- a/clippy_lints/src/format.rs +++ b/clippy_lints/src/format.rs @@ -38,7 +38,7 @@ declare_clippy_lint! { declare_lint_pass!(UselessFormat => [USELESS_FORMAT]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UselessFormat { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { + fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { let span = match is_expn_of(expr.span, "format") { Some(s) if !s.from_expansion() => s, _ => return, @@ -72,7 +72,11 @@ fn span_useless_format(cx: &T, span: Span, help: &str, mut sugg: }); } -fn on_argumentv1_new<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr, arms: &'tcx [Arm]) -> Option { +fn on_argumentv1_new<'a, 'tcx>( + cx: &LateContext<'a, 'tcx>, + expr: &'tcx Expr<'_>, + arms: &'tcx [Arm<'_>], +) -> Option { if_chain! { if let ExprKind::AddrOf(BorrowKind::Ref, _, ref format_args) = expr.kind; if let ExprKind::Array(ref elems) = arms[0].body.kind; @@ -111,7 +115,7 @@ fn on_argumentv1_new<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr, arm None } -fn on_new_v1<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) -> Option { +fn on_new_v1<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) -> Option { if_chain! { if let Some(args) = match_function_call(cx, expr, &paths::FMT_ARGUMENTS_NEW_V1); if args.len() == 2; @@ -138,7 +142,7 @@ fn on_new_v1<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) -> Option(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) -> Option { +fn on_new_v1_fmt<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) -> Option { if_chain! { if let Some(args) = match_function_call(cx, expr, &paths::FMT_ARGUMENTS_NEW_V1_FORMATTED); if args.len() == 3; @@ -172,7 +176,7 @@ fn on_new_v1_fmt<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) -> Opti /// ..., /// }] /// ``` -fn check_unformatted(expr: &Expr) -> bool { +fn check_unformatted(expr: &Expr<'_>) -> bool { if_chain! { if let ExprKind::AddrOf(BorrowKind::Ref, _, ref expr) = expr.kind; if let ExprKind::Array(ref exprs) = expr.kind; diff --git a/clippy_lints/src/functions.rs b/clippy_lints/src/functions.rs index b0b82d981761..0d7b24fd762d 100644 --- a/clippy_lints/src/functions.rs +++ b/clippy_lints/src/functions.rs @@ -483,7 +483,7 @@ fn has_mutable_arg(cx: &LateContext<'_, '_>, body: &hir::Body<'_>) -> bool { body.params.iter().any(|param| is_mutable_pat(cx, ¶m.pat, &mut tys)) } -fn is_mutable_pat(cx: &LateContext<'_, '_>, pat: &hir::Pat, tys: &mut FxHashSet) -> bool { +fn is_mutable_pat(cx: &LateContext<'_, '_>, pat: &hir::Pat<'_>, tys: &mut FxHashSet) -> bool { if let hir::PatKind::Wild = pat.kind { return false; // ignore `_` patterns } @@ -518,7 +518,7 @@ fn is_mutable_ty<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty<'tcx>, span: Span, } } -fn raw_ptr_arg(arg: &hir::Param, ty: &hir::Ty) -> Option { +fn raw_ptr_arg(arg: &hir::Param<'_>, ty: &hir::Ty) -> Option { if let (&hir::PatKind::Binding(_, id, _, _), &hir::TyKind::Ptr(_)) = (&arg.pat.kind, &ty.kind) { Some(id) } else { @@ -533,9 +533,9 @@ struct DerefVisitor<'a, 'tcx> { } impl<'a, 'tcx> intravisit::Visitor<'tcx> for DerefVisitor<'a, 'tcx> { - fn visit_expr(&mut self, expr: &'tcx hir::Expr) { + fn visit_expr(&mut self, expr: &'tcx hir::Expr<'_>) { match expr.kind { - hir::ExprKind::Call(ref f, ref args) => { + hir::ExprKind::Call(ref f, args) => { let ty = self.tables.expr_ty(f); if type_is_unsafe_function(self.cx, ty) { @@ -544,7 +544,7 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for DerefVisitor<'a, 'tcx> { } } }, - hir::ExprKind::MethodCall(_, _, ref args) => { + hir::ExprKind::MethodCall(_, _, args) => { let def_id = self.tables.type_dependent_def_id(expr.hir_id).unwrap(); let base_type = self.cx.tcx.type_of(def_id); @@ -567,7 +567,7 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for DerefVisitor<'a, 'tcx> { } impl<'a, 'tcx> DerefVisitor<'a, 'tcx> { - fn check_arg(&self, ptr: &hir::Expr) { + fn check_arg(&self, ptr: &hir::Expr<'_>) { if let hir::ExprKind::Path(ref qpath) = ptr.kind { if let Res::Local(id) = qpath_res(self.cx, qpath, ptr.hir_id) { if self.ptrs.contains(&id) { @@ -589,14 +589,14 @@ struct StaticMutVisitor<'a, 'tcx> { } impl<'a, 'tcx> intravisit::Visitor<'tcx> for StaticMutVisitor<'a, 'tcx> { - fn visit_expr(&mut self, expr: &'tcx hir::Expr) { + fn visit_expr(&mut self, expr: &'tcx hir::Expr<'_>) { use hir::ExprKind::*; if self.mutates_static { return; } match expr.kind { - Call(_, ref args) | MethodCall(_, _, ref args) => { + Call(_, args) | MethodCall(_, _, args) => { let mut tys = FxHashSet::default(); for arg in args { let def_id = arg.hir_id.owner_def_id(); @@ -627,7 +627,7 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for StaticMutVisitor<'a, 'tcx> { } } -fn is_mutated_static(cx: &LateContext<'_, '_>, e: &hir::Expr) -> bool { +fn is_mutated_static(cx: &LateContext<'_, '_>, e: &hir::Expr<'_>) -> bool { use hir::ExprKind::*; match e.kind { diff --git a/clippy_lints/src/get_last_with_len.rs b/clippy_lints/src/get_last_with_len.rs index 3d38d2db662d..8ee3b75c9593 100644 --- a/clippy_lints/src/get_last_with_len.rs +++ b/clippy_lints/src/get_last_with_len.rs @@ -46,7 +46,7 @@ declare_clippy_lint! { declare_lint_pass!(GetLastWithLen => [GET_LAST_WITH_LEN]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for GetLastWithLen { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { + fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { if_chain! { // Is a method call if let ExprKind::MethodCall(ref path, _, ref args) = expr.kind; diff --git a/clippy_lints/src/identity_conversion.rs b/clippy_lints/src/identity_conversion.rs index c37bb02708f0..c266c496090c 100644 --- a/clippy_lints/src/identity_conversion.rs +++ b/clippy_lints/src/identity_conversion.rs @@ -32,7 +32,7 @@ pub struct IdentityConversion { impl_lint_pass!(IdentityConversion => [IDENTITY_CONVERSION]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IdentityConversion { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) { + fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) { if e.span.from_expansion() { return; } @@ -114,7 +114,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IdentityConversion { } } - fn check_expr_post(&mut self, _: &LateContext<'a, 'tcx>, e: &'tcx Expr) { + fn check_expr_post(&mut self, _: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) { if Some(&e.hir_id) == self.try_desugar_arm.last() { self.try_desugar_arm.pop(); } diff --git a/clippy_lints/src/identity_op.rs b/clippy_lints/src/identity_op.rs index a4575c2c38fa..5f9e0aecb19e 100644 --- a/clippy_lints/src/identity_op.rs +++ b/clippy_lints/src/identity_op.rs @@ -29,7 +29,7 @@ declare_clippy_lint! { declare_lint_pass!(IdentityOp => [IDENTITY_OP]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IdentityOp { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) { + fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) { if e.span.from_expansion() { return; } @@ -56,7 +56,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IdentityOp { } #[allow(clippy::cast_possible_wrap)] -fn check(cx: &LateContext<'_, '_>, e: &Expr, m: i8, span: Span, arg: Span) { +fn check(cx: &LateContext<'_, '_>, e: &Expr<'_>, m: i8, span: Span, arg: Span) { if let Some(Constant::Int(v)) = constant_simple(cx, cx.tables, e) { let check = match cx.tables.expr_ty(e).kind { ty::Int(ity) => unsext(cx.tcx, -1_i128, ity), diff --git a/clippy_lints/src/implicit_return.rs b/clippy_lints/src/implicit_return.rs index a09856dedaea..166f371e1460 100644 --- a/clippy_lints/src/implicit_return.rs +++ b/clippy_lints/src/implicit_return.rs @@ -62,8 +62,8 @@ fn lint(cx: &LateContext<'_, '_>, outer_span: Span, inner_span: Span, msg: &str) }); } -fn expr_match(cx: &LateContext<'_, '_>, expr: &Expr) { - match &expr.kind { +fn expr_match(cx: &LateContext<'_, '_>, expr: &Expr<'_>) { + match expr.kind { // loops could be using `break` instead of `return` ExprKind::Block(block, ..) | ExprKind::Loop(block, ..) => { if let Some(expr) = &block.expr { @@ -92,7 +92,7 @@ fn expr_match(cx: &LateContext<'_, '_>, expr: &Expr) { let check_all_arms = match source { MatchSource::IfLetDesugar { contains_else_clause: has_else, - } => *has_else, + } => has_else, _ => true, }; diff --git a/clippy_lints/src/indexing_slicing.rs b/clippy_lints/src/indexing_slicing.rs index 1d42158b42c1..837df9f3808e 100644 --- a/clippy_lints/src/indexing_slicing.rs +++ b/clippy_lints/src/indexing_slicing.rs @@ -89,7 +89,7 @@ declare_clippy_lint! { declare_lint_pass!(IndexingSlicing => [INDEXING_SLICING, OUT_OF_BOUNDS_INDEXING]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IndexingSlicing { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { + fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { if let ExprKind::Index(ref array, ref index) = &expr.kind { let ty = cx.tables.expr_ty(array); if let Some(range) = higher::range(cx, index) { diff --git a/clippy_lints/src/infallible_destructuring_match.rs b/clippy_lints/src/infallible_destructuring_match.rs index a9539534ea9c..26695a66894d 100644 --- a/clippy_lints/src/infallible_destructuring_match.rs +++ b/clippy_lints/src/infallible_destructuring_match.rs @@ -44,7 +44,7 @@ declare_clippy_lint! { declare_lint_pass!(InfallibleDestructingMatch => [INFALLIBLE_DESTRUCTURING_MATCH]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InfallibleDestructingMatch { - fn check_local(&mut self, cx: &LateContext<'a, 'tcx>, local: &'tcx Local) { + fn check_local(&mut self, cx: &LateContext<'a, 'tcx>, local: &'tcx Local<'_>) { if_chain! { if let Some(ref expr) = local.init; if let ExprKind::Match(ref target, ref arms, MatchSource::Normal) = expr.kind; diff --git a/clippy_lints/src/infinite_iter.rs b/clippy_lints/src/infinite_iter.rs index b8d50e4ef009..74d4d9c072bd 100644 --- a/clippy_lints/src/infinite_iter.rs +++ b/clippy_lints/src/infinite_iter.rs @@ -46,7 +46,7 @@ declare_clippy_lint! { declare_lint_pass!(InfiniteIter => [INFINITE_ITER, MAYBE_INFINITE_ITER]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InfiniteIter { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { + fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { let (lint, msg) = match complete_infinite_iter(cx, expr) { Infinite => (INFINITE_ITER, "infinite iteration detected"), MaybeInfinite => (MAYBE_INFINITE_ITER, "possible infinite iteration detected"), @@ -141,7 +141,7 @@ const HEURISTICS: [(&str, usize, Heuristic, Finiteness); 19] = [ ("scan", 3, First, MaybeInfinite), ]; -fn is_infinite(cx: &LateContext<'_, '_>, expr: &Expr) -> Finiteness { +fn is_infinite(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> Finiteness { match expr.kind { ExprKind::MethodCall(ref method, _, ref args) => { for &(name, len, heuristic, cap) in &HEURISTICS { @@ -217,7 +217,7 @@ const INFINITE_COLLECTORS: [&[&str]; 8] = [ &paths::VEC_DEQUE, ]; -fn complete_infinite_iter(cx: &LateContext<'_, '_>, expr: &Expr) -> Finiteness { +fn complete_infinite_iter(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> Finiteness { match expr.kind { ExprKind::MethodCall(ref method, _, ref args) => { for &(name, len) in &COMPLETING_METHODS { diff --git a/clippy_lints/src/integer_division.rs b/clippy_lints/src/integer_division.rs index 4964fc6b4e30..57c9a8537452 100644 --- a/clippy_lints/src/integer_division.rs +++ b/clippy_lints/src/integer_division.rs @@ -29,7 +29,7 @@ declare_clippy_lint! { declare_lint_pass!(IntegerDivision => [INTEGER_DIVISION]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IntegerDivision { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) { + fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr<'_>) { if is_integer_division(cx, expr) { span_help_and_lint( cx, @@ -42,7 +42,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IntegerDivision { } } -fn is_integer_division<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) -> bool { +fn is_integer_division<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr<'_>) -> bool { if_chain! { if let hir::ExprKind::Binary(binop, left, right) = &expr.kind; if let hir::BinOpKind::Div = &binop.node; diff --git a/clippy_lints/src/large_stack_arrays.rs b/clippy_lints/src/large_stack_arrays.rs index 4cfa50b3ff39..f5d5c95ed7aa 100644 --- a/clippy_lints/src/large_stack_arrays.rs +++ b/clippy_lints/src/large_stack_arrays.rs @@ -40,7 +40,7 @@ impl LargeStackArrays { impl_lint_pass!(LargeStackArrays => [LARGE_STACK_ARRAYS]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LargeStackArrays { - fn check_expr(&mut self, cx: &LateContext<'_, '_>, expr: &Expr) { + fn check_expr(&mut self, cx: &LateContext<'_, '_>, expr: &Expr<'_>) { if_chain! { if let ExprKind::Repeat(_, _) = expr.kind; if let ty::Array(element_type, cst) = cx.tables.expr_ty(expr).kind; diff --git a/clippy_lints/src/len_zero.rs b/clippy_lints/src/len_zero.rs index e403b7af82a7..c17e43ea8ccd 100644 --- a/clippy_lints/src/len_zero.rs +++ b/clippy_lints/src/len_zero.rs @@ -84,7 +84,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LenZero { } } - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { + fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { if expr.span.from_expansion() { return; } @@ -207,7 +207,7 @@ fn check_impl_items(cx: &LateContext<'_, '_>, item: &Item<'_>, impl_items: &[Imp } } -fn check_cmp(cx: &LateContext<'_, '_>, span: Span, method: &Expr, lit: &Expr, op: &str, compare_to: u32) { +fn check_cmp(cx: &LateContext<'_, '_>, span: Span, method: &Expr<'_>, lit: &Expr<'_>, op: &str, compare_to: u32) { if let (&ExprKind::MethodCall(ref method_path, _, ref args), &ExprKind::Lit(ref lit)) = (&method.kind, &lit.kind) { // check if we are in an is_empty() method if let Some(name) = get_item_name(cx, method) { @@ -224,7 +224,7 @@ fn check_len( cx: &LateContext<'_, '_>, span: Span, method_name: Name, - args: &[Expr], + args: &[Expr<'_>], lit: &LitKind, op: &str, compare_to: u32, @@ -255,7 +255,7 @@ fn check_len( } /// Checks if this type has an `is_empty` method. -fn has_is_empty(cx: &LateContext<'_, '_>, expr: &Expr) -> bool { +fn has_is_empty(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool { /// Gets an `AssocItem` and return true if it matches `is_empty(self)`. fn is_is_empty(cx: &LateContext<'_, '_>, item: &ty::AssocItem) -> bool { if let ty::AssocKind::Method = item.kind { diff --git a/clippy_lints/src/let_if_seq.rs b/clippy_lints/src/let_if_seq.rs index 264982d5e5af..4ac88d573f3f 100644 --- a/clippy_lints/src/let_if_seq.rs +++ b/clippy_lints/src/let_if_seq.rs @@ -56,7 +56,7 @@ declare_clippy_lint! { declare_lint_pass!(LetIfSeq => [USELESS_LET_IF_SEQ]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetIfSeq { - fn check_block(&mut self, cx: &LateContext<'a, 'tcx>, block: &'tcx hir::Block) { + fn check_block(&mut self, cx: &LateContext<'a, 'tcx>, block: &'tcx hir::Block<'_>) { let mut it = block.stmts.iter().peekable(); while let Some(stmt) = it.next() { if_chain! { @@ -143,7 +143,7 @@ struct UsedVisitor<'a, 'tcx> { } impl<'a, 'tcx> hir::intravisit::Visitor<'tcx> for UsedVisitor<'a, 'tcx> { - fn visit_expr(&mut self, expr: &'tcx hir::Expr) { + fn visit_expr(&mut self, expr: &'tcx hir::Expr<'_>) { if_chain! { if let hir::ExprKind::Path(ref qpath) = expr.kind; if let Res::Local(local_id) = qpath_res(self.cx, qpath, expr.hir_id); @@ -163,8 +163,8 @@ impl<'a, 'tcx> hir::intravisit::Visitor<'tcx> for UsedVisitor<'a, 'tcx> { fn check_assign<'a, 'tcx>( cx: &LateContext<'a, 'tcx>, decl: hir::HirId, - block: &'tcx hir::Block, -) -> Option<&'tcx hir::Expr> { + block: &'tcx hir::Block<'_>, +) -> Option<&'tcx hir::Expr<'tcx>> { if_chain! { if block.expr.is_none(); if let Some(expr) = block.stmts.iter().last(); @@ -195,7 +195,7 @@ fn check_assign<'a, 'tcx>( None } -fn used_in_expr<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, id: hir::HirId, expr: &'tcx hir::Expr) -> bool { +fn used_in_expr<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, id: hir::HirId, expr: &'tcx hir::Expr<'_>) -> bool { let mut v = UsedVisitor { cx, id, used: false }; hir::intravisit::walk_expr(&mut v, expr); v.used diff --git a/clippy_lints/src/let_underscore.rs b/clippy_lints/src/let_underscore.rs index 2b59b7c6b4aa..4933b3049c28 100644 --- a/clippy_lints/src/let_underscore.rs +++ b/clippy_lints/src/let_underscore.rs @@ -33,7 +33,7 @@ declare_clippy_lint! { declare_lint_pass!(LetUnderscore => [LET_UNDERSCORE_MUST_USE]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetUnderscore { - fn check_stmt(&mut self, cx: &LateContext<'_, '_>, stmt: &Stmt) { + fn check_stmt(&mut self, cx: &LateContext<'_, '_>, stmt: &Stmt<'_>) { if_chain! { if let StmtKind::Local(ref local) = stmt.kind; if let PatKind::Wild = local.pat.kind; diff --git a/clippy_lints/src/loops.rs b/clippy_lints/src/loops.rs index 1127edd0896e..7fb924ee75f6 100644 --- a/clippy_lints/src/loops.rs +++ b/clippy_lints/src/loops.rs @@ -475,7 +475,7 @@ declare_lint_pass!(Loops => [ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Loops { #[allow(clippy::too_many_lines)] - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { + fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { if let Some((pat, arg, body)) = higher::for_loop(expr) { // we don't want to check expanded macros // this check is not at the top of the function @@ -651,14 +651,14 @@ fn combine_branches(b1: NeverLoopResult, b2: NeverLoopResult) -> NeverLoopResult } } -fn never_loop_block(block: &Block, main_loop_id: HirId) -> NeverLoopResult { +fn never_loop_block(block: &Block<'_>, main_loop_id: HirId) -> NeverLoopResult { let stmts = block.stmts.iter().map(stmt_to_expr); let expr = once(block.expr.as_ref().map(|p| &**p)); let mut iter = stmts.chain(expr).filter_map(|e| e); never_loop_expr_seq(&mut iter, main_loop_id) } -fn stmt_to_expr(stmt: &Stmt) -> Option<&Expr> { +fn stmt_to_expr<'tcx>(stmt: &Stmt<'tcx>) -> Option<&'tcx Expr<'tcx>> { match stmt.kind { StmtKind::Semi(ref e, ..) | StmtKind::Expr(ref e, ..) => Some(e), StmtKind::Local(ref local) => local.init.as_ref().map(|p| &**p), @@ -666,7 +666,7 @@ fn stmt_to_expr(stmt: &Stmt) -> Option<&Expr> { } } -fn never_loop_expr(expr: &Expr, main_loop_id: HirId) -> NeverLoopResult { +fn never_loop_expr(expr: &Expr<'_>, main_loop_id: HirId) -> NeverLoopResult { match expr.kind { ExprKind::Box(ref e) | ExprKind::Unary(_, ref e) @@ -726,27 +726,27 @@ fn never_loop_expr(expr: &Expr, main_loop_id: HirId) -> NeverLoopResult { } } -fn never_loop_expr_seq<'a, T: Iterator>(es: &mut T, main_loop_id: HirId) -> NeverLoopResult { +fn never_loop_expr_seq<'a, T: Iterator>>(es: &mut T, main_loop_id: HirId) -> NeverLoopResult { es.map(|e| never_loop_expr(e, main_loop_id)) .fold(NeverLoopResult::Otherwise, combine_seq) } -fn never_loop_expr_all<'a, T: Iterator>(es: &mut T, main_loop_id: HirId) -> NeverLoopResult { +fn never_loop_expr_all<'a, T: Iterator>>(es: &mut T, main_loop_id: HirId) -> NeverLoopResult { es.map(|e| never_loop_expr(e, main_loop_id)) .fold(NeverLoopResult::Otherwise, combine_both) } -fn never_loop_expr_branch<'a, T: Iterator>(e: &mut T, main_loop_id: HirId) -> NeverLoopResult { +fn never_loop_expr_branch<'a, T: Iterator>>(e: &mut T, main_loop_id: HirId) -> NeverLoopResult { e.map(|e| never_loop_expr(e, main_loop_id)) .fold(NeverLoopResult::AlwaysBreak, combine_branches) } fn check_for_loop<'a, 'tcx>( cx: &LateContext<'a, 'tcx>, - pat: &'tcx Pat, - arg: &'tcx Expr, - body: &'tcx Expr, - expr: &'tcx Expr, + pat: &'tcx Pat<'_>, + arg: &'tcx Expr<'_>, + body: &'tcx Expr<'_>, + expr: &'tcx Expr<'_>, ) { check_for_loop_range(cx, pat, arg, body, expr); check_for_loop_reverse_range(cx, arg, expr); @@ -757,7 +757,7 @@ fn check_for_loop<'a, 'tcx>( detect_manual_memcpy(cx, pat, arg, body, expr); } -fn same_var<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &Expr, var: HirId) -> bool { +fn same_var<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &Expr<'_>, var: HirId) -> bool { if_chain! { if let ExprKind::Path(ref qpath) = expr.kind; if let QPath::Resolved(None, ref path) = *qpath; @@ -806,8 +806,8 @@ fn is_slice_like<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty<'_>) -> bool { is_slice || is_type_diagnostic_item(cx, ty, Symbol::intern("vec_type")) || match_type(cx, ty, &paths::VEC_DEQUE) } -fn get_fixed_offset_var<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &Expr, var: HirId) -> Option { - fn extract_offset<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, e: &Expr, var: HirId) -> Option { +fn get_fixed_offset_var<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &Expr<'_>, var: HirId) -> Option { + fn extract_offset<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, e: &Expr<'_>, var: HirId) -> Option { match e.kind { ExprKind::Lit(ref l) => match l.node { ast::LitKind::Int(x, _ty) => Some(x.to_string()), @@ -861,7 +861,7 @@ fn get_fixed_offset_var<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &Expr, var: fn fetch_cloned_fixed_offset_var<'a, 'tcx>( cx: &LateContext<'a, 'tcx>, - expr: &Expr, + expr: &Expr<'_>, var: HirId, ) -> Option { if_chain! { @@ -879,12 +879,12 @@ fn fetch_cloned_fixed_offset_var<'a, 'tcx>( fn get_indexed_assignments<'a, 'tcx>( cx: &LateContext<'a, 'tcx>, - body: &Expr, + body: &Expr<'_>, var: HirId, ) -> Vec<(FixedOffsetVar, FixedOffsetVar)> { fn get_assignment<'a, 'tcx>( cx: &LateContext<'a, 'tcx>, - e: &Expr, + e: &Expr<'_>, var: HirId, ) -> Option<(FixedOffsetVar, FixedOffsetVar)> { if let ExprKind::Assign(ref lhs, ref rhs, _) = e.kind { @@ -931,10 +931,10 @@ fn get_indexed_assignments<'a, 'tcx>( /// object to another. fn detect_manual_memcpy<'a, 'tcx>( cx: &LateContext<'a, 'tcx>, - pat: &'tcx Pat, - arg: &'tcx Expr, - body: &'tcx Expr, - expr: &'tcx Expr, + pat: &'tcx Pat<'_>, + arg: &'tcx Expr<'_>, + body: &'tcx Expr<'_>, + expr: &'tcx Expr<'_>, ) { if let Some(higher::Range { start: Some(start), @@ -968,7 +968,7 @@ fn detect_manual_memcpy<'a, 'tcx>( } }; - let print_limit = |end: &Option<&Expr>, offset: Offset, var_name: &str| { + let print_limit = |end: &Option<&Expr<'_>>, offset: Offset, var_name: &str| { if let Some(end) = *end { if_chain! { if let ExprKind::MethodCall(ref method, _, ref len_args) = end.kind; @@ -1044,10 +1044,10 @@ fn detect_manual_memcpy<'a, 'tcx>( #[allow(clippy::too_many_lines)] fn check_for_loop_range<'a, 'tcx>( cx: &LateContext<'a, 'tcx>, - pat: &'tcx Pat, - arg: &'tcx Expr, - body: &'tcx Expr, - expr: &'tcx Expr, + pat: &'tcx Pat<'_>, + arg: &'tcx Expr<'_>, + body: &'tcx Expr<'_>, + expr: &'tcx Expr<'_>, ) { if let Some(higher::Range { start: Some(start), @@ -1206,7 +1206,7 @@ fn check_for_loop_range<'a, 'tcx>( } } -fn is_len_call(expr: &Expr, var: Name) -> bool { +fn is_len_call(expr: &Expr<'_>, var: Name) -> bool { if_chain! { if let ExprKind::MethodCall(ref method, _, ref len_args) = expr.kind; if len_args.len() == 1; @@ -1224,7 +1224,7 @@ fn is_len_call(expr: &Expr, var: Name) -> bool { fn is_end_eq_array_len<'tcx>( cx: &LateContext<'_, 'tcx>, - end: &Expr, + end: &Expr<'_>, limits: ast::RangeLimits, indexed_ty: Ty<'tcx>, ) -> bool { @@ -1244,7 +1244,7 @@ fn is_end_eq_array_len<'tcx>( false } -fn check_for_loop_reverse_range<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, arg: &'tcx Expr, expr: &'tcx Expr) { +fn check_for_loop_reverse_range<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, arg: &'tcx Expr<'_>, expr: &'tcx Expr<'_>) { // if this for loop is iterating over a two-sided range... if let Some(higher::Range { start: Some(start), @@ -1316,7 +1316,7 @@ fn check_for_loop_reverse_range<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, arg: &'tcx } } -fn lint_iter_method(cx: &LateContext<'_, '_>, args: &[Expr], arg: &Expr, method_name: &str) { +fn lint_iter_method(cx: &LateContext<'_, '_>, args: &[Expr<'_>], arg: &Expr<'_>, method_name: &str) { let mut applicability = Applicability::MachineApplicable; let object = snippet_with_applicability(cx, args[0].span, "_", &mut applicability); let muta = if method_name == "iter_mut" { "mut " } else { "" }; @@ -1332,7 +1332,7 @@ fn lint_iter_method(cx: &LateContext<'_, '_>, args: &[Expr], arg: &Expr, method_ ) } -fn check_for_loop_arg(cx: &LateContext<'_, '_>, pat: &Pat, arg: &Expr, expr: &Expr) { +fn check_for_loop_arg(cx: &LateContext<'_, '_>, pat: &Pat<'_>, arg: &Expr<'_>, expr: &Expr<'_>) { let mut next_loop_linted = false; // whether or not ITER_NEXT_LOOP lint was used if let ExprKind::MethodCall(ref method, _, ref args) = arg.kind { // just the receiver, no arguments @@ -1389,7 +1389,7 @@ fn check_for_loop_arg(cx: &LateContext<'_, '_>, pat: &Pat, arg: &Expr, expr: &Ex } /// Checks for `for` loops over `Option`s and `Result`s. -fn check_arg_type(cx: &LateContext<'_, '_>, pat: &Pat, arg: &Expr) { +fn check_arg_type(cx: &LateContext<'_, '_>, pat: &Pat<'_>, arg: &Expr<'_>) { let ty = cx.tables.expr_ty(arg); if match_type(cx, ty, &paths::OPTION) { span_help_and_lint( @@ -1428,10 +1428,10 @@ fn check_arg_type(cx: &LateContext<'_, '_>, pat: &Pat, arg: &Expr) { fn check_for_loop_explicit_counter<'a, 'tcx>( cx: &LateContext<'a, 'tcx>, - pat: &'tcx Pat, - arg: &'tcx Expr, - body: &'tcx Expr, - expr: &'tcx Expr, + pat: &'tcx Pat<'_>, + arg: &'tcx Expr<'_>, + body: &'tcx Expr<'_>, + expr: &'tcx Expr<'_>, ) { // Look for variables that are incremented once per loop iteration. let mut visitor = IncrementVisitor { @@ -1491,7 +1491,7 @@ fn check_for_loop_explicit_counter<'a, 'tcx>( /// If `arg` was the argument to a `for` loop, return the "cleanest" way of writing the /// actual `Iterator` that the loop uses. -fn make_iterator_snippet(cx: &LateContext<'_, '_>, arg: &Expr, applic_ref: &mut Applicability) -> String { +fn make_iterator_snippet(cx: &LateContext<'_, '_>, arg: &Expr<'_>, applic_ref: &mut Applicability) -> String { let impls_iterator = get_trait_def_id(cx, &paths::ITERATOR) .map_or(false, |id| implements_trait(cx, cx.tables.expr_ty(arg), id, &[])); if impls_iterator { @@ -1527,10 +1527,10 @@ fn make_iterator_snippet(cx: &LateContext<'_, '_>, arg: &Expr, applic_ref: &mut /// Checks for the `FOR_KV_MAP` lint. fn check_for_loop_over_map_kv<'a, 'tcx>( cx: &LateContext<'a, 'tcx>, - pat: &'tcx Pat, - arg: &'tcx Expr, - body: &'tcx Expr, - expr: &'tcx Expr, + pat: &'tcx Pat<'_>, + arg: &'tcx Expr<'_>, + body: &'tcx Expr<'_>, + expr: &'tcx Expr<'_>, ) { let pat_span = pat.span; @@ -1618,7 +1618,7 @@ impl<'tcx> MutatePairDelegate { } } -fn check_for_mut_range_bound(cx: &LateContext<'_, '_>, arg: &Expr, body: &Expr) { +fn check_for_mut_range_bound(cx: &LateContext<'_, '_>, arg: &Expr<'_>, body: &Expr<'_>) { if let Some(higher::Range { start: Some(start), end: Some(end), @@ -1645,7 +1645,7 @@ fn mut_warn_with_span(cx: &LateContext<'_, '_>, span: Option) { } } -fn check_for_mutability(cx: &LateContext<'_, '_>, bound: &Expr) -> Option { +fn check_for_mutability(cx: &LateContext<'_, '_>, bound: &Expr<'_>) -> Option { if_chain! { if let ExprKind::Path(ref qpath) = bound.kind; if let QPath::Resolved(None, _) = *qpath; @@ -1669,7 +1669,7 @@ fn check_for_mutability(cx: &LateContext<'_, '_>, bound: &Expr) -> Option fn check_for_mutation( cx: &LateContext<'_, '_>, - body: &Expr, + body: &Expr<'_>, bound_ids: &[Option], ) -> (Option, Option) { let mut delegate = MutatePairDelegate { @@ -1686,7 +1686,7 @@ fn check_for_mutation( } /// Returns `true` if the pattern is a `PatWild` or an ident prefixed with `_`. -fn pat_is_wild<'tcx>(pat: &'tcx PatKind, body: &'tcx Expr) -> bool { +fn pat_is_wild<'tcx>(pat: &'tcx PatKind<'_>, body: &'tcx Expr<'_>) -> bool { match *pat { PatKind::Wild => true, PatKind::Binding(.., ident, None) if ident.as_str().starts_with('_') => { @@ -1707,7 +1707,7 @@ struct UsedVisitor { } impl<'tcx> Visitor<'tcx> for UsedVisitor { - fn visit_expr(&mut self, expr: &'tcx Expr) { + fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { if match_var(expr, self.var) { self.used = true; } else { @@ -1727,7 +1727,7 @@ struct LocalUsedVisitor<'a, 'tcx> { } impl<'a, 'tcx> Visitor<'tcx> for LocalUsedVisitor<'a, 'tcx> { - fn visit_expr(&mut self, expr: &'tcx Expr) { + fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { if same_var(self.cx, expr, self.local) { self.used = true; } else { @@ -1764,7 +1764,7 @@ struct VarVisitor<'a, 'tcx> { } impl<'a, 'tcx> VarVisitor<'a, 'tcx> { - fn check(&mut self, idx: &'tcx Expr, seqexpr: &'tcx Expr, expr: &'tcx Expr) -> bool { + fn check(&mut self, idx: &'tcx Expr<'_>, seqexpr: &'tcx Expr<'_>, expr: &'tcx Expr<'_>) -> bool { if_chain! { // the indexed container is referenced by a name if let ExprKind::Path(ref seqpath) = seqexpr.kind; @@ -1825,7 +1825,7 @@ impl<'a, 'tcx> VarVisitor<'a, 'tcx> { } impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> { - fn visit_expr(&mut self, expr: &'tcx Expr) { + fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { if_chain! { // a range index op if let ExprKind::MethodCall(ref meth, _, ref args) = expr.kind; @@ -1873,7 +1873,7 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> { } self.visit_expr(expr); }, - ExprKind::Call(ref f, ref args) => { + ExprKind::Call(ref f, args) => { self.visit_expr(f); for expr in args { let ty = self.cx.tables.expr_ty_adjusted(expr); @@ -1886,7 +1886,7 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> { self.visit_expr(expr); } }, - ExprKind::MethodCall(_, _, ref args) => { + ExprKind::MethodCall(_, _, args) => { let def_id = self.cx.tables.type_dependent_def_id(expr.hir_id).unwrap(); for (ty, expr) in self.cx.tcx.fn_sig(def_id).inputs().skip_binder().iter().zip(args) { self.prefer_mutable = false; @@ -1911,7 +1911,7 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> { } } -fn is_used_inside<'a, 'tcx>(cx: &'a LateContext<'a, 'tcx>, expr: &'tcx Expr, container: &'tcx Expr) -> bool { +fn is_used_inside<'a, 'tcx>(cx: &'a LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>, container: &'tcx Expr<'_>) -> bool { let def_id = match var_def_id(cx, expr) { Some(id) => id, None => return false, @@ -1924,7 +1924,7 @@ fn is_used_inside<'a, 'tcx>(cx: &'a LateContext<'a, 'tcx>, expr: &'tcx Expr, con false } -fn is_iterator_used_after_while_let<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, iter_expr: &'tcx Expr) -> bool { +fn is_iterator_used_after_while_let<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, iter_expr: &'tcx Expr<'_>) -> bool { let def_id = match var_def_id(cx, iter_expr) { Some(id) => id, None => return false, @@ -1951,7 +1951,7 @@ struct VarUsedAfterLoopVisitor<'a, 'tcx> { } impl<'a, 'tcx> Visitor<'tcx> for VarUsedAfterLoopVisitor<'a, 'tcx> { - fn visit_expr(&mut self, expr: &'tcx Expr) { + fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { if self.past_while_let { if Some(self.def_id) == var_def_id(self.cx, expr) { self.var_used_after_while_let = true; @@ -1969,7 +1969,7 @@ impl<'a, 'tcx> Visitor<'tcx> for VarUsedAfterLoopVisitor<'a, 'tcx> { /// Returns `true` if the type of expr is one that provides `IntoIterator` impls /// for `&T` and `&mut T`, such as `Vec`. #[rustfmt::skip] -fn is_ref_iterable_type(cx: &LateContext<'_, '_>, e: &Expr) -> bool { +fn is_ref_iterable_type(cx: &LateContext<'_, '_>, e: &Expr<'_>) -> bool { // no walk_ptrs_ty: calling iter() on a reference can make sense because it // will allow further borrows afterwards let ty = cx.tables.expr_ty(e); @@ -2000,12 +2000,12 @@ fn is_iterable_array<'tcx>(ty: Ty<'tcx>, cx: &LateContext<'_, 'tcx>) -> bool { /// If a block begins with a statement (possibly a `let` binding) and has an /// expression, return it. -fn extract_expr_from_first_stmt(block: &Block) -> Option<&Expr> { +fn extract_expr_from_first_stmt<'tcx>(block: &Block<'tcx>) -> Option<&'tcx Expr<'tcx>> { if block.stmts.is_empty() { return None; } if let StmtKind::Local(ref local) = block.stmts[0].kind { - if let Some(ref expr) = local.init { + if let Some(expr) = local.init { Some(expr) } else { None @@ -2016,7 +2016,7 @@ fn extract_expr_from_first_stmt(block: &Block) -> Option<&Expr> { } /// If a block begins with an expression (with or without semicolon), return it. -fn extract_first_expr(block: &Block) -> Option<&Expr> { +fn extract_first_expr<'tcx>(block: &Block<'tcx>) -> Option<&'tcx Expr<'tcx>> { match block.expr { Some(ref expr) if block.stmts.is_empty() => Some(expr), None if !block.stmts.is_empty() => match block.stmts[0].kind { @@ -2030,7 +2030,7 @@ fn extract_first_expr(block: &Block) -> Option<&Expr> { /// Returns `true` if expr contains a single break expr without destination label /// and /// passed expression. The expression may be within a block. -fn is_simple_break_expr(expr: &Expr) -> bool { +fn is_simple_break_expr(expr: &Expr<'_>) -> bool { match expr.kind { ExprKind::Break(dest, ref passed_expr) if dest.label.is_none() && passed_expr.is_none() => true, ExprKind::Block(ref b, _) => extract_first_expr(b).map_or(false, |subexpr| is_simple_break_expr(subexpr)), @@ -2059,7 +2059,7 @@ struct IncrementVisitor<'a, 'tcx> { } impl<'a, 'tcx> Visitor<'tcx> for IncrementVisitor<'a, 'tcx> { - fn visit_expr(&mut self, expr: &'tcx Expr) { + fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { if self.done { return; } @@ -2109,7 +2109,7 @@ impl<'a, 'tcx> Visitor<'tcx> for IncrementVisitor<'a, 'tcx> { /// Checks whether a variable is initialized to zero at the start of a loop. struct InitializeVisitor<'a, 'tcx> { cx: &'a LateContext<'a, 'tcx>, // context reference - end_expr: &'tcx Expr, // the for loop. Stop scanning here. + end_expr: &'tcx Expr<'tcx>, // the for loop. Stop scanning here. var_id: HirId, state: VarState, name: Option, @@ -2118,7 +2118,7 @@ struct InitializeVisitor<'a, 'tcx> { } impl<'a, 'tcx> Visitor<'tcx> for InitializeVisitor<'a, 'tcx> { - fn visit_stmt(&mut self, stmt: &'tcx Stmt) { + fn visit_stmt(&mut self, stmt: &'tcx Stmt<'_>) { // Look for declarations of the variable if let StmtKind::Local(ref local) = stmt.kind { if local.pat.hir_id == self.var_id { @@ -2140,7 +2140,7 @@ impl<'a, 'tcx> Visitor<'tcx> for InitializeVisitor<'a, 'tcx> { walk_stmt(self, stmt); } - fn visit_expr(&mut self, expr: &'tcx Expr) { + fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { if self.state == VarState::DontWarn { return; } @@ -2196,7 +2196,7 @@ impl<'a, 'tcx> Visitor<'tcx> for InitializeVisitor<'a, 'tcx> { } } -fn var_def_id(cx: &LateContext<'_, '_>, expr: &Expr) -> Option { +fn var_def_id(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> Option { if let ExprKind::Path(ref qpath) = expr.kind { let path_res = qpath_res(cx, qpath, expr.hir_id); if let Res::Local(node_id) = path_res { @@ -2206,21 +2206,21 @@ fn var_def_id(cx: &LateContext<'_, '_>, expr: &Expr) -> Option { None } -fn is_loop(expr: &Expr) -> bool { +fn is_loop(expr: &Expr<'_>) -> bool { match expr.kind { ExprKind::Loop(..) => true, _ => false, } } -fn is_conditional(expr: &Expr) -> bool { +fn is_conditional(expr: &Expr<'_>) -> bool { match expr.kind { ExprKind::Match(..) => true, _ => false, } } -fn is_nested(cx: &LateContext<'_, '_>, match_expr: &Expr, iter_expr: &Expr) -> bool { +fn is_nested(cx: &LateContext<'_, '_>, match_expr: &Expr<'_>, iter_expr: &Expr<'_>) -> bool { if_chain! { if let Some(loop_block) = get_enclosing_block(cx, match_expr.hir_id); let parent_node = cx.tcx.hir().get_parent_node(loop_block.hir_id); @@ -2232,7 +2232,7 @@ fn is_nested(cx: &LateContext<'_, '_>, match_expr: &Expr, iter_expr: &Expr) -> b false } -fn is_loop_nested(cx: &LateContext<'_, '_>, loop_expr: &Expr, iter_expr: &Expr) -> bool { +fn is_loop_nested(cx: &LateContext<'_, '_>, loop_expr: &Expr<'_>, iter_expr: &Expr<'_>) -> bool { let mut id = loop_expr.hir_id; let iter_name = if let Some(name) = path_name(iter_expr) { name @@ -2286,7 +2286,7 @@ struct LoopNestVisitor { } impl<'tcx> Visitor<'tcx> for LoopNestVisitor { - fn visit_stmt(&mut self, stmt: &'tcx Stmt) { + fn visit_stmt(&mut self, stmt: &'tcx Stmt<'_>) { if stmt.hir_id == self.hir_id { self.nesting = LookFurther; } else if self.nesting == Unknown { @@ -2294,7 +2294,7 @@ impl<'tcx> Visitor<'tcx> for LoopNestVisitor { } } - fn visit_expr(&mut self, expr: &'tcx Expr) { + fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { if self.nesting != Unknown { return; } @@ -2312,7 +2312,7 @@ impl<'tcx> Visitor<'tcx> for LoopNestVisitor { } } - fn visit_pat(&mut self, pat: &'tcx Pat) { + fn visit_pat(&mut self, pat: &'tcx Pat<'_>) { if self.nesting != Unknown { return; } @@ -2330,7 +2330,7 @@ impl<'tcx> Visitor<'tcx> for LoopNestVisitor { } } -fn path_name(e: &Expr) -> Option { +fn path_name(e: &Expr<'_>) -> Option { if let ExprKind::Path(QPath::Resolved(_, ref path)) = e.kind { let segments = &path.segments; if segments.len() == 1 { @@ -2340,7 +2340,7 @@ fn path_name(e: &Expr) -> Option { None } -fn check_infinite_loop<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, cond: &'tcx Expr, expr: &'tcx Expr) { +fn check_infinite_loop<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, cond: &'tcx Expr<'_>, expr: &'tcx Expr<'_>) { if constant(cx, cx.tables, cond).is_some() { // A pure constant condition (e.g., `while false`) is not linted. return; @@ -2393,7 +2393,7 @@ struct HasBreakOrReturnVisitor { } impl<'a, 'tcx> Visitor<'tcx> for HasBreakOrReturnVisitor { - fn visit_expr(&mut self, expr: &'tcx Expr) { + fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { if self.has_break_or_return { return; } @@ -2426,7 +2426,7 @@ struct VarCollectorVisitor<'a, 'tcx> { } impl<'a, 'tcx> VarCollectorVisitor<'a, 'tcx> { - fn insert_def_id(&mut self, ex: &'tcx Expr) { + fn insert_def_id(&mut self, ex: &'tcx Expr<'_>) { if_chain! { if let ExprKind::Path(ref qpath) = ex.kind; if let QPath::Resolved(None, _) = *qpath; @@ -2448,7 +2448,7 @@ impl<'a, 'tcx> VarCollectorVisitor<'a, 'tcx> { } impl<'a, 'tcx> Visitor<'tcx> for VarCollectorVisitor<'a, 'tcx> { - fn visit_expr(&mut self, ex: &'tcx Expr) { + fn visit_expr(&mut self, ex: &'tcx Expr<'_>) { match ex.kind { ExprKind::Path(_) => self.insert_def_id(ex), // If there is any function/method call… we just stop analysis @@ -2465,7 +2465,7 @@ impl<'a, 'tcx> Visitor<'tcx> for VarCollectorVisitor<'a, 'tcx> { const NEEDLESS_COLLECT_MSG: &str = "avoid using `collect()` when not needed"; -fn check_needless_collect<'a, 'tcx>(expr: &'tcx Expr, cx: &LateContext<'a, 'tcx>) { +fn check_needless_collect<'a, 'tcx>(expr: &'tcx Expr<'_>, cx: &LateContext<'a, 'tcx>) { if_chain! { if let ExprKind::MethodCall(ref method, _, ref args) = expr.kind; if let ExprKind::MethodCall(ref chain_method, _, _) = args[0].kind; @@ -2525,7 +2525,7 @@ fn check_needless_collect<'a, 'tcx>(expr: &'tcx Expr, cx: &LateContext<'a, 'tcx> } } -fn shorten_needless_collect_span(expr: &Expr) -> Span { +fn shorten_needless_collect_span(expr: &Expr<'_>) -> Span { if_chain! { if let ExprKind::MethodCall(_, _, ref args) = expr.kind; if let ExprKind::MethodCall(_, ref span, _) = args[0].kind; diff --git a/clippy_lints/src/main_recursion.rs b/clippy_lints/src/main_recursion.rs index 54840702cb07..affa20c885f5 100644 --- a/clippy_lints/src/main_recursion.rs +++ b/clippy_lints/src/main_recursion.rs @@ -45,7 +45,7 @@ impl LateLintPass<'_, '_> for MainRecursion { }); } - fn check_expr_post(&mut self, cx: &LateContext<'_, '_>, expr: &Expr) { + fn check_expr_post(&mut self, cx: &LateContext<'_, '_>, expr: &Expr<'_>) { if self.has_no_std_attr { return; } diff --git a/clippy_lints/src/map_clone.rs b/clippy_lints/src/map_clone.rs index 7931fabf8d71..755794a5f112 100644 --- a/clippy_lints/src/map_clone.rs +++ b/clippy_lints/src/map_clone.rs @@ -43,7 +43,7 @@ declare_clippy_lint! { declare_lint_pass!(MapClone => [MAP_CLONE]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MapClone { - fn check_expr(&mut self, cx: &LateContext<'_, '_>, e: &hir::Expr) { + fn check_expr(&mut self, cx: &LateContext<'_, '_>, e: &hir::Expr<'_>) { if e.span.from_expansion() { return; } @@ -98,7 +98,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MapClone { } } -fn ident_eq(name: Ident, path: &hir::Expr) -> bool { +fn ident_eq(name: Ident, path: &hir::Expr<'_>) -> bool { if let hir::ExprKind::Path(hir::QPath::Resolved(None, ref path)) = path.kind { path.segments.len() == 1 && path.segments[0].ident == name } else { diff --git a/clippy_lints/src/map_unit_fn.rs b/clippy_lints/src/map_unit_fn.rs index 83dd1180e762..bedce8d9c893 100644 --- a/clippy_lints/src/map_unit_fn.rs +++ b/clippy_lints/src/map_unit_fn.rs @@ -102,7 +102,7 @@ fn is_unit_type(ty: Ty<'_>) -> bool { } } -fn is_unit_function(cx: &LateContext<'_, '_>, expr: &hir::Expr) -> bool { +fn is_unit_function(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>) -> bool { let ty = cx.tables.expr_ty(expr); if let ty::FnDef(id, _) = ty.kind { @@ -113,7 +113,7 @@ fn is_unit_function(cx: &LateContext<'_, '_>, expr: &hir::Expr) -> bool { false } -fn is_unit_expression(cx: &LateContext<'_, '_>, expr: &hir::Expr) -> bool { +fn is_unit_expression(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>) -> bool { is_unit_type(cx.tables.expr_ty(expr)) } @@ -121,7 +121,7 @@ fn is_unit_expression(cx: &LateContext<'_, '_>, expr: &hir::Expr) -> bool { /// semicolons, which causes problems when generating a suggestion. Given an /// expression that evaluates to '()' or '!', recursively remove useless braces /// and semi-colons until is suitable for including in the suggestion template -fn reduce_unit_expression<'a>(cx: &LateContext<'_, '_>, expr: &'a hir::Expr) -> Option { +fn reduce_unit_expression<'a>(cx: &LateContext<'_, '_>, expr: &'a hir::Expr<'_>) -> Option { if !is_unit_expression(cx, expr) { return None; } @@ -164,8 +164,8 @@ fn reduce_unit_expression<'a>(cx: &LateContext<'_, '_>, expr: &'a hir::Expr) -> fn unit_closure<'a, 'tcx>( cx: &LateContext<'a, 'tcx>, - expr: &'a hir::Expr, -) -> Option<(&'tcx hir::Param, &'a hir::Expr)> { + expr: &'a hir::Expr<'a>, +) -> Option<(&'tcx hir::Param<'tcx>, &'a hir::Expr<'a>)> { if let hir::ExprKind::Closure(_, ref decl, inner_expr_id, _, _) = expr.kind { let body = cx.tcx.hir().body(inner_expr_id); let body_expr = &body.value; @@ -188,7 +188,7 @@ fn unit_closure<'a, 'tcx>( /// `y` => `_y` /// /// Anything else will return `_`. -fn let_binding_name(cx: &LateContext<'_, '_>, var_arg: &hir::Expr) -> String { +fn let_binding_name(cx: &LateContext<'_, '_>, var_arg: &hir::Expr<'_>) -> String { match &var_arg.kind { hir::ExprKind::Field(_, _) => snippet(cx, var_arg.span, "_").replace(".", "_"), hir::ExprKind::Path(_) => format!("_{}", snippet(cx, var_arg.span, "")), @@ -204,7 +204,7 @@ fn suggestion_msg(function_type: &str, map_type: &str) -> String { ) } -fn lint_map_unit_fn(cx: &LateContext<'_, '_>, stmt: &hir::Stmt, expr: &hir::Expr, map_args: &[hir::Expr]) { +fn lint_map_unit_fn(cx: &LateContext<'_, '_>, stmt: &hir::Stmt<'_>, expr: &hir::Expr<'_>, map_args: &[hir::Expr<'_>]) { let var_arg = &map_args[0]; let (map_type, variant, lint) = if match_type(cx, cx.tables.expr_ty(var_arg), &paths::OPTION) { @@ -261,7 +261,7 @@ fn lint_map_unit_fn(cx: &LateContext<'_, '_>, stmt: &hir::Stmt, expr: &hir::Expr } impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MapUnit { - fn check_stmt(&mut self, cx: &LateContext<'_, '_>, stmt: &hir::Stmt) { + fn check_stmt(&mut self, cx: &LateContext<'_, '_>, stmt: &hir::Stmt<'_>) { if stmt.span.from_expansion() { return; } diff --git a/clippy_lints/src/matches.rs b/clippy_lints/src/matches.rs index fc265c5231bb..b0d38d179b5c 100644 --- a/clippy_lints/src/matches.rs +++ b/clippy_lints/src/matches.rs @@ -235,7 +235,7 @@ declare_lint_pass!(Matches => [ ]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Matches { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { + fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { if in_external_macro(cx.sess(), expr.span) { return; } @@ -254,7 +254,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Matches { } #[rustfmt::skip] -fn check_single_match(cx: &LateContext<'_, '_>, ex: &Expr, arms: &[Arm], expr: &Expr) { +fn check_single_match(cx: &LateContext<'_, '_>, ex: &Expr<'_>, arms: &[Arm<'_>], expr: &Expr<'_>) { if arms.len() == 2 && arms[0].guard.is_none() && arms[1].guard.is_none() { if let PatKind::Or(..) = arms[0].pat.kind { // don't lint for or patterns for now, this makes @@ -281,10 +281,10 @@ fn check_single_match(cx: &LateContext<'_, '_>, ex: &Expr, arms: &[Arm], expr: & fn check_single_match_single_pattern( cx: &LateContext<'_, '_>, - ex: &Expr, - arms: &[Arm], - expr: &Expr, - els: Option<&Expr>, + ex: &Expr<'_>, + arms: &[Arm<'_>], + expr: &Expr<'_>, + els: Option<&Expr<'_>>, ) { if is_wild(&arms[1].pat) { report_single_match_single_pattern(cx, ex, arms, expr, els); @@ -293,10 +293,10 @@ fn check_single_match_single_pattern( fn report_single_match_single_pattern( cx: &LateContext<'_, '_>, - ex: &Expr, - arms: &[Arm], - expr: &Expr, - els: Option<&Expr>, + ex: &Expr<'_>, + arms: &[Arm<'_>], + expr: &Expr<'_>, + els: Option<&Expr<'_>>, ) { let lint = if els.is_some() { SINGLE_MATCH_ELSE } else { SINGLE_MATCH }; let els_str = els.map_or(String::new(), |els| { @@ -322,11 +322,11 @@ fn report_single_match_single_pattern( fn check_single_match_opt_like( cx: &LateContext<'_, '_>, - ex: &Expr, - arms: &[Arm], - expr: &Expr, + ex: &Expr<'_>, + arms: &[Arm<'_>], + expr: &Expr<'_>, ty: Ty<'_>, - els: Option<&Expr>, + els: Option<&Expr<'_>>, ) { // list of candidate `Enum`s we know will never get any more members let candidates = &[ @@ -359,7 +359,7 @@ fn check_single_match_opt_like( } } -fn check_match_bool(cx: &LateContext<'_, '_>, ex: &Expr, arms: &[Arm], expr: &Expr) { +fn check_match_bool(cx: &LateContext<'_, '_>, ex: &Expr<'_>, arms: &[Arm<'_>], expr: &Expr<'_>) { // Type of expression is `bool`. if cx.tables.expr_ty(ex).kind == ty::Bool { span_lint_and_then( @@ -419,7 +419,7 @@ fn check_match_bool(cx: &LateContext<'_, '_>, ex: &Expr, arms: &[Arm], expr: &Ex } } -fn check_overlapping_arms<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ex: &'tcx Expr, arms: &'tcx [Arm]) { +fn check_overlapping_arms<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ex: &'tcx Expr<'_>, arms: &'tcx [Arm<'_>]) { if arms.len() >= 2 && cx.tables.expr_ty(ex).is_integral() { let ranges = all_ranges(cx, arms); let type_ranges = type_ranges(&ranges); @@ -438,14 +438,14 @@ fn check_overlapping_arms<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ex: &'tcx Expr, } } -fn is_wild(pat: &impl std::ops::Deref) -> bool { +fn is_wild<'tcx>(pat: &impl std::ops::Deref>) -> bool { match pat.kind { PatKind::Wild => true, _ => false, } } -fn check_wild_err_arm(cx: &LateContext<'_, '_>, ex: &Expr, arms: &[Arm]) { +fn check_wild_err_arm(cx: &LateContext<'_, '_>, ex: &Expr<'_>, arms: &[Arm<'_>]) { let ex_ty = walk_ptrs_ty(cx.tables.expr_ty(ex)); if match_type(cx, ex_ty, &paths::RESULT) { for arm in arms { @@ -472,7 +472,7 @@ fn check_wild_err_arm(cx: &LateContext<'_, '_>, ex: &Expr, arms: &[Arm]) { } } -fn check_wild_enum_match(cx: &LateContext<'_, '_>, ex: &Expr, arms: &[Arm]) { +fn check_wild_enum_match(cx: &LateContext<'_, '_>, ex: &Expr<'_>, arms: &[Arm<'_>]) { let ty = cx.tables.expr_ty(ex); if !ty.is_enum() { // If there isn't a nice closed set of possible values that can be conveniently enumerated, @@ -565,7 +565,7 @@ fn check_wild_enum_match(cx: &LateContext<'_, '_>, ex: &Expr, arms: &[Arm]) { } // If the block contains only a `panic!` macro (as expression or statement) -fn is_panic_block(block: &Block) -> bool { +fn is_panic_block(block: &Block<'_>) -> bool { match (&block.expr, block.stmts.len(), block.stmts.first()) { (&Some(ref exp), 0, _) => { is_expn_of(exp.span, "panic").is_some() && is_expn_of(exp.span, "unreachable").is_none() @@ -577,7 +577,7 @@ fn is_panic_block(block: &Block) -> bool { } } -fn check_match_ref_pats(cx: &LateContext<'_, '_>, ex: &Expr, arms: &[Arm], expr: &Expr) { +fn check_match_ref_pats(cx: &LateContext<'_, '_>, ex: &Expr<'_>, arms: &[Arm<'_>], expr: &Expr<'_>) { if has_only_ref_pats(arms) { let mut suggs = Vec::new(); let (title, msg) = if let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Not, ref inner) = ex.kind { @@ -612,7 +612,7 @@ fn check_match_ref_pats(cx: &LateContext<'_, '_>, ex: &Expr, arms: &[Arm], expr: } } -fn check_match_as_ref(cx: &LateContext<'_, '_>, ex: &Expr, arms: &[Arm], expr: &Expr) { +fn check_match_as_ref(cx: &LateContext<'_, '_>, ex: &Expr<'_>, arms: &[Arm<'_>], expr: &Expr<'_>) { if arms.len() == 2 && arms[0].guard.is_none() && arms[1].guard.is_none() { let arm_ref: Option = if is_none_arm(&arms[0]) { is_ref_some_arm(&arms[1]) @@ -665,7 +665,7 @@ fn check_match_as_ref(cx: &LateContext<'_, '_>, ex: &Expr, arms: &[Arm], expr: & } /// Gets all arms that are unbounded `PatRange`s. -fn all_ranges<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, arms: &'tcx [Arm]) -> Vec> { +fn all_ranges<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, arms: &'tcx [Arm<'_>]) -> Vec> { arms.iter() .flat_map(|arm| { if let Arm { @@ -730,7 +730,7 @@ fn type_ranges(ranges: &[SpannedRange]) -> TypedRanges { .collect() } -fn is_unit_expr(expr: &Expr) -> bool { +fn is_unit_expr(expr: &Expr<'_>) -> bool { match expr.kind { ExprKind::Tup(ref v) if v.is_empty() => true, ExprKind::Block(ref b, _) if b.stmts.is_empty() && b.expr.is_none() => true, @@ -739,7 +739,7 @@ fn is_unit_expr(expr: &Expr) -> bool { } // Checks if arm has the form `None => None` -fn is_none_arm(arm: &Arm) -> bool { +fn is_none_arm(arm: &Arm<'_>) -> bool { match arm.pat.kind { PatKind::Path(ref path) if match_qpath(path, &paths::OPTION_NONE) => true, _ => false, @@ -747,7 +747,7 @@ fn is_none_arm(arm: &Arm) -> bool { } // Checks if arm has the form `Some(ref v) => Some(v)` (checks for `ref` and `ref mut`) -fn is_ref_some_arm(arm: &Arm) -> Option { +fn is_ref_some_arm(arm: &Arm<'_>) -> Option { if_chain! { if let PatKind::TupleStruct(ref path, ref pats, _) = arm.pat.kind; if pats.len() == 1 && match_qpath(path, &paths::OPTION_SOME); @@ -766,7 +766,7 @@ fn is_ref_some_arm(arm: &Arm) -> Option { None } -fn has_only_ref_pats(arms: &[Arm]) -> bool { +fn has_only_ref_pats(arms: &[Arm<'_>]) -> bool { let mapped = arms .iter() .map(|a| { diff --git a/clippy_lints/src/mem_discriminant.rs b/clippy_lints/src/mem_discriminant.rs index 989c254fe556..881ade8cd3fc 100644 --- a/clippy_lints/src/mem_discriminant.rs +++ b/clippy_lints/src/mem_discriminant.rs @@ -31,7 +31,7 @@ declare_clippy_lint! { declare_lint_pass!(MemDiscriminant => [MEM_DISCRIMINANT_NON_ENUM]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MemDiscriminant { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { + fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { if_chain! { if let ExprKind::Call(ref func, ref func_args) = expr.kind; // is `mem::discriminant` diff --git a/clippy_lints/src/mem_forget.rs b/clippy_lints/src/mem_forget.rs index fc3c5ab5dc86..4c3ba21e4f9d 100644 --- a/clippy_lints/src/mem_forget.rs +++ b/clippy_lints/src/mem_forget.rs @@ -27,7 +27,7 @@ declare_clippy_lint! { declare_lint_pass!(MemForget => [MEM_FORGET]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MemForget { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) { + fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) { if let ExprKind::Call(ref path_expr, ref args) = e.kind { if let ExprKind::Path(ref qpath) = path_expr.kind { if let Some(def_id) = qpath_res(cx, qpath, path_expr.hir_id).opt_def_id() { diff --git a/clippy_lints/src/mem_replace.rs b/clippy_lints/src/mem_replace.rs index f819fdc17b12..b7b0538cbaee 100644 --- a/clippy_lints/src/mem_replace.rs +++ b/clippy_lints/src/mem_replace.rs @@ -71,7 +71,7 @@ declare_lint_pass!(MemReplace => [MEM_REPLACE_OPTION_WITH_NONE, MEM_REPLACE_WITH_UNINIT]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MemReplace { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { + fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { if_chain! { // Check that `expr` is a call to `mem::replace()` if let ExprKind::Call(ref func, ref func_args) = expr.kind; diff --git a/clippy_lints/src/methods/inefficient_to_string.rs b/clippy_lints/src/methods/inefficient_to_string.rs index 9e87ab3ad3a9..47a77b011e45 100644 --- a/clippy_lints/src/methods/inefficient_to_string.rs +++ b/clippy_lints/src/methods/inefficient_to_string.rs @@ -7,7 +7,7 @@ use rustc::ty::{self, Ty}; use rustc_errors::Applicability; /// Checks for the `INEFFICIENT_TO_STRING` lint -pub fn lint<'tcx>(cx: &LateContext<'_, 'tcx>, expr: &hir::Expr, arg: &hir::Expr, arg_ty: Ty<'tcx>) { +pub fn lint<'tcx>(cx: &LateContext<'_, 'tcx>, expr: &hir::Expr<'_>, arg: &hir::Expr<'_>, arg_ty: Ty<'tcx>) { if_chain! { if let Some(to_string_meth_did) = cx.tables.type_dependent_def_id(expr.hir_id); if match_def_path(cx, to_string_meth_did, &paths::TO_STRING_METHOD); diff --git a/clippy_lints/src/methods/manual_saturating_arithmetic.rs b/clippy_lints/src/methods/manual_saturating_arithmetic.rs index 075039954bd2..e6ffa3328820 100644 --- a/clippy_lints/src/methods/manual_saturating_arithmetic.rs +++ b/clippy_lints/src/methods/manual_saturating_arithmetic.rs @@ -6,7 +6,7 @@ use rustc_errors::Applicability; use rustc_target::abi::LayoutOf; use syntax::ast; -pub fn lint(cx: &LateContext<'_, '_>, expr: &hir::Expr, args: &[&[hir::Expr]], arith: &str) { +pub fn lint(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, args: &[&[hir::Expr<'_>]], arith: &str) { let unwrap_arg = &args[0][1]; let arith_lhs = &args[1][0]; let arith_rhs = &args[1][1]; @@ -82,7 +82,7 @@ enum MinMax { Max, } -fn is_min_or_max<'tcx>(cx: &LateContext<'_, 'tcx>, expr: &hir::Expr) -> Option { +fn is_min_or_max<'tcx>(cx: &LateContext<'_, 'tcx>, expr: &hir::Expr<'_>) -> Option { // `T::max_value()` `T::min_value()` inherent methods if_chain! { if let hir::ExprKind::Call(func, args) = &expr.kind; @@ -125,7 +125,7 @@ fn is_min_or_max<'tcx>(cx: &LateContext<'_, 'tcx>, expr: &hir::Expr) -> Option, check_min: bool| { if let hir::ExprKind::Lit(lit) = &expr.kind { if let ast::LitKind::Int(value, _) = lit.node { if value == maxval { @@ -160,7 +160,7 @@ enum Sign { Neg, } -fn lit_sign(expr: &hir::Expr) -> Option { +fn lit_sign(expr: &hir::Expr<'_>) -> Option { if let hir::ExprKind::Unary(hir::UnNeg, inner) = &expr.kind { if let hir::ExprKind::Lit(..) = &inner.kind { return Some(Sign::Neg); diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index 8a4d08ccb984..56c958bdc88c 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -1152,7 +1152,7 @@ declare_lint_pass!(Methods => [ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Methods { #[allow(clippy::cognitive_complexity)] - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) { + fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr<'_>) { if in_macro(expr.span) { return; } @@ -1370,10 +1370,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Methods { #[allow(clippy::too_many_lines)] fn lint_or_fun_call<'a, 'tcx>( cx: &LateContext<'a, 'tcx>, - expr: &hir::Expr, + expr: &hir::Expr<'_>, method_span: Span, name: &str, - args: &'tcx [hir::Expr], + args: &'tcx [hir::Expr<'_>], ) { // Searches an expression for method calls or function calls that aren't ctors struct FunCallFinder<'a, 'tcx> { @@ -1382,7 +1382,7 @@ fn lint_or_fun_call<'a, 'tcx>( } impl<'a, 'tcx> intravisit::Visitor<'tcx> for FunCallFinder<'a, 'tcx> { - fn visit_expr(&mut self, expr: &'tcx hir::Expr) { + fn visit_expr(&mut self, expr: &'tcx hir::Expr<'_>) { let call_found = match &expr.kind { // ignore enum and struct constructors hir::ExprKind::Call(..) => !is_ctor_or_promotable_const_function(self.cx, expr), @@ -1408,9 +1408,9 @@ fn lint_or_fun_call<'a, 'tcx>( fn check_unwrap_or_default( cx: &LateContext<'_, '_>, name: &str, - fun: &hir::Expr, - self_expr: &hir::Expr, - arg: &hir::Expr, + fun: &hir::Expr<'_>, + self_expr: &hir::Expr<'_>, + arg: &hir::Expr<'_>, or_has_args: bool, span: Span, ) -> bool { @@ -1453,8 +1453,8 @@ fn lint_or_fun_call<'a, 'tcx>( name: &str, method_span: Span, fun_span: Span, - self_expr: &hir::Expr, - arg: &'tcx hir::Expr, + self_expr: &hir::Expr<'_>, + arg: &'tcx hir::Expr<'_>, or_has_args: bool, span: Span, ) { @@ -1534,10 +1534,16 @@ fn lint_or_fun_call<'a, 'tcx>( /// Checks for the `EXPECT_FUN_CALL` lint. #[allow(clippy::too_many_lines)] -fn lint_expect_fun_call(cx: &LateContext<'_, '_>, expr: &hir::Expr, method_span: Span, name: &str, args: &[hir::Expr]) { +fn lint_expect_fun_call( + cx: &LateContext<'_, '_>, + expr: &hir::Expr<'_>, + method_span: Span, + name: &str, + args: &[hir::Expr<'_>], +) { // Strip `&`, `as_ref()` and `as_str()` off `arg` until we're left with either a `String` or // `&str` - fn get_arg_root<'a>(cx: &LateContext<'_, '_>, arg: &'a hir::Expr) -> &'a hir::Expr { + fn get_arg_root<'a>(cx: &LateContext<'_, '_>, arg: &'a hir::Expr<'a>) -> &'a hir::Expr<'a> { let mut arg_root = arg; loop { arg_root = match &arg_root.kind { @@ -1564,7 +1570,7 @@ fn lint_expect_fun_call(cx: &LateContext<'_, '_>, expr: &hir::Expr, method_span: // Only `&'static str` or `String` can be used directly in the `panic!`. Other types should be // converted to string. - fn requires_to_string(cx: &LateContext<'_, '_>, arg: &hir::Expr) -> bool { + fn requires_to_string(cx: &LateContext<'_, '_>, arg: &hir::Expr<'_>) -> bool { let arg_ty = cx.tables.expr_ty(arg); if match_type(cx, arg_ty, &paths::STRING) { return false; @@ -1579,7 +1585,7 @@ fn lint_expect_fun_call(cx: &LateContext<'_, '_>, expr: &hir::Expr, method_span: fn generate_format_arg_snippet( cx: &LateContext<'_, '_>, - a: &hir::Expr, + a: &hir::Expr<'_>, applicability: &mut Applicability, ) -> Vec { if_chain! { @@ -1598,7 +1604,7 @@ fn lint_expect_fun_call(cx: &LateContext<'_, '_>, expr: &hir::Expr, method_span: } } - fn is_call(node: &hir::ExprKind) -> bool { + fn is_call(node: &hir::ExprKind<'_>) -> bool { match node { hir::ExprKind::AddrOf(hir::BorrowKind::Ref, _, expr) => { is_call(&expr.kind) @@ -1681,7 +1687,7 @@ fn lint_expect_fun_call(cx: &LateContext<'_, '_>, expr: &hir::Expr, method_span: } /// Checks for the `CLONE_ON_COPY` lint. -fn lint_clone_on_copy(cx: &LateContext<'_, '_>, expr: &hir::Expr, arg: &hir::Expr, arg_ty: Ty<'_>) { +fn lint_clone_on_copy(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, arg: &hir::Expr<'_>, arg_ty: Ty<'_>) { let ty = cx.tables.expr_ty(expr); if let ty::Ref(_, inner, _) = arg_ty.kind { if let ty::Ref(_, innermost, _) = inner.kind { @@ -1774,7 +1780,7 @@ fn lint_clone_on_copy(cx: &LateContext<'_, '_>, expr: &hir::Expr, arg: &hir::Exp } } -fn lint_clone_on_ref_ptr(cx: &LateContext<'_, '_>, expr: &hir::Expr, arg: &hir::Expr) { +fn lint_clone_on_ref_ptr(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, arg: &hir::Expr<'_>) { let obj_ty = walk_ptrs_ty(cx.tables.expr_ty(arg)); if let ty::Adt(_, subst) = obj_ty.kind { @@ -1805,7 +1811,7 @@ fn lint_clone_on_ref_ptr(cx: &LateContext<'_, '_>, expr: &hir::Expr, arg: &hir:: } } -fn lint_string_extend(cx: &LateContext<'_, '_>, expr: &hir::Expr, args: &[hir::Expr]) { +fn lint_string_extend(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, args: &[hir::Expr<'_>]) { let arg = &args[1]; if let Some(arglists) = method_chain_args(arg, &["chars"]) { let target = &arglists[0][0]; @@ -1836,14 +1842,14 @@ fn lint_string_extend(cx: &LateContext<'_, '_>, expr: &hir::Expr, args: &[hir::E } } -fn lint_extend(cx: &LateContext<'_, '_>, expr: &hir::Expr, args: &[hir::Expr]) { +fn lint_extend(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, args: &[hir::Expr<'_>]) { let obj_ty = walk_ptrs_ty(cx.tables.expr_ty(&args[0])); if match_type(cx, obj_ty, &paths::STRING) { lint_string_extend(cx, expr, args); } } -fn lint_cstring_as_ptr(cx: &LateContext<'_, '_>, expr: &hir::Expr, source: &hir::Expr, unwrap: &hir::Expr) { +fn lint_cstring_as_ptr(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, source: &hir::Expr<'_>, unwrap: &hir::Expr<'_>) { if_chain! { let source_type = cx.tables.expr_ty(source); if let ty::Adt(def, substs) = source_type.kind; @@ -1863,7 +1869,11 @@ fn lint_cstring_as_ptr(cx: &LateContext<'_, '_>, expr: &hir::Expr, source: &hir: } } -fn lint_iter_cloned_collect<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &hir::Expr, iter_args: &'tcx [hir::Expr]) { +fn lint_iter_cloned_collect<'a, 'tcx>( + cx: &LateContext<'a, 'tcx>, + expr: &hir::Expr<'_>, + iter_args: &'tcx [hir::Expr<'_>], +) { if_chain! { if is_type_diagnostic_item(cx, cx.tables.expr_ty(expr), Symbol::intern("vec_type")); if let Some(slice) = derefs_to_slice(cx, &iter_args[0], cx.tables.expr_ty(&iter_args[0])); @@ -1884,11 +1894,11 @@ fn lint_iter_cloned_collect<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &hir::Ex } } -fn lint_unnecessary_fold(cx: &LateContext<'_, '_>, expr: &hir::Expr, fold_args: &[hir::Expr], fold_span: Span) { +fn lint_unnecessary_fold(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, fold_args: &[hir::Expr<'_>], fold_span: Span) { fn check_fold_with_op( cx: &LateContext<'_, '_>, - expr: &hir::Expr, - fold_args: &[hir::Expr], + expr: &hir::Expr<'_>, + fold_args: &[hir::Expr<'_>], fold_span: Span, op: hir::BinOpKind, replacement_method_name: &str, @@ -1971,7 +1981,7 @@ fn lint_unnecessary_fold(cx: &LateContext<'_, '_>, expr: &hir::Expr, fold_args: } } -fn lint_step_by<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &hir::Expr, args: &'tcx [hir::Expr]) { +fn lint_step_by<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &hir::Expr<'_>, args: &'tcx [hir::Expr<'_>]) { if match_trait_method(cx, expr, &paths::ITERATOR) { use crate::consts::{constant, Constant}; if let Some((Constant::Int(0), _)) = constant(cx, cx.tables, &args[1]) { @@ -1985,7 +1995,12 @@ fn lint_step_by<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &hir::Expr, args: &' } } -fn lint_iter_nth<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &hir::Expr, iter_args: &'tcx [hir::Expr], is_mut: bool) { +fn lint_iter_nth<'a, 'tcx>( + cx: &LateContext<'a, 'tcx>, + expr: &hir::Expr<'_>, + iter_args: &'tcx [hir::Expr<'_>], + is_mut: bool, +) { let mut_str = if is_mut { "_mut" } else { "" }; let caller_type = if derefs_to_slice(cx, &iter_args[0], cx.tables.expr_ty(&iter_args[0])).is_some() { "slice" @@ -2008,7 +2023,12 @@ fn lint_iter_nth<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &hir::Expr, iter_ar ); } -fn lint_get_unwrap<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &hir::Expr, get_args: &'tcx [hir::Expr], is_mut: bool) { +fn lint_get_unwrap<'a, 'tcx>( + cx: &LateContext<'a, 'tcx>, + expr: &hir::Expr<'_>, + get_args: &'tcx [hir::Expr<'_>], + is_mut: bool, +) { // Note: we don't want to lint `get_mut().unwrap` for `HashMap` or `BTreeMap`, // because they do not implement `IndexMut` let mut applicability = Applicability::MachineApplicable; @@ -2081,7 +2101,7 @@ fn lint_get_unwrap<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &hir::Expr, get_a ); } -fn lint_iter_skip_next(cx: &LateContext<'_, '_>, expr: &hir::Expr) { +fn lint_iter_skip_next(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>) { // lint if caller of skip is an Iterator if match_trait_method(cx, expr, &paths::ITERATOR) { span_lint( @@ -2095,9 +2115,9 @@ fn lint_iter_skip_next(cx: &LateContext<'_, '_>, expr: &hir::Expr) { fn derefs_to_slice<'a, 'tcx>( cx: &LateContext<'a, 'tcx>, - expr: &'tcx hir::Expr, + expr: &'tcx hir::Expr<'tcx>, ty: Ty<'tcx>, -) -> Option<&'tcx hir::Expr> { +) -> Option<&'tcx hir::Expr<'tcx>> { fn may_slice<'a>(cx: &LateContext<'_, 'a>, ty: Ty<'a>) -> bool { match ty.kind { ty::Slice(_) => true, @@ -2132,7 +2152,7 @@ fn derefs_to_slice<'a, 'tcx>( } /// lint use of `unwrap()` for `Option`s and `Result`s -fn lint_unwrap(cx: &LateContext<'_, '_>, expr: &hir::Expr, unwrap_args: &[hir::Expr]) { +fn lint_unwrap(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, unwrap_args: &[hir::Expr<'_>]) { let obj_ty = walk_ptrs_ty(cx.tables.expr_ty(&unwrap_args[0])); let mess = if match_type(cx, obj_ty, &paths::OPTION) { @@ -2159,7 +2179,7 @@ fn lint_unwrap(cx: &LateContext<'_, '_>, expr: &hir::Expr, unwrap_args: &[hir::E } /// lint use of `expect()` for `Option`s and `Result`s -fn lint_expect(cx: &LateContext<'_, '_>, expr: &hir::Expr, expect_args: &[hir::Expr]) { +fn lint_expect(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, expect_args: &[hir::Expr<'_>]) { let obj_ty = walk_ptrs_ty(cx.tables.expr_ty(&expect_args[0])); let mess = if match_type(cx, obj_ty, &paths::OPTION) { @@ -2184,7 +2204,7 @@ fn lint_expect(cx: &LateContext<'_, '_>, expr: &hir::Expr, expect_args: &[hir::E } /// lint use of `ok().expect()` for `Result`s -fn lint_ok_expect(cx: &LateContext<'_, '_>, expr: &hir::Expr, ok_args: &[hir::Expr]) { +fn lint_ok_expect(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, ok_args: &[hir::Expr<'_>]) { if_chain! { // lint if the caller of `ok()` is a `Result` if match_type(cx, cx.tables.expr_ty(&ok_args[0]), &paths::RESULT); @@ -2204,7 +2224,7 @@ fn lint_ok_expect(cx: &LateContext<'_, '_>, expr: &hir::Expr, ok_args: &[hir::Ex } /// lint use of `map().flatten()` for `Iterators` -fn lint_map_flatten<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr, map_args: &'tcx [hir::Expr]) { +fn lint_map_flatten<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr<'_>, map_args: &'tcx [hir::Expr<'_>]) { // lint if caller of `.map().flatten()` is an Iterator if match_trait_method(cx, expr, &paths::ITERATOR) { let msg = "called `map(..).flatten()` on an `Iterator`. \ @@ -2226,9 +2246,9 @@ fn lint_map_flatten<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr, /// lint use of `map().unwrap_or_else()` for `Option`s and `Result`s fn lint_map_unwrap_or_else<'a, 'tcx>( cx: &LateContext<'a, 'tcx>, - expr: &'tcx hir::Expr, - map_args: &'tcx [hir::Expr], - unwrap_args: &'tcx [hir::Expr], + expr: &'tcx hir::Expr<'_>, + map_args: &'tcx [hir::Expr<'_>], + unwrap_args: &'tcx [hir::Expr<'_>], ) { // lint if the caller of `map()` is an `Option` let is_option = match_type(cx, cx.tables.expr_ty(&map_args[0]), &paths::OPTION); @@ -2294,7 +2314,11 @@ fn lint_map_unwrap_or_else<'a, 'tcx>( } /// lint use of `_.map_or(None, _)` for `Option`s -fn lint_map_or_none<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr, map_or_args: &'tcx [hir::Expr]) { +fn lint_map_or_none<'a, 'tcx>( + cx: &LateContext<'a, 'tcx>, + expr: &'tcx hir::Expr<'_>, + map_or_args: &'tcx [hir::Expr<'_>], +) { if match_type(cx, cx.tables.expr_ty(&map_or_args[0]), &paths::OPTION) { // check if the first non-self argument to map_or() is None let map_or_arg_is_none = if let hir::ExprKind::Path(ref qpath) = map_or_args[1].kind { @@ -2323,7 +2347,7 @@ fn lint_map_or_none<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr, } /// Lint use of `_.and_then(|x| Some(y))` for `Option`s -fn lint_option_and_then_some(cx: &LateContext<'_, '_>, expr: &hir::Expr, args: &[hir::Expr]) { +fn lint_option_and_then_some(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, args: &[hir::Expr<'_>]) { const LINT_MSG: &str = "using `Option.and_then(|x| Some(y))`, which is more succinctly expressed as `map(|x| y)`"; const NO_OP_MSG: &str = "using `Option.and_then(Some)`, which is a no-op"; @@ -2390,7 +2414,11 @@ fn lint_option_and_then_some(cx: &LateContext<'_, '_>, expr: &hir::Expr, args: & } /// lint use of `filter().next()` for `Iterators` -fn lint_filter_next<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr, filter_args: &'tcx [hir::Expr]) { +fn lint_filter_next<'a, 'tcx>( + cx: &LateContext<'a, 'tcx>, + expr: &'tcx hir::Expr<'_>, + filter_args: &'tcx [hir::Expr<'_>], +) { // lint if caller of `.filter().next()` is an Iterator if match_trait_method(cx, expr, &paths::ITERATOR) { let msg = "called `filter(p).next()` on an `Iterator`. This is more succinctly expressed by calling \ @@ -2415,9 +2443,9 @@ fn lint_filter_next<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr, /// lint use of `filter().map()` for `Iterators` fn lint_filter_map<'a, 'tcx>( cx: &LateContext<'a, 'tcx>, - expr: &'tcx hir::Expr, - _filter_args: &'tcx [hir::Expr], - _map_args: &'tcx [hir::Expr], + expr: &'tcx hir::Expr<'_>, + _filter_args: &'tcx [hir::Expr<'_>], + _map_args: &'tcx [hir::Expr<'_>], ) { // lint if caller of `.filter().map()` is an Iterator if match_trait_method(cx, expr, &paths::ITERATOR) { @@ -2428,7 +2456,11 @@ fn lint_filter_map<'a, 'tcx>( } /// lint use of `filter_map().next()` for `Iterators` -fn lint_filter_map_next<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr, filter_args: &'tcx [hir::Expr]) { +fn lint_filter_map_next<'a, 'tcx>( + cx: &LateContext<'a, 'tcx>, + expr: &'tcx hir::Expr<'_>, + filter_args: &'tcx [hir::Expr<'_>], +) { if match_trait_method(cx, expr, &paths::ITERATOR) { let msg = "called `filter_map(p).next()` on an `Iterator`. This is more succinctly expressed by calling \ `.find_map(p)` instead."; @@ -2451,9 +2483,9 @@ fn lint_filter_map_next<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::E /// lint use of `find().map()` for `Iterators` fn lint_find_map<'a, 'tcx>( cx: &LateContext<'a, 'tcx>, - expr: &'tcx hir::Expr, - _find_args: &'tcx [hir::Expr], - map_args: &'tcx [hir::Expr], + expr: &'tcx hir::Expr<'_>, + _find_args: &'tcx [hir::Expr<'_>], + map_args: &'tcx [hir::Expr<'_>], ) { // lint if caller of `.filter().map()` is an Iterator if match_trait_method(cx, &map_args[0], &paths::ITERATOR) { @@ -2466,9 +2498,9 @@ fn lint_find_map<'a, 'tcx>( /// lint use of `filter_map().map()` for `Iterators` fn lint_filter_map_map<'a, 'tcx>( cx: &LateContext<'a, 'tcx>, - expr: &'tcx hir::Expr, - _filter_args: &'tcx [hir::Expr], - _map_args: &'tcx [hir::Expr], + expr: &'tcx hir::Expr<'_>, + _filter_args: &'tcx [hir::Expr<'_>], + _map_args: &'tcx [hir::Expr<'_>], ) { // lint if caller of `.filter().map()` is an Iterator if match_trait_method(cx, expr, &paths::ITERATOR) { @@ -2481,9 +2513,9 @@ fn lint_filter_map_map<'a, 'tcx>( /// lint use of `filter().flat_map()` for `Iterators` fn lint_filter_flat_map<'a, 'tcx>( cx: &LateContext<'a, 'tcx>, - expr: &'tcx hir::Expr, - _filter_args: &'tcx [hir::Expr], - _map_args: &'tcx [hir::Expr], + expr: &'tcx hir::Expr<'_>, + _filter_args: &'tcx [hir::Expr<'_>], + _map_args: &'tcx [hir::Expr<'_>], ) { // lint if caller of `.filter().flat_map()` is an Iterator if match_trait_method(cx, expr, &paths::ITERATOR) { @@ -2497,9 +2529,9 @@ fn lint_filter_flat_map<'a, 'tcx>( /// lint use of `filter_map().flat_map()` for `Iterators` fn lint_filter_map_flat_map<'a, 'tcx>( cx: &LateContext<'a, 'tcx>, - expr: &'tcx hir::Expr, - _filter_args: &'tcx [hir::Expr], - _map_args: &'tcx [hir::Expr], + expr: &'tcx hir::Expr<'_>, + _filter_args: &'tcx [hir::Expr<'_>], + _map_args: &'tcx [hir::Expr<'_>], ) { // lint if caller of `.filter_map().flat_map()` is an Iterator if match_trait_method(cx, expr, &paths::ITERATOR) { @@ -2513,8 +2545,8 @@ fn lint_filter_map_flat_map<'a, 'tcx>( /// lint use of `flat_map` for `Iterators` where `flatten` would be sufficient fn lint_flat_map_identity<'a, 'tcx>( cx: &LateContext<'a, 'tcx>, - expr: &'tcx hir::Expr, - flat_map_args: &'tcx [hir::Expr], + expr: &'tcx hir::Expr<'_>, + flat_map_args: &'tcx [hir::Expr<'_>], flat_map_span: Span, ) { if match_trait_method(cx, expr, &paths::ITERATOR) { @@ -2562,10 +2594,10 @@ fn lint_flat_map_identity<'a, 'tcx>( /// lint searching an Iterator followed by `is_some()` fn lint_search_is_some<'a, 'tcx>( cx: &LateContext<'a, 'tcx>, - expr: &'tcx hir::Expr, + expr: &'tcx hir::Expr<'_>, search_method: &str, - search_args: &'tcx [hir::Expr], - is_some_args: &'tcx [hir::Expr], + search_args: &'tcx [hir::Expr<'_>], + is_some_args: &'tcx [hir::Expr<'_>], method_span: Span, ) { // lint if caller of search is an Iterator @@ -2618,9 +2650,9 @@ fn lint_search_is_some<'a, 'tcx>( /// Used for `lint_binary_expr_with_method_call`. #[derive(Copy, Clone)] struct BinaryExprInfo<'a> { - expr: &'a hir::Expr, - chain: &'a hir::Expr, - other: &'a hir::Expr, + expr: &'a hir::Expr<'a>, + chain: &'a hir::Expr<'a>, + other: &'a hir::Expr<'a>, eq: bool, } @@ -2751,7 +2783,11 @@ fn lint_chars_last_cmp_with_unwrap<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, info: & } /// lint for length-1 `str`s for methods in `PATTERN_METHODS` -fn lint_single_char_pattern<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, _expr: &'tcx hir::Expr, arg: &'tcx hir::Expr) { +fn lint_single_char_pattern<'a, 'tcx>( + cx: &LateContext<'a, 'tcx>, + _expr: &'tcx hir::Expr<'_>, + arg: &'tcx hir::Expr<'_>, +) { if_chain! { if let hir::ExprKind::Lit(lit) = &arg.kind; if let ast::LitKind::Str(r, style) = lit.node; @@ -2782,7 +2818,7 @@ fn lint_single_char_pattern<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, _expr: &'tcx h } /// Checks for the `USELESS_ASREF` lint. -fn lint_asref(cx: &LateContext<'_, '_>, expr: &hir::Expr, call_name: &str, as_ref_args: &[hir::Expr]) { +fn lint_asref(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, call_name: &str, as_ref_args: &[hir::Expr<'_>]) { // when we get here, we've already checked that the call name is "as_ref" or "as_mut" // check if the call is to the actual `AsRef` or `AsMut` trait if match_trait_method(cx, expr, &paths::ASREF_TRAIT) || match_trait_method(cx, expr, &paths::ASMUT_TRAIT) { @@ -2831,7 +2867,7 @@ fn ty_has_iter_method(cx: &LateContext<'_, '_>, self_ref_ty: Ty<'_>) -> Option<( }) } -fn lint_into_iter(cx: &LateContext<'_, '_>, expr: &hir::Expr, self_ref_ty: Ty<'_>, method_span: Span) { +fn lint_into_iter(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, self_ref_ty: Ty<'_>, method_span: Span) { if !match_trait_method(cx, expr, &paths::INTO_ITERATOR) { return; } @@ -2852,7 +2888,7 @@ fn lint_into_iter(cx: &LateContext<'_, '_>, expr: &hir::Expr, self_ref_ty: Ty<'_ } /// lint for `MaybeUninit::uninit().assume_init()` (we already have the latter) -fn lint_maybe_uninit(cx: &LateContext<'_, '_>, expr: &hir::Expr, outer: &hir::Expr) { +fn lint_maybe_uninit(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, outer: &hir::Expr<'_>) { if_chain! { if let hir::ExprKind::Call(ref callee, ref args) = expr.kind; if args.is_empty(); @@ -2882,7 +2918,7 @@ fn is_maybe_uninit_ty_valid(cx: &LateContext<'_, '_>, ty: Ty<'_>) -> bool { } } -fn lint_suspicious_map(cx: &LateContext<'_, '_>, expr: &hir::Expr) { +fn lint_suspicious_map(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>) { span_help_and_lint( cx, SUSPICIOUS_MAP, @@ -3095,13 +3131,13 @@ fn is_bool(ty: &hir::Ty) -> bool { } // Returns `true` if `expr` contains a return expression -fn contains_return(expr: &hir::Expr) -> bool { +fn contains_return(expr: &hir::Expr<'_>) -> bool { struct RetCallFinder { found: bool, } impl<'tcx> intravisit::Visitor<'tcx> for RetCallFinder { - fn visit_expr(&mut self, expr: &'tcx hir::Expr) { + fn visit_expr(&mut self, expr: &'tcx hir::Expr<'_>) { if self.found { return; } @@ -3122,7 +3158,7 @@ fn contains_return(expr: &hir::Expr) -> bool { visitor.found } -fn check_pointer_offset(cx: &LateContext<'_, '_>, expr: &hir::Expr, args: &[hir::Expr]) { +fn check_pointer_offset(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, args: &[hir::Expr<'_>]) { if_chain! { if args.len() == 2; if let ty::RawPtr(ty::TypeAndMut { ref ty, .. }) = cx.tables.expr_ty(&args[0]).kind; diff --git a/clippy_lints/src/methods/option_map_unwrap_or.rs b/clippy_lints/src/methods/option_map_unwrap_or.rs index 769392a6fd8f..b1647b032504 100644 --- a/clippy_lints/src/methods/option_map_unwrap_or.rs +++ b/clippy_lints/src/methods/option_map_unwrap_or.rs @@ -11,9 +11,9 @@ use super::OPTION_MAP_UNWRAP_OR; /// lint use of `map().unwrap_or()` for `Option`s pub(super) fn lint<'a, 'tcx>( cx: &LateContext<'a, 'tcx>, - expr: &hir::Expr, - map_args: &'tcx [hir::Expr], - unwrap_args: &'tcx [hir::Expr], + expr: &hir::Expr<'_>, + map_args: &'tcx [hir::Expr<'_>], + unwrap_args: &'tcx [hir::Expr<'_>], ) { // lint if the caller of `map()` is an `Option` if match_type(cx, cx.tables.expr_ty(&map_args[0]), &paths::OPTION) { diff --git a/clippy_lints/src/methods/unnecessary_filter_map.rs b/clippy_lints/src/methods/unnecessary_filter_map.rs index abcdc35cd888..567b3db1e82c 100644 --- a/clippy_lints/src/methods/unnecessary_filter_map.rs +++ b/clippy_lints/src/methods/unnecessary_filter_map.rs @@ -10,7 +10,7 @@ use if_chain::if_chain; use super::UNNECESSARY_FILTER_MAP; -pub(super) fn lint(cx: &LateContext<'_, '_>, expr: &hir::Expr, args: &[hir::Expr]) { +pub(super) fn lint(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, args: &[hir::Expr<'_>]) { if !match_trait_method(cx, expr, &paths::ITERATOR) { return; } @@ -54,7 +54,7 @@ pub(super) fn lint(cx: &LateContext<'_, '_>, expr: &hir::Expr, args: &[hir::Expr fn check_expression<'a, 'tcx>( cx: &'a LateContext<'a, 'tcx>, arg_id: hir::HirId, - expr: &'tcx hir::Expr, + expr: &'tcx hir::Expr<'_>, ) -> (bool, bool) { match &expr.kind { hir::ExprKind::Call(ref func, ref args) => { @@ -87,10 +87,10 @@ fn check_expression<'a, 'tcx>( (false, false) } }, - hir::ExprKind::Match(_, ref arms, _) => { + hir::ExprKind::Match(_, arms, _) => { let mut found_mapping = false; let mut found_filtering = false; - for arm in arms { + for arm in *arms { let (m, f) = check_expression(cx, arg_id, &arm.body); found_mapping |= m; found_filtering |= f; @@ -123,7 +123,7 @@ impl<'a, 'tcx> ReturnVisitor<'a, 'tcx> { } impl<'a, 'tcx> Visitor<'tcx> for ReturnVisitor<'a, 'tcx> { - fn visit_expr(&mut self, expr: &'tcx hir::Expr) { + fn visit_expr(&mut self, expr: &'tcx hir::Expr<'_>) { if let hir::ExprKind::Ret(Some(expr)) = &expr.kind { let (found_mapping, found_filtering) = check_expression(self.cx, self.arg_id, expr); self.found_mapping |= found_mapping; diff --git a/clippy_lints/src/minmax.rs b/clippy_lints/src/minmax.rs index 7e2ec8f498bd..a838bb0f3d89 100644 --- a/clippy_lints/src/minmax.rs +++ b/clippy_lints/src/minmax.rs @@ -29,7 +29,7 @@ declare_clippy_lint! { declare_lint_pass!(MinMaxPass => [MIN_MAX]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MinMaxPass { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { + fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { if let Some((outer_max, outer_c, oe)) = min_max(cx, expr) { if let Some((inner_max, inner_c, ie)) = min_max(cx, oe) { if outer_max == inner_max { @@ -60,7 +60,7 @@ enum MinMax { Max, } -fn min_max<'a>(cx: &LateContext<'_, '_>, expr: &'a Expr) -> Option<(MinMax, Constant, &'a Expr)> { +fn min_max<'a>(cx: &LateContext<'_, '_>, expr: &'a Expr<'a>) -> Option<(MinMax, Constant, &'a Expr<'a>)> { if let ExprKind::Call(ref path, ref args) = expr.kind { if let ExprKind::Path(ref qpath) = path.kind { cx.tables.qpath_res(qpath, path.hir_id).opt_def_id().and_then(|def_id| { @@ -80,7 +80,11 @@ fn min_max<'a>(cx: &LateContext<'_, '_>, expr: &'a Expr) -> Option<(MinMax, Cons } } -fn fetch_const<'a>(cx: &LateContext<'_, '_>, args: &'a [Expr], m: MinMax) -> Option<(MinMax, Constant, &'a Expr)> { +fn fetch_const<'a>( + cx: &LateContext<'_, '_>, + args: &'a [Expr<'a>], + m: MinMax, +) -> Option<(MinMax, Constant, &'a Expr<'a>)> { if args.len() != 2 { return None; } diff --git a/clippy_lints/src/misc.rs b/clippy_lints/src/misc.rs index 494f04d4bcd3..295794e8c38f 100644 --- a/clippy_lints/src/misc.rs +++ b/clippy_lints/src/misc.rs @@ -262,7 +262,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MiscLints { } } - fn check_stmt(&mut self, cx: &LateContext<'a, 'tcx>, stmt: &'tcx Stmt) { + fn check_stmt(&mut self, cx: &LateContext<'a, 'tcx>, stmt: &'tcx Stmt<'_>) { if_chain! { if let StmtKind::Local(ref local) = stmt.kind; if let PatKind::Binding(an, .., name, None) = local.pat.kind; @@ -334,7 +334,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MiscLints { }; } - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { + fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { match expr.kind { ExprKind::Cast(ref e, ref ty) => { check_cast(cx, expr.span, e, ty); @@ -440,7 +440,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MiscLints { } } -fn check_nan(cx: &LateContext<'_, '_>, expr: &Expr, cmp_expr: &Expr) { +fn check_nan(cx: &LateContext<'_, '_>, expr: &Expr<'_>, cmp_expr: &Expr<'_>) { if_chain! { if !in_constant(cx, cmp_expr.hir_id); if let Some((value, _)) = constant(cx, cx.tables, expr); @@ -463,7 +463,7 @@ fn check_nan(cx: &LateContext<'_, '_>, expr: &Expr, cmp_expr: &Expr) { } } -fn is_named_constant<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) -> bool { +fn is_named_constant<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) -> bool { if let Some((_, res)) = constant(cx, cx.tables, expr) { res } else { @@ -471,7 +471,7 @@ fn is_named_constant<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) -> } } -fn is_allowed<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) -> bool { +fn is_allowed<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) -> bool { match constant(cx, cx.tables, expr) { Some((Constant::F32(f), _)) => f == 0.0 || f.is_infinite(), Some((Constant::F64(f), _)) => f == 0.0 || f.is_infinite(), @@ -480,7 +480,7 @@ fn is_allowed<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) -> bool { } // Return true if `expr` is the result of `signum()` invoked on a float value. -fn is_signum(cx: &LateContext<'_, '_>, expr: &Expr) -> bool { +fn is_signum(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool { // The negation of a signum is still a signum if let ExprKind::Unary(UnNeg, ref child_expr) = expr.kind { return is_signum(cx, &child_expr); @@ -498,11 +498,11 @@ fn is_signum(cx: &LateContext<'_, '_>, expr: &Expr) -> bool { false } -fn is_float(cx: &LateContext<'_, '_>, expr: &Expr) -> bool { +fn is_float(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool { matches!(walk_ptrs_ty(cx.tables.expr_ty(expr)).kind, ty::Float(_)) } -fn check_to_owned(cx: &LateContext<'_, '_>, expr: &Expr, other: &Expr) { +fn check_to_owned(cx: &LateContext<'_, '_>, expr: &Expr<'_>, other: &Expr<'_>) { let (arg_ty, snip) = match expr.kind { ExprKind::MethodCall(.., ref args) if args.len() == 1 => { if match_trait_method(cx, expr, &paths::TO_STRING) || match_trait_method(cx, expr, &paths::TO_OWNED) { @@ -587,7 +587,7 @@ fn check_to_owned(cx: &LateContext<'_, '_>, expr: &Expr, other: &Expr) { /// Heuristic to see if an expression is used. Should be compatible with /// `unused_variables`'s idea /// of what it means for an expression to be "used". -fn is_used(cx: &LateContext<'_, '_>, expr: &Expr) -> bool { +fn is_used(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool { if let Some(parent) = get_parent_expr(cx, expr) { match parent.kind { ExprKind::Assign(_, ref rhs, _) | ExprKind::AssignOp(_, _, ref rhs) => { @@ -602,7 +602,7 @@ fn is_used(cx: &LateContext<'_, '_>, expr: &Expr) -> bool { /// Tests whether an expression is in a macro expansion (e.g., something /// generated by `#[derive(...)]` or the like). -fn in_attributes_expansion(expr: &Expr) -> bool { +fn in_attributes_expansion(expr: &Expr<'_>) -> bool { use syntax_pos::hygiene::MacroKind; if expr.span.from_expansion() { let data = expr.span.ctxt().outer_expn_data(); @@ -626,7 +626,7 @@ fn non_macro_local(cx: &LateContext<'_, '_>, res: def::Res) -> bool { } } -fn check_cast(cx: &LateContext<'_, '_>, span: Span, e: &Expr, ty: &Ty) { +fn check_cast(cx: &LateContext<'_, '_>, span: Span, e: &Expr<'_>, ty: &Ty) { if_chain! { if let TyKind::Ptr(ref mut_ty) = ty.kind; if let ExprKind::Lit(ref lit) = e.kind; diff --git a/clippy_lints/src/mul_add.rs b/clippy_lints/src/mul_add.rs index e6a68ac5c5a9..d62cea7cdb29 100644 --- a/clippy_lints/src/mul_add.rs +++ b/clippy_lints/src/mul_add.rs @@ -44,12 +44,15 @@ declare_clippy_lint! { declare_lint_pass!(MulAddCheck => [MANUAL_MUL_ADD]); -fn is_float<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &Expr) -> bool { +fn is_float<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &Expr<'_>) -> bool { cx.tables.expr_ty(expr).is_floating_point() } // Checks whether expression is multiplication of two floats -fn is_float_mult_expr<'a, 'tcx, 'b>(cx: &LateContext<'a, 'tcx>, expr: &'b Expr) -> Option<(&'b Expr, &'b Expr)> { +fn is_float_mult_expr<'a, 'tcx, 'b>( + cx: &LateContext<'a, 'tcx>, + expr: &'b Expr<'b>, +) -> Option<(&'b Expr<'b>, &'b Expr<'b>)> { if let ExprKind::Binary(op, lhs, rhs) = &expr.kind { if let BinOpKind::Mul = op.node { if is_float(cx, &lhs) && is_float(cx, &rhs) { @@ -62,7 +65,7 @@ fn is_float_mult_expr<'a, 'tcx, 'b>(cx: &LateContext<'a, 'tcx>, expr: &'b Expr) } impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MulAddCheck { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { + fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { if let ExprKind::Binary(op, lhs, rhs) = &expr.kind { if let BinOpKind::Add = op.node { //Converts mult_lhs * mult_rhs + rhs to mult_lhs.mult_add(mult_rhs, rhs) diff --git a/clippy_lints/src/mut_key.rs b/clippy_lints/src/mut_key.rs index 3a0899032a56..03f9d522f0a4 100644 --- a/clippy_lints/src/mut_key.rs +++ b/clippy_lints/src/mut_key.rs @@ -73,7 +73,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MutableKeyType { } } - fn check_local(&mut self, cx: &LateContext<'_, '_>, local: &hir::Local) { + fn check_local(&mut self, cx: &LateContext<'_, '_>, local: &hir::Local<'_>) { if let hir::PatKind::Wild = local.pat.kind { return; } diff --git a/clippy_lints/src/mut_mut.rs b/clippy_lints/src/mut_mut.rs index 5bc0ff806b9d..99c37c82ad58 100644 --- a/clippy_lints/src/mut_mut.rs +++ b/clippy_lints/src/mut_mut.rs @@ -28,7 +28,7 @@ declare_clippy_lint! { declare_lint_pass!(MutMut => [MUT_MUT]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MutMut { - fn check_block(&mut self, cx: &LateContext<'a, 'tcx>, block: &'tcx hir::Block) { + fn check_block(&mut self, cx: &LateContext<'a, 'tcx>, block: &'tcx hir::Block<'_>) { intravisit::walk_block(&mut MutVisitor { cx }, block); } @@ -44,7 +44,7 @@ pub struct MutVisitor<'a, 'tcx> { } impl<'a, 'tcx> intravisit::Visitor<'tcx> for MutVisitor<'a, 'tcx> { - fn visit_expr(&mut self, expr: &'tcx hir::Expr) { + fn visit_expr(&mut self, expr: &'tcx hir::Expr<'_>) { if in_external_macro(self.cx.sess(), expr.span) { return; } diff --git a/clippy_lints/src/mut_reference.rs b/clippy_lints/src/mut_reference.rs index a8d1454096ab..6e5c5102a4ce 100644 --- a/clippy_lints/src/mut_reference.rs +++ b/clippy_lints/src/mut_reference.rs @@ -27,7 +27,7 @@ declare_clippy_lint! { declare_lint_pass!(UnnecessaryMutPassed => [UNNECESSARY_MUT_PASSED]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnnecessaryMutPassed { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) { + fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) { match e.kind { ExprKind::Call(ref fn_expr, ref arguments) => { if let ExprKind::Path(ref path) = fn_expr.kind { @@ -50,7 +50,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnnecessaryMutPassed { } } -fn check_arguments<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, arguments: &[Expr], type_definition: Ty<'tcx>, name: &str) { +fn check_arguments<'a, 'tcx>( + cx: &LateContext<'a, 'tcx>, + arguments: &[Expr<'_>], + type_definition: Ty<'tcx>, + name: &str, +) { match type_definition.kind { ty::FnDef(..) | ty::FnPtr(_) => { let parameters = type_definition.fn_sig(cx.tcx).skip_binder().inputs(); diff --git a/clippy_lints/src/mutable_debug_assertion.rs b/clippy_lints/src/mutable_debug_assertion.rs index 998153010105..5844de136b91 100644 --- a/clippy_lints/src/mutable_debug_assertion.rs +++ b/clippy_lints/src/mutable_debug_assertion.rs @@ -36,7 +36,7 @@ declare_lint_pass!(DebugAssertWithMutCall => [DEBUG_ASSERT_WITH_MUT_CALL]); const DEBUG_MACRO_NAMES: [&str; 3] = ["debug_assert", "debug_assert_eq", "debug_assert_ne"]; impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DebugAssertWithMutCall { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) { + fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) { for dmn in &DEBUG_MACRO_NAMES { if is_direct_expn_of(e.span, dmn).is_some() { if let Some(span) = extract_call(cx, e) { @@ -54,7 +54,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DebugAssertWithMutCall { //HACK(hellow554): remove this when #4694 is implemented #[allow(clippy::cognitive_complexity)] -fn extract_call<'a, 'tcx>(cx: &'a LateContext<'a, 'tcx>, e: &'tcx Expr) -> Option { +fn extract_call<'a, 'tcx>(cx: &'a LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) -> Option { if_chain! { if let ExprKind::Block(ref block, _) = e.kind; if block.stmts.len() == 1; @@ -127,7 +127,7 @@ impl<'a, 'tcx> MutArgVisitor<'a, 'tcx> { } impl<'a, 'tcx> Visitor<'tcx> for MutArgVisitor<'a, 'tcx> { - fn visit_expr(&mut self, expr: &'tcx Expr) { + fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { match expr.kind { ExprKind::AddrOf(BorrowKind::Ref, Mutability::Mut, _) => { self.found = true; diff --git a/clippy_lints/src/mutex_atomic.rs b/clippy_lints/src/mutex_atomic.rs index 89865bbaa99e..08c94be54ff2 100644 --- a/clippy_lints/src/mutex_atomic.rs +++ b/clippy_lints/src/mutex_atomic.rs @@ -56,7 +56,7 @@ declare_clippy_lint! { declare_lint_pass!(Mutex => [MUTEX_ATOMIC, MUTEX_INTEGER]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Mutex { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { + fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { let ty = cx.tables.expr_ty(expr); if let ty::Adt(_, subst) = ty.kind { if match_type(cx, ty, &paths::MUTEX) { diff --git a/clippy_lints/src/needless_bool.rs b/clippy_lints/src/needless_bool.rs index 7e8540ffd359..a9fc033f7245 100644 --- a/clippy_lints/src/needless_bool.rs +++ b/clippy_lints/src/needless_bool.rs @@ -62,7 +62,7 @@ declare_clippy_lint! { declare_lint_pass!(NeedlessBool => [NEEDLESS_BOOL]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessBool { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) { + fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) { use self::Expression::*; if let Some((ref pred, ref then_block, Some(ref else_expr))) = higher::if_block(&e) { let reduce = |ret, not| { @@ -122,7 +122,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessBool { declare_lint_pass!(BoolComparison => [BOOL_COMPARISON]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BoolComparison { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) { + fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) { if e.span.from_expansion() { return; } @@ -185,7 +185,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BoolComparison { fn check_comparison<'a, 'tcx>( cx: &LateContext<'a, 'tcx>, - e: &'tcx Expr, + e: &'tcx Expr<'_>, left_true: Option<(impl FnOnce(Sugg<'a>) -> Sugg<'a>, &str)>, left_false: Option<(impl FnOnce(Sugg<'a>) -> Sugg<'a>, &str)>, right_true: Option<(impl FnOnce(Sugg<'a>) -> Sugg<'a>, &str)>, @@ -232,8 +232,8 @@ fn check_comparison<'a, 'tcx>( fn suggest_bool_comparison<'a, 'tcx>( cx: &LateContext<'a, 'tcx>, - e: &'tcx Expr, - expr: &Expr, + e: &'tcx Expr<'_>, + expr: &Expr<'_>, mut applicability: Applicability, message: &str, conv_hint: impl FnOnce(Sugg<'a>) -> Sugg<'a>, @@ -256,7 +256,7 @@ enum Expression { Other, } -fn fetch_bool_block(block: &Block) -> Expression { +fn fetch_bool_block(block: &Block<'_>) -> Expression { match (&*block.stmts, block.expr.as_ref()) { (&[], Some(e)) => fetch_bool_expr(&**e), (&[ref e], None) => { @@ -274,7 +274,7 @@ fn fetch_bool_block(block: &Block) -> Expression { } } -fn fetch_bool_expr(expr: &Expr) -> Expression { +fn fetch_bool_expr(expr: &Expr<'_>) -> Expression { match expr.kind { ExprKind::Block(ref block, _) => fetch_bool_block(block), ExprKind::Lit(ref lit_ptr) => { diff --git a/clippy_lints/src/needless_borrow.rs b/clippy_lints/src/needless_borrow.rs index 6e18501480b6..a74b6dbf317c 100644 --- a/clippy_lints/src/needless_borrow.rs +++ b/clippy_lints/src/needless_borrow.rs @@ -38,7 +38,7 @@ pub struct NeedlessBorrow { impl_lint_pass!(NeedlessBorrow => [NEEDLESS_BORROW]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessBorrow { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) { + fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) { if e.span.from_expansion() || self.derived_item.is_some() { return; } @@ -76,7 +76,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessBorrow { } } } - fn check_pat(&mut self, cx: &LateContext<'a, 'tcx>, pat: &'tcx Pat) { + fn check_pat(&mut self, cx: &LateContext<'a, 'tcx>, pat: &'tcx Pat<'_>) { if pat.span.from_expansion() || self.derived_item.is_some() { return; } diff --git a/clippy_lints/src/needless_borrowed_ref.rs b/clippy_lints/src/needless_borrowed_ref.rs index e9b7aa4a7efa..bf7e44a1fcc3 100644 --- a/clippy_lints/src/needless_borrowed_ref.rs +++ b/clippy_lints/src/needless_borrowed_ref.rs @@ -54,7 +54,7 @@ declare_clippy_lint! { declare_lint_pass!(NeedlessBorrowedRef => [NEEDLESS_BORROWED_REFERENCE]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessBorrowedRef { - fn check_pat(&mut self, cx: &LateContext<'a, 'tcx>, pat: &'tcx Pat) { + fn check_pat(&mut self, cx: &LateContext<'a, 'tcx>, pat: &'tcx Pat<'_>) { if pat.span.from_expansion() { // OK, simple enough, lints doesn't check in macro. return; diff --git a/clippy_lints/src/needless_update.rs b/clippy_lints/src/needless_update.rs index 77483bc12808..dfcba2904215 100644 --- a/clippy_lints/src/needless_update.rs +++ b/clippy_lints/src/needless_update.rs @@ -36,7 +36,7 @@ declare_clippy_lint! { declare_lint_pass!(NeedlessUpdate => [NEEDLESS_UPDATE]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessUpdate { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { + fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { if let ExprKind::Struct(_, ref fields, Some(ref base)) = expr.kind { let ty = cx.tables.expr_ty(expr); if let ty::Adt(def, _) = ty.kind { diff --git a/clippy_lints/src/neg_cmp_op_on_partial_ord.rs b/clippy_lints/src/neg_cmp_op_on_partial_ord.rs index 432d2552f2fe..4e6bcc6f1d91 100644 --- a/clippy_lints/src/neg_cmp_op_on_partial_ord.rs +++ b/clippy_lints/src/neg_cmp_op_on_partial_ord.rs @@ -46,7 +46,7 @@ declare_clippy_lint! { declare_lint_pass!(NoNegCompOpForPartialOrd => [NEG_CMP_OP_ON_PARTIAL_ORD]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NoNegCompOpForPartialOrd { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { + fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { if_chain! { if !in_external_macro(cx.sess(), expr.span); diff --git a/clippy_lints/src/neg_multiply.rs b/clippy_lints/src/neg_multiply.rs index 6b76479ceddb..fbdf5d8c132b 100644 --- a/clippy_lints/src/neg_multiply.rs +++ b/clippy_lints/src/neg_multiply.rs @@ -28,7 +28,7 @@ declare_lint_pass!(NegMultiply => [NEG_MULTIPLY]); #[allow(clippy::match_same_arms)] impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NegMultiply { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) { + fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) { if let ExprKind::Binary(ref op, ref left, ref right) = e.kind { if BinOpKind::Mul == op.node { match (&left.kind, &right.kind) { @@ -42,7 +42,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NegMultiply { } } -fn check_mul(cx: &LateContext<'_, '_>, span: Span, lit: &Expr, exp: &Expr) { +fn check_mul(cx: &LateContext<'_, '_>, span: Span, lit: &Expr<'_>, exp: &Expr<'_>) { if_chain! { if let ExprKind::Lit(ref l) = lit.kind; if let Constant::Int(1) = consts::lit_to_constant(&l.node, cx.tables.expr_ty_opt(lit)); diff --git a/clippy_lints/src/no_effect.rs b/clippy_lints/src/no_effect.rs index 8ce4f1a78b0b..afd0be851d8a 100644 --- a/clippy_lints/src/no_effect.rs +++ b/clippy_lints/src/no_effect.rs @@ -43,7 +43,7 @@ declare_clippy_lint! { "outer expressions with no effect" } -fn has_no_effect(cx: &LateContext<'_, '_>, expr: &Expr) -> bool { +fn has_no_effect(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool { if expr.span.from_expansion() { return false; } @@ -89,7 +89,7 @@ fn has_no_effect(cx: &LateContext<'_, '_>, expr: &Expr) -> bool { declare_lint_pass!(NoEffect => [NO_EFFECT, UNNECESSARY_OPERATION]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NoEffect { - fn check_stmt(&mut self, cx: &LateContext<'a, 'tcx>, stmt: &'tcx Stmt) { + fn check_stmt(&mut self, cx: &LateContext<'a, 'tcx>, stmt: &'tcx Stmt<'_>) { if let StmtKind::Semi(ref expr) = stmt.kind { if has_no_effect(cx, expr) { span_lint(cx, NO_EFFECT, stmt.span, "statement with no effect"); @@ -120,7 +120,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NoEffect { } } -fn reduce_expression<'a>(cx: &LateContext<'_, '_>, expr: &'a Expr) -> Option> { +fn reduce_expression<'a>(cx: &LateContext<'_, '_>, expr: &'a Expr<'a>) -> Option>> { if expr.span.from_expansion() { return None; } diff --git a/clippy_lints/src/non_copy_const.rs b/clippy_lints/src/non_copy_const.rs index 40f1c2917165..b454cfbac671 100644 --- a/clippy_lints/src/non_copy_const.rs +++ b/clippy_lints/src/non_copy_const.rs @@ -183,7 +183,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonCopyConst { } } - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { + fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { if let ExprKind::Path(qpath) = &expr.kind { // Only lint if we use the const item inside a function. if in_constant(cx, expr.hir_id) { diff --git a/clippy_lints/src/ok_if_let.rs b/clippy_lints/src/ok_if_let.rs index 6a9c7288f692..e02cc395d810 100644 --- a/clippy_lints/src/ok_if_let.rs +++ b/clippy_lints/src/ok_if_let.rs @@ -38,7 +38,7 @@ declare_clippy_lint! { declare_lint_pass!(OkIfLet => [IF_LET_SOME_RESULT]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for OkIfLet { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { + fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { if_chain! { //begin checking variables if let ExprKind::Match(ref op, ref body, ref source) = expr.kind; //test if expr is a match if let MatchSource::IfLetDesugar { .. } = *source; //test if it is an If Let diff --git a/clippy_lints/src/open_options.rs b/clippy_lints/src/open_options.rs index 03261cdd7138..545def3567e0 100644 --- a/clippy_lints/src/open_options.rs +++ b/clippy_lints/src/open_options.rs @@ -29,7 +29,7 @@ declare_clippy_lint! { declare_lint_pass!(OpenOptions => [NONSENSICAL_OPEN_OPTIONS]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for OpenOptions { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) { + fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) { if let ExprKind::MethodCall(ref path, _, ref arguments) = e.kind { let obj_ty = walk_ptrs_ty(cx.tables.expr_ty(&arguments[0])); if path.ident.name == sym!(open) && match_type(cx, obj_ty, &paths::OPEN_OPTIONS) { @@ -57,7 +57,7 @@ enum OpenOption { Append, } -fn get_open_options(cx: &LateContext<'_, '_>, argument: &Expr, options: &mut Vec<(OpenOption, Argument)>) { +fn get_open_options(cx: &LateContext<'_, '_>, argument: &Expr<'_>, options: &mut Vec<(OpenOption, Argument)>) { if let ExprKind::MethodCall(ref path, _, ref arguments) = argument.kind { let obj_ty = walk_ptrs_ty(cx.tables.expr_ty(&arguments[0])); diff --git a/clippy_lints/src/overflow_check_conditional.rs b/clippy_lints/src/overflow_check_conditional.rs index 749d0e97975f..4c67539f62b3 100644 --- a/clippy_lints/src/overflow_check_conditional.rs +++ b/clippy_lints/src/overflow_check_conditional.rs @@ -28,7 +28,7 @@ declare_lint_pass!(OverflowCheckConditional => [OVERFLOW_CHECK_CONDITIONAL]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for OverflowCheckConditional { // a + b < a, a > a + b, a < a - b, a - b > a - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { + fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { let eq = |l, r| SpanlessEq::new(cx).eq_path_segment(l, r); if_chain! { if let ExprKind::Binary(ref op, ref first, ref second) = expr.kind; diff --git a/clippy_lints/src/panic_unimplemented.rs b/clippy_lints/src/panic_unimplemented.rs index cb6d92534ee2..e63bfd0135fb 100644 --- a/clippy_lints/src/panic_unimplemented.rs +++ b/clippy_lints/src/panic_unimplemented.rs @@ -93,7 +93,7 @@ declare_clippy_lint! { declare_lint_pass!(PanicUnimplemented => [PANIC_PARAMS, UNIMPLEMENTED, UNREACHABLE, TODO, PANIC]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PanicUnimplemented { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { + fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { if_chain! { if let ExprKind::Block(ref block, _) = expr.kind; if let Some(ref ex) = block.expr; @@ -123,7 +123,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PanicUnimplemented { } } -fn get_outer_span(expr: &Expr) -> Span { +fn get_outer_span(expr: &Expr<'_>) -> Span { if_chain! { if expr.span.from_expansion(); let first = expr.span.ctxt().outer_expn_data(); @@ -137,7 +137,7 @@ fn get_outer_span(expr: &Expr) -> Span { } } -fn match_panic(params: &[Expr], expr: &Expr, cx: &LateContext<'_, '_>) { +fn match_panic(params: &[Expr<'_>], expr: &Expr<'_>, cx: &LateContext<'_, '_>) { if_chain! { if let ExprKind::Lit(ref lit) = params[0].kind; if is_direct_expn_of(expr.span, "panic").is_some(); diff --git a/clippy_lints/src/path_buf_push_overwrite.rs b/clippy_lints/src/path_buf_push_overwrite.rs index 4c7d2eedda26..2a9d31ec937e 100644 --- a/clippy_lints/src/path_buf_push_overwrite.rs +++ b/clippy_lints/src/path_buf_push_overwrite.rs @@ -42,7 +42,7 @@ declare_clippy_lint! { declare_lint_pass!(PathBufPushOverwrite => [PATH_BUF_PUSH_OVERWRITE]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PathBufPushOverwrite { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { + fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { if_chain! { if let ExprKind::MethodCall(ref path, _, ref args) = expr.kind; if path.ident.name == sym!(push); diff --git a/clippy_lints/src/ptr.rs b/clippy_lints/src/ptr.rs index c741c43bc99a..609b3bbc1c2c 100644 --- a/clippy_lints/src/ptr.rs +++ b/clippy_lints/src/ptr.rs @@ -130,7 +130,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Ptr { } } - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { + fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { if let ExprKind::Binary(ref op, ref l, ref r) = expr.kind { if (op.node == BinOpKind::Eq || op.node == BinOpKind::Ne) && (is_null_path(l) || is_null_path(r)) { span_lint( @@ -293,7 +293,7 @@ fn get_rptr_lm(ty: &Ty) -> Option<(&Lifetime, Mutability, Span)> { } } -fn is_null_path(expr: &Expr) -> bool { +fn is_null_path(expr: &Expr<'_>) -> bool { if let ExprKind::Call(ref pathexp, ref args) = expr.kind { if args.is_empty() { if let ExprKind::Path(ref path) = pathexp.kind { diff --git a/clippy_lints/src/ptr_offset_with_cast.rs b/clippy_lints/src/ptr_offset_with_cast.rs index f454e5ac2c35..f7c42c356bee 100644 --- a/clippy_lints/src/ptr_offset_with_cast.rs +++ b/clippy_lints/src/ptr_offset_with_cast.rs @@ -45,7 +45,7 @@ declare_clippy_lint! { declare_lint_pass!(PtrOffsetWithCast => [PTR_OFFSET_WITH_CAST]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PtrOffsetWithCast { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { + fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { // Check if the expressions is a ptr.offset or ptr.wrapping_offset method call let (receiver_expr, arg_expr, method) = match expr_as_ptr_offset_call(cx, expr) { Some(call_arg) => call_arg, @@ -76,7 +76,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PtrOffsetWithCast { } // If the given expression is a cast from a usize, return the lhs of the cast -fn expr_as_cast_from_usize<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) -> Option<&'tcx Expr> { +fn expr_as_cast_from_usize<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'tcx>) -> Option<&'tcx Expr<'tcx>> { if let ExprKind::Cast(ref cast_lhs_expr, _) = expr.kind { if is_expr_ty_usize(cx, &cast_lhs_expr) { return Some(cast_lhs_expr); @@ -89,8 +89,8 @@ fn expr_as_cast_from_usize<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Exp // receiver, the arg of the method call, and the method. fn expr_as_ptr_offset_call<'a, 'tcx>( cx: &LateContext<'a, 'tcx>, - expr: &'tcx Expr, -) -> Option<(&'tcx Expr, &'tcx Expr, Method)> { + expr: &'tcx Expr<'_>, +) -> Option<(&'tcx Expr<'tcx>, &'tcx Expr<'tcx>, Method)> { if let ExprKind::MethodCall(ref path_segment, _, ref args) = expr.kind { if is_expr_ty_raw_ptr(cx, &args[0]) { if path_segment.ident.name == sym!(offset) { @@ -105,20 +105,20 @@ fn expr_as_ptr_offset_call<'a, 'tcx>( } // Is the type of the expression a usize? -fn is_expr_ty_usize<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &Expr) -> bool { +fn is_expr_ty_usize<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &Expr<'_>) -> bool { cx.tables.expr_ty(expr) == cx.tcx.types.usize } // Is the type of the expression a raw pointer? -fn is_expr_ty_raw_ptr<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &Expr) -> bool { +fn is_expr_ty_raw_ptr<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &Expr<'_>) -> bool { cx.tables.expr_ty(expr).is_unsafe_ptr() } fn build_suggestion<'a, 'tcx>( cx: &LateContext<'a, 'tcx>, method: Method, - receiver_expr: &Expr, - cast_lhs_expr: &Expr, + receiver_expr: &Expr<'_>, + cast_lhs_expr: &Expr<'_>, ) -> Option { let receiver = utils::snippet_opt(cx, receiver_expr.span)?; let cast_lhs = utils::snippet_opt(cx, cast_lhs_expr.span)?; diff --git a/clippy_lints/src/question_mark.rs b/clippy_lints/src/question_mark.rs index ccd3208912ab..cd06dad3a813 100644 --- a/clippy_lints/src/question_mark.rs +++ b/clippy_lints/src/question_mark.rs @@ -1,7 +1,6 @@ use if_chain::if_chain; use rustc::declare_lint_pass; use rustc::hir::def::{DefKind, Res}; -use rustc::hir::ptr::P; use rustc::hir::*; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; use rustc_errors::Applicability; @@ -47,7 +46,7 @@ impl QuestionMark { /// ``` /// /// If it matches, it will suggest to use the question mark operator instead - fn check_is_none_and_early_return_none(cx: &LateContext<'_, '_>, expr: &Expr) { + fn check_is_none_and_early_return_none(cx: &LateContext<'_, '_>, expr: &Expr<'_>) { if_chain! { if let Some((if_expr, body, else_)) = higher::if_block(&expr); if let ExprKind::MethodCall(segment, _, args) = &if_expr.kind; @@ -62,7 +61,7 @@ impl QuestionMark { if let Some(else_) = else_ { if_chain! { if let ExprKind::Block(block, None) = &else_.kind; - if block.stmts.len() == 0; + if block.stmts.is_empty(); if let Some(block_expr) = &block.expr; if SpanlessEq::new(cx).ignore_fn().eq_expr(subject, block_expr); then { @@ -95,19 +94,19 @@ impl QuestionMark { } } - fn moves_by_default(cx: &LateContext<'_, '_>, expression: &Expr) -> bool { + fn moves_by_default(cx: &LateContext<'_, '_>, expression: &Expr<'_>) -> bool { let expr_ty = cx.tables.expr_ty(expression); !expr_ty.is_copy_modulo_regions(cx.tcx, cx.param_env, expression.span) } - fn is_option(cx: &LateContext<'_, '_>, expression: &Expr) -> bool { + fn is_option(cx: &LateContext<'_, '_>, expression: &Expr<'_>) -> bool { let expr_ty = cx.tables.expr_ty(expression); match_type(cx, expr_ty, &OPTION) } - fn expression_returns_none(cx: &LateContext<'_, '_>, expression: &Expr) -> bool { + fn expression_returns_none(cx: &LateContext<'_, '_>, expression: &Expr<'_>) -> bool { match expression.kind { ExprKind::Block(ref block, _) => { if let Some(return_expression) = Self::return_expression(block) { @@ -130,14 +129,14 @@ impl QuestionMark { } } - fn return_expression(block: &Block) -> Option<&P> { + fn return_expression<'tcx>(block: &Block<'tcx>) -> Option<&'tcx Expr<'tcx>> { // Check if last expression is a return statement. Then, return the expression if_chain! { if block.stmts.len() == 1; if let Some(expr) = block.stmts.iter().last(); if let StmtKind::Semi(ref expr) = expr.kind; - if let ExprKind::Ret(ref ret_expr) = expr.kind; - if let &Some(ref ret_expr) = ret_expr; + if let ExprKind::Ret(ret_expr) = expr.kind; + if let Some(ret_expr) = ret_expr; then { return Some(ret_expr); @@ -146,7 +145,7 @@ impl QuestionMark { // Check for `return` without a semicolon. if_chain! { - if block.stmts.len() == 0; + if block.stmts.is_empty(); if let Some(ExprKind::Ret(Some(ret_expr))) = block.expr.as_ref().map(|e| &e.kind); then { return Some(ret_expr); @@ -158,7 +157,7 @@ impl QuestionMark { } impl<'a, 'tcx> LateLintPass<'a, 'tcx> for QuestionMark { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { + fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { Self::check_is_none_and_early_return_none(cx, expr); } } diff --git a/clippy_lints/src/ranges.rs b/clippy_lints/src/ranges.rs index 6a16adf71dc1..11cb1d398503 100644 --- a/clippy_lints/src/ranges.rs +++ b/clippy_lints/src/ranges.rs @@ -88,7 +88,7 @@ declare_lint_pass!(Ranges => [ ]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Ranges { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { + fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { if let ExprKind::MethodCall(ref path, _, ref args) = expr.kind { let name = path.ident.as_str(); if name == "zip" && args.len() == 2 { @@ -125,7 +125,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Ranges { } // exclusive range plus one: `x..(y+1)` -fn check_exclusive_range_plus_one(cx: &LateContext<'_, '_>, expr: &Expr) { +fn check_exclusive_range_plus_one(cx: &LateContext<'_, '_>, expr: &Expr<'_>) { if_chain! { if let Some(higher::Range { start, @@ -174,7 +174,7 @@ fn check_exclusive_range_plus_one(cx: &LateContext<'_, '_>, expr: &Expr) { } // inclusive range minus one: `x..=(y-1)` -fn check_inclusive_range_minus_one(cx: &LateContext<'_, '_>, expr: &Expr) { +fn check_inclusive_range_minus_one(cx: &LateContext<'_, '_>, expr: &Expr<'_>) { if_chain! { if let Some(higher::Range { start, end: Some(end), limits: RangeLimits::Closed }) = higher::range(cx, expr); if let Some(y) = y_minus_one(cx, end); @@ -199,7 +199,7 @@ fn check_inclusive_range_minus_one(cx: &LateContext<'_, '_>, expr: &Expr) { } } -fn y_plus_one<'t>(cx: &LateContext<'_, '_>, expr: &'t Expr) -> Option<&'t Expr> { +fn y_plus_one<'t>(cx: &LateContext<'_, '_>, expr: &'t Expr<'_>) -> Option<&'t Expr<'t>> { match expr.kind { ExprKind::Binary( Spanned { @@ -220,7 +220,7 @@ fn y_plus_one<'t>(cx: &LateContext<'_, '_>, expr: &'t Expr) -> Option<&'t Expr> } } -fn y_minus_one<'t>(cx: &LateContext<'_, '_>, expr: &'t Expr) -> Option<&'t Expr> { +fn y_minus_one<'t>(cx: &LateContext<'_, '_>, expr: &'t Expr<'_>) -> Option<&'t Expr<'t>> { match expr.kind { ExprKind::Binary( Spanned { diff --git a/clippy_lints/src/redundant_pattern_matching.rs b/clippy_lints/src/redundant_pattern_matching.rs index e36237ab239e..cd0d6c8cda77 100644 --- a/clippy_lints/src/redundant_pattern_matching.rs +++ b/clippy_lints/src/redundant_pattern_matching.rs @@ -1,6 +1,5 @@ use crate::utils::{match_qpath, paths, snippet, span_lint_and_then}; use rustc::declare_lint_pass; -use rustc::hir::ptr::P; use rustc::hir::*; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; use rustc_errors::Applicability; @@ -46,8 +45,8 @@ declare_clippy_lint! { declare_lint_pass!(RedundantPatternMatching => [REDUNDANT_PATTERN_MATCHING]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for RedundantPatternMatching { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { - if let ExprKind::Match(ref op, ref arms, ref match_source) = expr.kind { + fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { + if let ExprKind::Match(op, arms, ref match_source) = &expr.kind { match match_source { MatchSource::Normal => find_sugg_for_match(cx, expr, op, arms), MatchSource::IfLetDesugar { contains_else_clause } => { @@ -61,9 +60,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for RedundantPatternMatching { fn find_sugg_for_if_let<'a, 'tcx>( cx: &LateContext<'a, 'tcx>, - expr: &'tcx Expr, - op: &P, - arms: &HirVec, + expr: &'tcx Expr<'_>, + op: &Expr<'_>, + arms: &[Arm<'_>], has_else: bool, ) { let good_method = match arms[0].pat.kind { @@ -107,7 +106,7 @@ fn find_sugg_for_if_let<'a, 'tcx>( ); } -fn find_sugg_for_match<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr, op: &P, arms: &HirVec) { +fn find_sugg_for_match<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>, op: &Expr<'_>, arms: &[Arm<'_>]) { if arms.len() == 2 { let node_pair = (&arms[0].pat.kind, &arms[1].pat.kind); @@ -172,7 +171,7 @@ fn find_sugg_for_match<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr, o } fn find_good_method_for_match<'a>( - arms: &HirVec, + arms: &[Arm<'_>], path_left: &QPath, path_right: &QPath, expected_left: &[&str], diff --git a/clippy_lints/src/regex.rs b/clippy_lints/src/regex.rs index c60912ddb2ca..76a317d7505a 100644 --- a/clippy_lints/src/regex.rs +++ b/clippy_lints/src/regex.rs @@ -79,7 +79,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Regex { self.spans.clear(); } - fn check_block(&mut self, cx: &LateContext<'a, 'tcx>, block: &'tcx Block) { + fn check_block(&mut self, cx: &LateContext<'a, 'tcx>, block: &'tcx Block<'_>) { if_chain! { if self.last.is_none(); if let Some(ref expr) = block.expr; @@ -99,13 +99,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Regex { } } - fn check_block_post(&mut self, _: &LateContext<'a, 'tcx>, block: &'tcx Block) { + fn check_block_post(&mut self, _: &LateContext<'a, 'tcx>, block: &'tcx Block<'_>) { if self.last.map_or(false, |id| block.hir_id == id) { self.last = None; } } - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { + fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { if_chain! { if let ExprKind::Call(ref fun, ref args) = expr.kind; if let ExprKind::Path(ref qpath) = fun.kind; @@ -138,7 +138,7 @@ fn str_span(base: Span, c: regex_syntax::ast::Span, offset: u16) -> Span { Span::new(start, end, base.ctxt()) } -fn const_str<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) -> Option { +fn const_str<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) -> Option { constant(cx, cx.tables, e).and_then(|(c, _)| match c { Constant::Str(s) => Some(s), _ => None, @@ -184,10 +184,10 @@ fn is_trivial_regex(s: ®ex_syntax::hir::Hir) -> Option<&'static str> { } } -fn check_set<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr, utf8: bool) { +fn check_set<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>, utf8: bool) { if_chain! { if let ExprKind::AddrOf(BorrowKind::Ref, _, ref expr) = expr.kind; - if let ExprKind::Array(ref exprs) = expr.kind; + if let ExprKind::Array(exprs) = expr.kind; then { for expr in exprs { check_regex(cx, expr, utf8); @@ -196,7 +196,7 @@ fn check_set<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr, utf8: bool) } } -fn check_regex<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr, utf8: bool) { +fn check_regex<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>, utf8: bool) { let mut parser = regex_syntax::ParserBuilder::new() .unicode(utf8) .allow_invalid_utf8(!utf8) diff --git a/clippy_lints/src/replace_consts.rs b/clippy_lints/src/replace_consts.rs index 3cca42ce03fa..b1224eaa7a43 100644 --- a/clippy_lints/src/replace_consts.rs +++ b/clippy_lints/src/replace_consts.rs @@ -35,7 +35,7 @@ declare_clippy_lint! { declare_lint_pass!(ReplaceConsts => [REPLACE_CONSTS]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ReplaceConsts { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) { + fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr<'_>) { if_chain! { if let hir::ExprKind::Path(ref qp) = expr.kind; if let Res::Def(DefKind::Const, def_id) = cx.tables.qpath_res(qp, expr.hir_id); diff --git a/clippy_lints/src/shadow.rs b/clippy_lints/src/shadow.rs index cfb1900bb3cf..f1a10a4ae840 100644 --- a/clippy_lints/src/shadow.rs +++ b/clippy_lints/src/shadow.rs @@ -110,9 +110,9 @@ fn check_fn<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, decl: &'tcx FnDecl, body: &'tc check_expr(cx, &body.value, &mut bindings); } -fn check_block<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, block: &'tcx Block, bindings: &mut Vec<(Name, Span)>) { +fn check_block<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, block: &'tcx Block<'_>, bindings: &mut Vec<(Name, Span)>) { let len = bindings.len(); - for stmt in &block.stmts { + for stmt in block.stmts { match stmt.kind { StmtKind::Local(ref local) => check_local(cx, local, bindings), StmtKind::Expr(ref e) | StmtKind::Semi(ref e) => check_expr(cx, e, bindings), @@ -125,7 +125,7 @@ fn check_block<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, block: &'tcx Block, binding bindings.truncate(len); } -fn check_local<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, local: &'tcx Local, bindings: &mut Vec<(Name, Span)>) { +fn check_local<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, local: &'tcx Local<'_>, bindings: &mut Vec<(Name, Span)>) { if in_external_macro(cx.sess(), local.span) { return; } @@ -160,8 +160,8 @@ fn is_binding(cx: &LateContext<'_, '_>, pat_id: HirId) -> bool { fn check_pat<'a, 'tcx>( cx: &LateContext<'a, 'tcx>, - pat: &'tcx Pat, - init: Option<&'tcx Expr>, + pat: &'tcx Pat<'_>, + init: Option<&'tcx Expr<'_>>, span: Span, bindings: &mut Vec<(Name, Span)>, ) { @@ -187,7 +187,7 @@ fn check_pat<'a, 'tcx>( check_pat(cx, p, init, span, bindings); } }, - PatKind::Struct(_, ref pfields, _) => { + PatKind::Struct(_, pfields, _) => { if let Some(init_struct) = init { if let ExprKind::Struct(_, ref efields, _) = init_struct.kind { for field in pfields { @@ -208,7 +208,7 @@ fn check_pat<'a, 'tcx>( } } }, - PatKind::Tuple(ref inner, _) => { + PatKind::Tuple(inner, _) => { if let Some(init_tup) = init { if let ExprKind::Tup(ref tup) = init_tup.kind { for (i, p) in inner.iter().enumerate() { @@ -247,7 +247,7 @@ fn lint_shadow<'a, 'tcx>( name: Name, span: Span, pattern_span: Span, - init: Option<&'tcx Expr>, + init: Option<&'tcx Expr<'_>>, prev_span: Span, ) { if let Some(expr) = init { @@ -309,7 +309,7 @@ fn lint_shadow<'a, 'tcx>( } } -fn check_expr<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr, bindings: &mut Vec<(Name, Span)>) { +fn check_expr<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>, bindings: &mut Vec<(Name, Span)>) { if in_external_macro(cx.sess(), expr.span) { return; } @@ -321,12 +321,12 @@ fn check_expr<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr, bindings: ExprKind::Block(ref block, _) | ExprKind::Loop(ref block, _, _) => check_block(cx, block, bindings), // ExprKind::Call // ExprKind::MethodCall - ExprKind::Array(ref v) | ExprKind::Tup(ref v) => { + ExprKind::Array(v) | ExprKind::Tup(v) => { for e in v { check_expr(cx, e, bindings) } }, - ExprKind::Match(ref init, ref arms, _) => { + ExprKind::Match(ref init, arms, _) => { check_expr(cx, init, bindings); let len = bindings.len(); for arm in arms { @@ -365,7 +365,7 @@ fn check_ty<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: &'tcx Ty, bindings: &mut V } } -fn is_self_shadow(name: Name, expr: &Expr) -> bool { +fn is_self_shadow(name: Name, expr: &Expr<'_>) -> bool { match expr.kind { ExprKind::Box(ref inner) | ExprKind::AddrOf(_, _, ref inner) => is_self_shadow(name, inner), ExprKind::Block(ref block, _) => { diff --git a/clippy_lints/src/slow_vector_initialization.rs b/clippy_lints/src/slow_vector_initialization.rs index 093b99e17f17..03becd1c7c10 100644 --- a/clippy_lints/src/slow_vector_initialization.rs +++ b/clippy_lints/src/slow_vector_initialization.rs @@ -43,24 +43,24 @@ struct VecAllocation<'tcx> { variable_name: Symbol, /// Reference to the expression which allocates the vector - allocation_expr: &'tcx Expr, + allocation_expr: &'tcx Expr<'tcx>, /// Reference to the expression used as argument on `with_capacity` call. This is used /// to only match slow zero-filling idioms of the same length than vector initialization. - len_expr: &'tcx Expr, + len_expr: &'tcx Expr<'tcx>, } /// Type of slow initialization enum InitializationType<'tcx> { /// Extend is a slow initialization with the form `vec.extend(repeat(0).take(..))` - Extend(&'tcx Expr), + Extend(&'tcx Expr<'tcx>), /// Resize is a slow initialization with the form `vec.resize(.., 0)` - Resize(&'tcx Expr), + Resize(&'tcx Expr<'tcx>), } impl<'a, 'tcx> LateLintPass<'a, 'tcx> for SlowVectorInit { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { + fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { // Matches initialization on reassignements. For example: `vec = Vec::with_capacity(100)` if_chain! { if let ExprKind::Assign(ref left, ref right, _) = expr.kind; @@ -84,7 +84,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for SlowVectorInit { } } - fn check_stmt(&mut self, cx: &LateContext<'a, 'tcx>, stmt: &'tcx Stmt) { + fn check_stmt(&mut self, cx: &LateContext<'a, 'tcx>, stmt: &'tcx Stmt<'_>) { // Matches statements which initializes vectors. For example: `let mut vec = Vec::with_capacity(10)` if_chain! { if let StmtKind::Local(ref local) = stmt.kind; @@ -108,7 +108,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for SlowVectorInit { impl SlowVectorInit { /// Checks if the given expression is `Vec::with_capacity(..)`. It will return the expression /// of the first argument of `with_capacity` call if it matches or `None` if it does not. - fn is_vec_with_capacity(expr: &Expr) -> Option<&Expr> { + fn is_vec_with_capacity<'tcx>(expr: &Expr<'tcx>) -> Option<&'tcx Expr<'tcx>> { if_chain! { if let ExprKind::Call(ref func, ref args) = expr.kind; if let ExprKind::Path(ref path) = func.kind; @@ -163,7 +163,7 @@ impl SlowVectorInit { fn emit_lint<'tcx>( cx: &LateContext<'_, 'tcx>, - slow_fill: &Expr, + slow_fill: &Expr<'_>, vec_alloc: &VecAllocation<'_>, msg: &str, lint: &'static Lint, @@ -198,7 +198,7 @@ struct VectorInitializationVisitor<'a, 'tcx> { impl<'a, 'tcx> VectorInitializationVisitor<'a, 'tcx> { /// Checks if the given expression is extending a vector with `repeat(0).take(..)` - fn search_slow_extend_filling(&mut self, expr: &'tcx Expr) { + fn search_slow_extend_filling(&mut self, expr: &'tcx Expr<'_>) { if_chain! { if self.initialization_found; if let ExprKind::MethodCall(ref path, _, ref args) = expr.kind; @@ -215,7 +215,7 @@ impl<'a, 'tcx> VectorInitializationVisitor<'a, 'tcx> { } /// Checks if the given expression is resizing a vector with 0 - fn search_slow_resize_filling(&mut self, expr: &'tcx Expr) { + fn search_slow_resize_filling(&mut self, expr: &'tcx Expr<'_>) { if_chain! { if self.initialization_found; if let ExprKind::MethodCall(ref path, _, ref args) = expr.kind; @@ -238,7 +238,7 @@ impl<'a, 'tcx> VectorInitializationVisitor<'a, 'tcx> { } /// Returns `true` if give expression is `repeat(0).take(...)` - fn is_repeat_take(&self, expr: &Expr) -> bool { + fn is_repeat_take(&self, expr: &Expr<'_>) -> bool { if_chain! { if let ExprKind::MethodCall(ref take_path, _, ref take_args) = expr.kind; if take_path.ident.name == sym!(take); @@ -260,7 +260,7 @@ impl<'a, 'tcx> VectorInitializationVisitor<'a, 'tcx> { } /// Returns `true` if given expression is `repeat(0)` - fn is_repeat_zero(expr: &Expr) -> bool { + fn is_repeat_zero(expr: &Expr<'_>) -> bool { if_chain! { if let ExprKind::Call(ref fn_expr, ref repeat_args) = expr.kind; if let ExprKind::Path(ref qpath_repeat) = fn_expr.kind; @@ -279,7 +279,7 @@ impl<'a, 'tcx> VectorInitializationVisitor<'a, 'tcx> { } impl<'a, 'tcx> Visitor<'tcx> for VectorInitializationVisitor<'a, 'tcx> { - fn visit_stmt(&mut self, stmt: &'tcx Stmt) { + fn visit_stmt(&mut self, stmt: &'tcx Stmt<'_>) { if self.initialization_found { match stmt.kind { StmtKind::Expr(ref expr) | StmtKind::Semi(ref expr) => { @@ -295,7 +295,7 @@ impl<'a, 'tcx> Visitor<'tcx> for VectorInitializationVisitor<'a, 'tcx> { } } - fn visit_block(&mut self, block: &'tcx Block) { + fn visit_block(&mut self, block: &'tcx Block<'_>) { if self.initialization_found { if let Some(ref s) = block.stmts.get(0) { self.visit_stmt(s) @@ -307,7 +307,7 @@ impl<'a, 'tcx> Visitor<'tcx> for VectorInitializationVisitor<'a, 'tcx> { } } - fn visit_expr(&mut self, expr: &'tcx Expr) { + fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { // Skip all the expressions previous to the vector initialization if self.vec_alloc.allocation_expr.hir_id == expr.hir_id { self.initialization_found = true; diff --git a/clippy_lints/src/strings.rs b/clippy_lints/src/strings.rs index 7b1be6f8c7cf..46c3e50140f0 100644 --- a/clippy_lints/src/strings.rs +++ b/clippy_lints/src/strings.rs @@ -79,7 +79,7 @@ declare_clippy_lint! { declare_lint_pass!(StringAdd => [STRING_ADD, STRING_ADD_ASSIGN]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for StringAdd { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) { + fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) { if in_external_macro(cx.sess(), e.span) { return; } @@ -125,11 +125,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for StringAdd { } } -fn is_string(cx: &LateContext<'_, '_>, e: &Expr) -> bool { +fn is_string(cx: &LateContext<'_, '_>, e: &Expr<'_>) -> bool { match_type(cx, walk_ptrs_ty(cx.tables.expr_ty(e)), &paths::STRING) } -fn is_add(cx: &LateContext<'_, '_>, src: &Expr, target: &Expr) -> bool { +fn is_add(cx: &LateContext<'_, '_>, src: &Expr<'_>, target: &Expr<'_>) -> bool { match src.kind { ExprKind::Binary( Spanned { @@ -151,7 +151,7 @@ const MAX_LENGTH_BYTE_STRING_LIT: usize = 32; declare_lint_pass!(StringLitAsBytes => [STRING_LIT_AS_BYTES]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for StringLitAsBytes { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) { + fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) { use crate::utils::{snippet, snippet_with_applicability}; use syntax::ast::LitKind; diff --git a/clippy_lints/src/suspicious_trait_impl.rs b/clippy_lints/src/suspicious_trait_impl.rs index b3520c181f6f..94ecb1459157 100644 --- a/clippy_lints/src/suspicious_trait_impl.rs +++ b/clippy_lints/src/suspicious_trait_impl.rs @@ -53,7 +53,7 @@ declare_clippy_lint! { declare_lint_pass!(SuspiciousImpl => [SUSPICIOUS_ARITHMETIC_IMPL, SUSPICIOUS_OP_ASSIGN_IMPL]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for SuspiciousImpl { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) { + fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr<'_>) { if let hir::ExprKind::Binary(binop, _, _) = expr.kind { match binop.node { hir::BinOpKind::Eq @@ -148,7 +148,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for SuspiciousImpl { fn check_binop( cx: &LateContext<'_, '_>, - expr: &hir::Expr, + expr: &hir::Expr<'_>, binop: hir::BinOpKind, traits: &[&'static str], expected_ops: &[hir::BinOpKind], @@ -185,7 +185,7 @@ struct BinaryExprVisitor { } impl<'a, 'tcx> Visitor<'tcx> for BinaryExprVisitor { - fn visit_expr(&mut self, expr: &'tcx hir::Expr) { + fn visit_expr(&mut self, expr: &'tcx hir::Expr<'_>) { match expr.kind { hir::ExprKind::Binary(..) | hir::ExprKind::Unary(hir::UnOp::UnNot, _) diff --git a/clippy_lints/src/swap.rs b/clippy_lints/src/swap.rs index 58b3f558e9c5..c4282dde585e 100644 --- a/clippy_lints/src/swap.rs +++ b/clippy_lints/src/swap.rs @@ -69,14 +69,14 @@ declare_clippy_lint! { declare_lint_pass!(Swap => [MANUAL_SWAP, ALMOST_SWAPPED]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Swap { - fn check_block(&mut self, cx: &LateContext<'a, 'tcx>, block: &'tcx Block) { + fn check_block(&mut self, cx: &LateContext<'a, 'tcx>, block: &'tcx Block<'_>) { check_manual_swap(cx, block); check_suspicious_swap(cx, block); } } /// Implementation of the `MANUAL_SWAP` lint. -fn check_manual_swap(cx: &LateContext<'_, '_>, block: &Block) { +fn check_manual_swap(cx: &LateContext<'_, '_>, block: &Block<'_>) { for w in block.stmts.windows(3) { if_chain! { // let t = foo(); @@ -176,7 +176,7 @@ enum Slice<'a> { /// // can be written as /// a.swap(0, 1); /// ``` - Swappable(&'a Expr, &'a Expr, &'a Expr), + Swappable(&'a Expr<'a>, &'a Expr<'a>, &'a Expr<'a>), /// The `swap` function cannot be used. /// /// ## Example @@ -193,7 +193,7 @@ enum Slice<'a> { } /// Checks if both expressions are index operations into "slice-like" types. -fn check_for_slice<'a>(cx: &LateContext<'_, '_>, lhs1: &'a Expr, lhs2: &'a Expr) -> Slice<'a> { +fn check_for_slice<'a>(cx: &LateContext<'_, '_>, lhs1: &'a Expr<'_>, lhs2: &'a Expr<'_>) -> Slice<'a> { if let ExprKind::Index(ref lhs1, ref idx1) = lhs1.kind { if let ExprKind::Index(ref lhs2, ref idx2) = lhs2.kind { if SpanlessEq::new(cx).ignore_fn().eq_expr(lhs1, lhs2) { @@ -216,7 +216,7 @@ fn check_for_slice<'a>(cx: &LateContext<'_, '_>, lhs1: &'a Expr, lhs2: &'a Expr) } /// Implementation of the `ALMOST_SWAPPED` lint. -fn check_suspicious_swap(cx: &LateContext<'_, '_>, block: &Block) { +fn check_suspicious_swap(cx: &LateContext<'_, '_>, block: &Block<'_>) { for w in block.stmts.windows(2) { if_chain! { if let StmtKind::Semi(ref first) = w[0].kind; diff --git a/clippy_lints/src/temporary_assignment.rs b/clippy_lints/src/temporary_assignment.rs index 4b0c4abc44e3..c7ae7b941144 100644 --- a/clippy_lints/src/temporary_assignment.rs +++ b/clippy_lints/src/temporary_assignment.rs @@ -24,7 +24,7 @@ declare_clippy_lint! { "assignments to temporaries" } -fn is_temporary(cx: &LateContext<'_, '_>, expr: &Expr) -> bool { +fn is_temporary(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool { match &expr.kind { ExprKind::Struct(..) | ExprKind::Tup(..) => true, ExprKind::Path(qpath) => { @@ -41,7 +41,7 @@ fn is_temporary(cx: &LateContext<'_, '_>, expr: &Expr) -> bool { declare_lint_pass!(TemporaryAssignment => [TEMPORARY_ASSIGNMENT]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TemporaryAssignment { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { + fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { if let ExprKind::Assign(target, ..) = &expr.kind { let mut base = target; while let ExprKind::Field(f, _) | ExprKind::Index(f, _) = &base.kind { diff --git a/clippy_lints/src/to_digit_is_some.rs b/clippy_lints/src/to_digit_is_some.rs index 250ddd5ad03d..ad8a4460953c 100644 --- a/clippy_lints/src/to_digit_is_some.rs +++ b/clippy_lints/src/to_digit_is_some.rs @@ -33,7 +33,7 @@ declare_clippy_lint! { declare_lint_pass!(ToDigitIsSome => [TO_DIGIT_IS_SOME]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ToDigitIsSome { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) { + fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr<'_>) { if_chain! { if let hir::ExprKind::MethodCall(is_some_path, _, is_some_args) = &expr.kind; if is_some_path.ident.name.as_str() == "is_some"; diff --git a/clippy_lints/src/transmute.rs b/clippy_lints/src/transmute.rs index bae64e85e7f5..637ed0746620 100644 --- a/clippy_lints/src/transmute.rs +++ b/clippy_lints/src/transmute.rs @@ -292,7 +292,7 @@ static COLLECTIONS: &[&[&str]] = &[ ]; impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute { #[allow(clippy::similar_names, clippy::too_many_lines)] - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) { + fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) { if_chain! { if let ExprKind::Call(ref path_expr, ref args) = e.kind; if let ExprKind::Path(ref qpath) = path_expr.kind; diff --git a/clippy_lints/src/transmuting_null.rs b/clippy_lints/src/transmuting_null.rs index 451725761fff..6438c79f99e8 100644 --- a/clippy_lints/src/transmuting_null.rs +++ b/clippy_lints/src/transmuting_null.rs @@ -30,7 +30,7 @@ declare_lint_pass!(TransmutingNull => [TRANSMUTING_NULL]); const LINT_MSG: &str = "transmuting a known null pointer into a reference."; impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TransmutingNull { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { + fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { if in_external_macro(cx.sess(), expr.span) { return; } @@ -72,7 +72,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TransmutingNull { if let ExprKind::Call(ref func1, ref args1) = args[0].kind; if let ExprKind::Path(ref path1) = func1.kind; if match_qpath(path1, &paths::STD_PTR_NULL); - if args1.len() == 0; + if args1.is_empty(); then { span_lint(cx, TRANSMUTING_NULL, expr.span, LINT_MSG) } diff --git a/clippy_lints/src/try_err.rs b/clippy_lints/src/try_err.rs index 8c3e755ef173..ef3c4b546c62 100644 --- a/clippy_lints/src/try_err.rs +++ b/clippy_lints/src/try_err.rs @@ -44,7 +44,7 @@ declare_clippy_lint! { declare_lint_pass!(TryErr => [TRY_ERR]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TryErr { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { + fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { // Looks for a structure like this: // match ::std::ops::Try::into_result(Err(5)) { // ::std::result::Result::Err(err) => @@ -97,7 +97,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TryErr { // In order to determine whether to suggest `.into()` or not, we need to find the error type the // function returns. To do that, we look for the From::from call (see tree above), and capture // its output type. -fn find_err_return_type<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx ExprKind) -> Option> { +fn find_err_return_type<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx ExprKind<'_>) -> Option> { if let ExprKind::Match(_, ref arms, MatchSource::TryDesugar) = expr { arms.iter().find_map(|ty| find_err_return_type_arm(cx, ty)) } else { @@ -106,7 +106,7 @@ fn find_err_return_type<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx ExprKi } // Check for From::from in one of the match arms. -fn find_err_return_type_arm<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, arm: &'tcx Arm) -> Option> { +fn find_err_return_type_arm<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, arm: &'tcx Arm<'_>) -> Option> { if_chain! { if let ExprKind::Ret(Some(ref err_ret)) = arm.body.kind; if let ExprKind::Call(ref from_error_path, ref from_error_args) = err_ret.kind; diff --git a/clippy_lints/src/types.rs b/clippy_lints/src/types.rs index 143262b21cfc..b435a95a4f8e 100644 --- a/clippy_lints/src/types.rs +++ b/clippy_lints/src/types.rs @@ -193,7 +193,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Types { } } - fn check_local(&mut self, cx: &LateContext<'_, '_>, local: &Local) { + fn check_local(&mut self, cx: &LateContext<'_, '_>, local: &Local<'_>) { if let Some(ref ty) = local.ty { check_ty(cx, ty, true); } @@ -462,7 +462,7 @@ declare_clippy_lint! { declare_lint_pass!(LetUnitValue => [LET_UNIT_VALUE]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetUnitValue { - fn check_stmt(&mut self, cx: &LateContext<'a, 'tcx>, stmt: &'tcx Stmt) { + fn check_stmt(&mut self, cx: &LateContext<'a, 'tcx>, stmt: &'tcx Stmt<'_>) { if let StmtKind::Local(ref local) = stmt.kind { if is_unit(cx.tables.pat_ty(&local.pat)) { if in_external_macro(cx.sess(), stmt.span) || local.pat.span.from_expansion() { @@ -537,7 +537,7 @@ declare_clippy_lint! { declare_lint_pass!(UnitCmp => [UNIT_CMP]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnitCmp { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { + fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'tcx>) { if expr.span.from_expansion() { if let Some(callee) = expr.span.source_callee() { if let ExpnKind::Macro(MacroKind::Bang, symbol) = callee.kind { @@ -610,7 +610,7 @@ declare_clippy_lint! { declare_lint_pass!(UnitArg => [UNIT_ARG]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnitArg { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { + fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { if expr.span.from_expansion() { return; } @@ -633,7 +633,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnitArg { } match expr.kind { - ExprKind::Call(_, ref args) | ExprKind::MethodCall(_, _, ref args) => { + ExprKind::Call(_, args) | ExprKind::MethodCall(_, _, args) => { for arg in args { if is_unit(cx.tables.expr_ty(arg)) && !is_unit_literal(arg) { if let ExprKind::Match(.., match_source) = &arg.kind { @@ -659,7 +659,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnitArg { } } -fn is_questionmark_desugar_marked_call(expr: &Expr) -> bool { +fn is_questionmark_desugar_marked_call(expr: &Expr<'_>) -> bool { use syntax_pos::hygiene::DesugaringKind; if let ExprKind::Call(ref callee, _) = expr.kind { callee.span.is_desugaring(DesugaringKind::QuestionMark) @@ -675,7 +675,7 @@ fn is_unit(ty: Ty<'_>) -> bool { } } -fn is_unit_literal(expr: &Expr) -> bool { +fn is_unit_literal(expr: &Expr<'_>) -> bool { match expr.kind { ExprKind::Tup(ref slice) if slice.is_empty() => true, _ => false, @@ -929,7 +929,7 @@ fn is_isize_or_usize(typ: Ty<'_>) -> bool { } } -fn span_precision_loss_lint(cx: &LateContext<'_, '_>, expr: &Expr, cast_from: Ty<'_>, cast_to_f64: bool) { +fn span_precision_loss_lint(cx: &LateContext<'_, '_>, expr: &Expr<'_>, cast_from: Ty<'_>, cast_to_f64: bool) { let mantissa_nbits = if cast_to_f64 { 52 } else { 23 }; let arch_dependent = is_isize_or_usize(cast_from) && cast_to_f64; let arch_dependent_str = "on targets with 64-bit wide pointers "; @@ -956,7 +956,7 @@ fn span_precision_loss_lint(cx: &LateContext<'_, '_>, expr: &Expr, cast_from: Ty ); } -fn should_strip_parens(op: &Expr, snip: &str) -> bool { +fn should_strip_parens(op: &Expr<'_>, snip: &str) -> bool { if let ExprKind::Binary(_, _, _) = op.kind { if snip.starts_with('(') && snip.ends_with(')') { return true; @@ -965,7 +965,7 @@ fn should_strip_parens(op: &Expr, snip: &str) -> bool { false } -fn span_lossless_lint(cx: &LateContext<'_, '_>, expr: &Expr, op: &Expr, cast_from: Ty<'_>, cast_to: Ty<'_>) { +fn span_lossless_lint(cx: &LateContext<'_, '_>, expr: &Expr<'_>, op: &Expr<'_>, cast_from: Ty<'_>, cast_to: Ty<'_>) { // Do not suggest using From in consts/statics until it is valid to do so (see #2267). if in_constant(cx, expr.hir_id) { return; @@ -1005,7 +1005,7 @@ enum ArchSuffix { None, } -fn check_loss_of_sign(cx: &LateContext<'_, '_>, expr: &Expr, op: &Expr, cast_from: Ty<'_>, cast_to: Ty<'_>) { +fn check_loss_of_sign(cx: &LateContext<'_, '_>, expr: &Expr<'_>, op: &Expr<'_>, cast_from: Ty<'_>, cast_to: Ty<'_>) { if !cast_from.is_signed() || cast_to.is_signed() { return; } @@ -1049,7 +1049,7 @@ fn check_loss_of_sign(cx: &LateContext<'_, '_>, expr: &Expr, op: &Expr, cast_fro ); } -fn check_truncation_and_wrapping(cx: &LateContext<'_, '_>, expr: &Expr, cast_from: Ty<'_>, cast_to: Ty<'_>) { +fn check_truncation_and_wrapping(cx: &LateContext<'_, '_>, expr: &Expr<'_>, cast_from: Ty<'_>, cast_to: Ty<'_>) { let arch_64_suffix = " on targets with 64-bit wide pointers"; let arch_32_suffix = " on targets with 32-bit wide pointers"; let cast_unsigned_to_signed = !cast_from.is_signed() && cast_to.is_signed(); @@ -1120,7 +1120,7 @@ fn check_truncation_and_wrapping(cx: &LateContext<'_, '_>, expr: &Expr, cast_fro } } -fn check_lossless(cx: &LateContext<'_, '_>, expr: &Expr, op: &Expr, cast_from: Ty<'_>, cast_to: Ty<'_>) { +fn check_lossless(cx: &LateContext<'_, '_>, expr: &Expr<'_>, op: &Expr<'_>, cast_from: Ty<'_>, cast_to: Ty<'_>) { let cast_signed_to_unsigned = cast_from.is_signed() && !cast_to.is_signed(); let from_nbits = int_ty_to_nbits(cast_from, cx.tcx); let to_nbits = int_ty_to_nbits(cast_to, cx.tcx); @@ -1169,7 +1169,7 @@ fn fp_ty_mantissa_nbits(typ: Ty<'_>) -> u32 { } impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Casts { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { + fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { if expr.span.from_expansion() { return; } @@ -1223,8 +1223,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Casts { fn lint_numeric_casts<'tcx>( cx: &LateContext<'_, 'tcx>, - expr: &Expr, - cast_expr: &Expr, + expr: &Expr<'tcx>, + cast_expr: &Expr<'_>, cast_from: Ty<'tcx>, cast_to: Ty<'tcx>, ) { @@ -1280,7 +1280,7 @@ fn lint_numeric_casts<'tcx>( } } -fn lint_cast_ptr_alignment<'tcx>(cx: &LateContext<'_, 'tcx>, expr: &Expr, cast_from: Ty<'tcx>, cast_to: Ty<'tcx>) { +fn lint_cast_ptr_alignment<'tcx>(cx: &LateContext<'_, 'tcx>, expr: &Expr<'_>, cast_from: Ty<'tcx>, cast_to: Ty<'tcx>) { if_chain! { if let ty::RawPtr(from_ptr_ty) = &cast_from.kind; if let ty::RawPtr(to_ptr_ty) = &cast_to.kind; @@ -1310,8 +1310,8 @@ fn lint_cast_ptr_alignment<'tcx>(cx: &LateContext<'_, 'tcx>, expr: &Expr, cast_f fn lint_fn_to_numeric_cast( cx: &LateContext<'_, '_>, - expr: &Expr, - cast_expr: &Expr, + expr: &Expr<'_>, + cast_expr: &Expr<'_>, cast_from: Ty<'_>, cast_to: Ty<'_>, ) { @@ -1432,7 +1432,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeComplexity { } } - fn check_local(&mut self, cx: &LateContext<'a, 'tcx>, local: &'tcx Local) { + fn check_local(&mut self, cx: &LateContext<'a, 'tcx>, local: &'tcx Local<'_>) { if let Some(ref ty) = local.ty { self.check_type(cx, ty); } @@ -1548,7 +1548,7 @@ declare_clippy_lint! { declare_lint_pass!(CharLitAsU8 => [CHAR_LIT_AS_U8]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CharLitAsU8 { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { + fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { if_chain! { if !expr.span.from_expansion(); if let ExprKind::Cast(e, _) = &expr.kind; @@ -1619,7 +1619,7 @@ enum ExtremeType { struct ExtremeExpr<'a> { which: ExtremeType, - expr: &'a Expr, + expr: &'a Expr<'a>, } enum AbsurdComparisonResult { @@ -1628,7 +1628,7 @@ enum AbsurdComparisonResult { InequalityImpossible, } -fn is_cast_between_fixed_and_target<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) -> bool { +fn is_cast_between_fixed_and_target<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'tcx>) -> bool { if let ExprKind::Cast(ref cast_exp, _) = expr.kind { let precast_ty = cx.tables.expr_ty(cast_exp); let cast_ty = cx.tables.expr_ty(expr); @@ -1642,8 +1642,8 @@ fn is_cast_between_fixed_and_target<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: fn detect_absurd_comparison<'a, 'tcx>( cx: &LateContext<'a, 'tcx>, op: BinOpKind, - lhs: &'tcx Expr, - rhs: &'tcx Expr, + lhs: &'tcx Expr<'_>, + rhs: &'tcx Expr<'_>, ) -> Option<(ExtremeExpr<'tcx>, AbsurdComparisonResult)> { use crate::types::AbsurdComparisonResult::*; use crate::types::ExtremeType::*; @@ -1691,7 +1691,7 @@ fn detect_absurd_comparison<'a, 'tcx>( }) } -fn detect_extreme_expr<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) -> Option> { +fn detect_extreme_expr<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) -> Option> { use crate::types::ExtremeType::*; let ty = cx.tables.expr_ty(expr); @@ -1720,7 +1720,7 @@ fn detect_extreme_expr<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) - } impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AbsurdExtremeComparisons { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { + fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { use crate::types::AbsurdComparisonResult::*; use crate::types::ExtremeType::*; @@ -1828,7 +1828,7 @@ impl Ord for FullInt { } } -fn numeric_cast_precast_bounds<'a>(cx: &LateContext<'_, '_>, expr: &'a Expr) -> Option<(FullInt, FullInt)> { +fn numeric_cast_precast_bounds<'a>(cx: &LateContext<'_, '_>, expr: &'a Expr<'_>) -> Option<(FullInt, FullInt)> { use std::*; if let ExprKind::Cast(ref cast_exp, _) = expr.kind { @@ -1892,7 +1892,7 @@ fn numeric_cast_precast_bounds<'a>(cx: &LateContext<'_, '_>, expr: &'a Expr) -> } } -fn node_as_const_fullint<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) -> Option { +fn node_as_const_fullint<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) -> Option { let val = constant(cx, cx.tables, expr)?.0; if let Constant::Int(const_int) = val { match cx.tables.expr_ty(expr).kind { @@ -1905,7 +1905,7 @@ fn node_as_const_fullint<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) } } -fn err_upcast_comparison(cx: &LateContext<'_, '_>, span: Span, expr: &Expr, always: bool) { +fn err_upcast_comparison(cx: &LateContext<'_, '_>, span: Span, expr: &Expr<'_>, always: bool) { if let ExprKind::Cast(ref cast_val, _) = expr.kind { span_lint( cx, @@ -1925,8 +1925,8 @@ fn upcast_comparison_bounds_err<'a, 'tcx>( span: Span, rel: comparisons::Rel, lhs_bounds: Option<(FullInt, FullInt)>, - lhs: &'tcx Expr, - rhs: &'tcx Expr, + lhs: &'tcx Expr<'_>, + rhs: &'tcx Expr<'_>, invert: bool, ) { use crate::utils::comparisons::*; @@ -1979,7 +1979,7 @@ fn upcast_comparison_bounds_err<'a, 'tcx>( } impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InvalidUpcastComparisons { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { + fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { if let ExprKind::Binary(ref cmp, ref lhs, ref rhs) = expr.kind { let normalized = comparisons::normalize_comparison(cmp.node, lhs, rhs); let (rel, normalized_lhs, normalized_rhs) = if let Some(val) = normalized { @@ -2298,7 +2298,7 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for ImplicitHasherConstructorVisitor<'a, 'b, 't self.body = prev_body; } - fn visit_expr(&mut self, e: &'tcx Expr) { + fn visit_expr(&mut self, e: &'tcx Expr<'_>) { if_chain! { if let ExprKind::Call(ref fun, ref args) = e.kind; if let ExprKind::Path(QPath::TypeRelative(ref ty, ref method)) = fun.kind; @@ -2383,7 +2383,7 @@ declare_clippy_lint! { declare_lint_pass!(RefToMut => [CAST_REF_TO_MUT]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for RefToMut { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { + fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { if_chain! { if let ExprKind::Unary(UnOp::UnDeref, e) = &expr.kind; if let ExprKind::Cast(e, t) = &e.kind; diff --git a/clippy_lints/src/unicode.rs b/clippy_lints/src/unicode.rs index 1024e71657c2..992b8d80c20d 100644 --- a/clippy_lints/src/unicode.rs +++ b/clippy_lints/src/unicode.rs @@ -67,7 +67,7 @@ declare_clippy_lint! { declare_lint_pass!(Unicode => [ZERO_WIDTH_SPACE, NON_ASCII_LITERAL, UNICODE_NOT_NFC]); impl LateLintPass<'_, '_> for Unicode { - fn check_expr(&mut self, cx: &LateContext<'_, '_>, expr: &'_ Expr) { + fn check_expr(&mut self, cx: &LateContext<'_, '_>, expr: &'_ Expr<'_>) { if let ExprKind::Lit(ref lit) = expr.kind { if let LitKind::Str(_, _) = lit.node { check_str(cx, lit.span, expr.hir_id) diff --git a/clippy_lints/src/unused_io_amount.rs b/clippy_lints/src/unused_io_amount.rs index 41182e3ca8b6..db1e61b4edd8 100644 --- a/clippy_lints/src/unused_io_amount.rs +++ b/clippy_lints/src/unused_io_amount.rs @@ -34,7 +34,7 @@ declare_clippy_lint! { declare_lint_pass!(UnusedIoAmount => [UNUSED_IO_AMOUNT]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedIoAmount { - fn check_stmt(&mut self, cx: &LateContext<'_, '_>, s: &hir::Stmt) { + fn check_stmt(&mut self, cx: &LateContext<'_, '_>, s: &hir::Stmt<'_>) { let expr = match s.kind { hir::StmtKind::Semi(ref expr) | hir::StmtKind::Expr(ref expr) => &**expr, _ => return, @@ -65,7 +65,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedIoAmount { } } -fn check_method_call(cx: &LateContext<'_, '_>, call: &hir::Expr, expr: &hir::Expr) { +fn check_method_call(cx: &LateContext<'_, '_>, call: &hir::Expr<'_>, expr: &hir::Expr<'_>) { if let hir::ExprKind::MethodCall(ref path, _, _) = call.kind { let symbol = &*path.ident.as_str(); if match_trait_method(cx, call, &paths::IO_READ) && symbol == "read" { diff --git a/clippy_lints/src/unwrap.rs b/clippy_lints/src/unwrap.rs index 555a157c2751..37a6a2859b55 100644 --- a/clippy_lints/src/unwrap.rs +++ b/clippy_lints/src/unwrap.rs @@ -72,7 +72,7 @@ struct UnwrapInfo<'tcx> { /// The variable that is checked ident: &'tcx Path, /// The check, like `x.is_ok()` - check: &'tcx Expr, + check: &'tcx Expr<'tcx>, /// Whether `is_some()` or `is_ok()` was called (as opposed to `is_err()` or `is_none()`). safe_to_unwrap: bool, } @@ -81,7 +81,7 @@ struct UnwrapInfo<'tcx> { /// The `invert` argument tells us whether the condition is negated. fn collect_unwrap_info<'a, 'tcx>( cx: &'a LateContext<'a, 'tcx>, - expr: &'tcx Expr, + expr: &'tcx Expr<'_>, invert: bool, ) -> Vec> { if let ExprKind::Binary(op, left, right) = &expr.kind { @@ -119,7 +119,7 @@ fn collect_unwrap_info<'a, 'tcx>( } impl<'a, 'tcx> UnwrappableVariablesVisitor<'a, 'tcx> { - fn visit_branch(&mut self, cond: &'tcx Expr, branch: &'tcx Expr, else_branch: bool) { + fn visit_branch(&mut self, cond: &'tcx Expr<'_>, branch: &'tcx Expr<'_>, else_branch: bool) { let prev_len = self.unwrappables.len(); for unwrap_info in collect_unwrap_info(self.cx, cond, else_branch) { if is_potentially_mutated(unwrap_info.ident, cond, self.cx) @@ -136,7 +136,7 @@ impl<'a, 'tcx> UnwrappableVariablesVisitor<'a, 'tcx> { } impl<'a, 'tcx> Visitor<'tcx> for UnwrappableVariablesVisitor<'a, 'tcx> { - fn visit_expr(&mut self, expr: &'tcx Expr) { + fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { if let Some((cond, then, els)) = if_block(&expr) { walk_expr(self, cond); self.visit_branch(cond, then, false); diff --git a/clippy_lints/src/utils/author.rs b/clippy_lints/src/utils/author.rs index fe3bcfd2cc9b..1169fce05ab5 100644 --- a/clippy_lints/src/utils/author.rs +++ b/clippy_lints/src/utils/author.rs @@ -109,7 +109,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Author { done(); } - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) { + fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr<'_>) { if !has_attr(cx.sess(), &expr.attrs) { return; } @@ -118,7 +118,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Author { done(); } - fn check_arm(&mut self, cx: &LateContext<'a, 'tcx>, arm: &'tcx hir::Arm) { + fn check_arm(&mut self, cx: &LateContext<'a, 'tcx>, arm: &'tcx hir::Arm<'_>) { if !has_attr(cx.sess(), &arm.attrs) { return; } @@ -127,7 +127,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Author { done(); } - fn check_stmt(&mut self, cx: &LateContext<'a, 'tcx>, stmt: &'tcx hir::Stmt) { + fn check_stmt(&mut self, cx: &LateContext<'a, 'tcx>, stmt: &'tcx hir::Stmt<'_>) { if !has_attr(cx.sess(), stmt.kind.attrs()) { return; } @@ -189,7 +189,7 @@ struct PrintVisitor { impl<'tcx> Visitor<'tcx> for PrintVisitor { #[allow(clippy::too_many_lines)] - fn visit_expr(&mut self, expr: &Expr) { + fn visit_expr(&mut self, expr: &Expr<'_>) { // handle if desugarings // TODO add more desugarings here if let Some((cond, then, opt_else)) = higher::if_block(&expr) { @@ -508,7 +508,7 @@ impl<'tcx> Visitor<'tcx> for PrintVisitor { } } - fn visit_block(&mut self, block: &Block) { + fn visit_block(&mut self, block: &Block<'_>) { let trailing_pat = self.next("trailing_expr"); println!(" if let Some({}) = &{}.expr;", trailing_pat, self.current); println!(" if {}.stmts.len() == {};", self.current, block.stmts.len()); @@ -520,7 +520,7 @@ impl<'tcx> Visitor<'tcx> for PrintVisitor { } #[allow(clippy::too_many_lines)] - fn visit_pat(&mut self, pat: &Pat) { + fn visit_pat(&mut self, pat: &Pat<'_>) { print!(" if let PatKind::"); let current = format!("{}.kind", self.current); match pat.kind { @@ -646,7 +646,7 @@ impl<'tcx> Visitor<'tcx> for PrintVisitor { } } - fn visit_stmt(&mut self, s: &Stmt) { + fn visit_stmt(&mut self, s: &Stmt<'_>) { print!(" if let StmtKind::"); let current = format!("{}.kind", self.current); match s.kind { diff --git a/clippy_lints/src/utils/comparisons.rs b/clippy_lints/src/utils/comparisons.rs index 31e20f37e20d..33c6bcc66d03 100644 --- a/clippy_lints/src/utils/comparisons.rs +++ b/clippy_lints/src/utils/comparisons.rs @@ -19,7 +19,11 @@ pub enum Rel { /// Put the expression in the form `lhs < rhs`, `lhs <= rhs`, `lhs == rhs` or /// `lhs != rhs`. -pub fn normalize_comparison<'a>(op: BinOpKind, lhs: &'a Expr, rhs: &'a Expr) -> Option<(Rel, &'a Expr, &'a Expr)> { +pub fn normalize_comparison<'a>( + op: BinOpKind, + lhs: &'a Expr<'a>, + rhs: &'a Expr<'a>, +) -> Option<(Rel, &'a Expr<'a>, &'a Expr<'a>)> { match op { BinOpKind::Lt => Some((Rel::Lt, lhs, rhs)), BinOpKind::Le => Some((Rel::Le, lhs, rhs)), diff --git a/clippy_lints/src/utils/higher.rs b/clippy_lints/src/utils/higher.rs index 623dc70c1136..37d37a94d0e8 100644 --- a/clippy_lints/src/utils/higher.rs +++ b/clippy_lints/src/utils/higher.rs @@ -38,18 +38,18 @@ pub fn binop(op: hir::BinOpKind) -> ast::BinOpKind { #[derive(Debug, Copy, Clone)] pub struct Range<'a> { /// The lower bound of the range, or `None` for ranges such as `..X`. - pub start: Option<&'a hir::Expr>, + pub start: Option<&'a hir::Expr<'a>>, /// The upper bound of the range, or `None` for ranges such as `X..`. - pub end: Option<&'a hir::Expr>, + pub end: Option<&'a hir::Expr<'a>>, /// Whether the interval is open or closed. pub limits: ast::RangeLimits, } /// Higher a `hir` range to something similar to `ast::ExprKind::Range`. -pub fn range<'a, 'b, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'b hir::Expr) -> Option> { +pub fn range<'a, 'b, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'b hir::Expr<'_>) -> Option> { /// Finds the field named `name` in the field. Always return `Some` for /// convenience. - fn get_field<'c>(name: &str, fields: &'c [hir::Field]) -> Option<&'c hir::Expr> { + fn get_field<'c>(name: &str, fields: &'c [hir::Field<'_>]) -> Option<&'c hir::Expr<'c>> { let expr = &fields.iter().find(|field| field.ident.name.as_str() == name)?.expr; Some(expr) @@ -150,7 +150,7 @@ pub fn range<'a, 'b, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'b hir::Expr) -> O } /// Checks if a `let` statement is from a `for` loop desugaring. -pub fn is_from_for_desugar(local: &hir::Local) -> bool { +pub fn is_from_for_desugar(local: &hir::Local<'_>) -> bool { // This will detect plain for-loops without an actual variable binding: // // ``` @@ -183,7 +183,9 @@ pub fn is_from_for_desugar(local: &hir::Local) -> bool { /// Recover the essential nodes of a desugared for loop: /// `for pat in arg { body }` becomes `(pat, arg, body)`. -pub fn for_loop(expr: &hir::Expr) -> Option<(&hir::Pat, &hir::Expr, &hir::Expr)> { +pub fn for_loop<'tcx>( + expr: &'tcx hir::Expr<'tcx>, +) -> Option<(&hir::Pat<'_>, &'tcx hir::Expr<'tcx>, &'tcx hir::Expr<'tcx>)> { if_chain! { if let hir::ExprKind::Match(ref iterexpr, ref arms, hir::MatchSource::ForLoopDesugar) = expr.kind; if let hir::ExprKind::Call(_, ref iterargs) = iterexpr.kind; @@ -202,7 +204,7 @@ pub fn for_loop(expr: &hir::Expr) -> Option<(&hir::Pat, &hir::Expr, &hir::Expr)> /// Recover the essential nodes of a desugared while loop: /// `while cond { body }` becomes `(cond, body)`. -pub fn while_loop(expr: &hir::Expr) -> Option<(&hir::Expr, &hir::Expr)> { +pub fn while_loop<'tcx>(expr: &'tcx hir::Expr<'tcx>) -> Option<(&'tcx hir::Expr<'tcx>, &'tcx hir::Expr<'tcx>)> { if_chain! { if let hir::ExprKind::Loop(block, _, hir::LoopSource::While) = &expr.kind; if let hir::Block { expr: Some(expr), .. } = &**block; @@ -219,7 +221,13 @@ pub fn while_loop(expr: &hir::Expr) -> Option<(&hir::Expr, &hir::Expr)> { /// Recover the essential nodes of a desugared if block /// `if cond { then } else { els }` becomes `(cond, then, Some(els))` -pub fn if_block(expr: &hir::Expr) -> Option<(&hir::Expr, &hir::Expr, Option<&hir::Expr>)> { +pub fn if_block<'tcx>( + expr: &'tcx hir::Expr<'tcx>, +) -> Option<( + &'tcx hir::Expr<'tcx>, + &'tcx hir::Expr<'tcx>, + Option<&'tcx hir::Expr<'tcx>>, +)> { if let hir::ExprKind::Match(ref cond, ref arms, hir::MatchSource::IfDesugar { contains_else_clause }) = expr.kind { let cond = if let hir::ExprKind::DropTemps(ref cond) = cond.kind { cond @@ -241,14 +249,14 @@ pub fn if_block(expr: &hir::Expr) -> Option<(&hir::Expr, &hir::Expr, Option<&hir /// Represent the pre-expansion arguments of a `vec!` invocation. pub enum VecArgs<'a> { /// `vec![elem; len]` - Repeat(&'a hir::Expr, &'a hir::Expr), + Repeat(&'a hir::Expr<'a>, &'a hir::Expr<'a>), /// `vec![a, b, c]` - Vec(&'a [hir::Expr]), + Vec(&'a [hir::Expr<'a>]), } /// Returns the arguments of the `vec!` macro if this expression was expanded /// from `vec!`. -pub fn vec_macro<'e>(cx: &LateContext<'_, '_>, expr: &'e hir::Expr) -> Option> { +pub fn vec_macro<'e>(cx: &LateContext<'_, '_>, expr: &'e hir::Expr<'_>) -> Option> { if_chain! { if let hir::ExprKind::Call(ref fun, ref args) = expr.kind; if let hir::ExprKind::Path(ref qpath) = fun.kind; diff --git a/clippy_lints/src/utils/hir_utils.rs b/clippy_lints/src/utils/hir_utils.rs index a32614c8e07b..1227c813f1cb 100644 --- a/clippy_lints/src/utils/hir_utils.rs +++ b/clippy_lints/src/utils/hir_utils.rs @@ -1,6 +1,5 @@ use crate::consts::{constant_context, constant_simple}; use crate::utils::differing_macro_contexts; -use rustc::hir::ptr::P; use rustc::hir::*; use rustc::ich::StableHashingContextProvider; use rustc::lint::LateContext; @@ -42,7 +41,7 @@ impl<'a, 'tcx> SpanlessEq<'a, 'tcx> { } /// Checks whether two statements are the same. - pub fn eq_stmt(&mut self, left: &Stmt, right: &Stmt) -> bool { + pub fn eq_stmt(&mut self, left: &Stmt<'_>, right: &Stmt<'_>) -> bool { match (&left.kind, &right.kind) { (&StmtKind::Local(ref l), &StmtKind::Local(ref r)) => { self.eq_pat(&l.pat, &r.pat) @@ -57,13 +56,13 @@ impl<'a, 'tcx> SpanlessEq<'a, 'tcx> { } /// Checks whether two blocks are the same. - pub fn eq_block(&mut self, left: &Block, right: &Block) -> bool { + pub fn eq_block(&mut self, left: &Block<'_>, right: &Block<'_>) -> bool { over(&left.stmts, &right.stmts, |l, r| self.eq_stmt(l, r)) && both(&left.expr, &right.expr, |l, r| self.eq_expr(l, r)) } #[allow(clippy::similar_names)] - pub fn eq_expr(&mut self, left: &Expr, right: &Expr) -> bool { + pub fn eq_expr(&mut self, left: &Expr<'_>, right: &Expr<'_>) -> bool { if self.ignore_fn && differing_macro_contexts(left.span, right.span) { return false; } @@ -102,7 +101,7 @@ impl<'a, 'tcx> SpanlessEq<'a, 'tcx> { && both(le, re, |l, r| self.eq_expr(l, r)) }, (&ExprKind::Box(ref l), &ExprKind::Box(ref r)) => self.eq_expr(l, r), - (&ExprKind::Call(ref l_fun, ref l_args), &ExprKind::Call(ref r_fun, ref r_args)) => { + (&ExprKind::Call(l_fun, l_args), &ExprKind::Call(r_fun, r_args)) => { !self.ignore_fn && self.eq_expr(l_fun, r_fun) && self.eq_exprs(l_args, r_args) }, (&ExprKind::Cast(ref lx, ref lt), &ExprKind::Cast(ref rx, ref rt)) @@ -128,7 +127,7 @@ impl<'a, 'tcx> SpanlessEq<'a, 'tcx> { && self.eq_pat(&l.pat, &r.pat) }) }, - (&ExprKind::MethodCall(ref l_path, _, ref l_args), &ExprKind::MethodCall(ref r_path, _, ref r_args)) => { + (&ExprKind::MethodCall(l_path, _, l_args), &ExprKind::MethodCall(r_path, _, r_args)) => { !self.ignore_fn && self.eq_path_segment(l_path, r_path) && self.eq_exprs(l_args, r_args) }, (&ExprKind::Repeat(ref le, ref ll_id), &ExprKind::Repeat(ref re, ref rl_id)) => { @@ -146,23 +145,23 @@ impl<'a, 'tcx> SpanlessEq<'a, 'tcx> { && both(lo, ro, |l, r| self.eq_expr(l, r)) && over(lf, rf, |l, r| self.eq_field(l, r)) }, - (&ExprKind::Tup(ref l_tup), &ExprKind::Tup(ref r_tup)) => self.eq_exprs(l_tup, r_tup), + (&ExprKind::Tup(l_tup), &ExprKind::Tup(r_tup)) => self.eq_exprs(l_tup, r_tup), (&ExprKind::Unary(l_op, ref le), &ExprKind::Unary(r_op, ref re)) => l_op == r_op && self.eq_expr(le, re), - (&ExprKind::Array(ref l), &ExprKind::Array(ref r)) => self.eq_exprs(l, r), + (&ExprKind::Array(l), &ExprKind::Array(r)) => self.eq_exprs(l, r), (&ExprKind::DropTemps(ref le), &ExprKind::DropTemps(ref re)) => self.eq_expr(le, re), _ => false, } } - fn eq_exprs(&mut self, left: &P<[Expr]>, right: &P<[Expr]>) -> bool { + fn eq_exprs(&mut self, left: &[Expr<'_>], right: &[Expr<'_>]) -> bool { over(left, right, |l, r| self.eq_expr(l, r)) } - fn eq_field(&mut self, left: &Field, right: &Field) -> bool { + fn eq_field(&mut self, left: &Field<'_>, right: &Field<'_>) -> bool { left.ident.name == right.ident.name && self.eq_expr(&left.expr, &right.expr) } - fn eq_guard(&mut self, left: &Guard, right: &Guard) -> bool { + fn eq_guard(&mut self, left: &Guard<'_>, right: &Guard<'_>) -> bool { match (left, right) { (Guard::If(l), Guard::If(r)) => self.eq_expr(l, r), } @@ -181,7 +180,7 @@ impl<'a, 'tcx> SpanlessEq<'a, 'tcx> { } /// Checks whether two patterns are the same. - pub fn eq_pat(&mut self, left: &Pat, right: &Pat) -> bool { + pub fn eq_pat(&mut self, left: &Pat<'_>, right: &Pat<'_>) -> bool { match (&left.kind, &right.kind) { (&PatKind::Box(ref l), &PatKind::Box(ref r)) => self.eq_pat(l, r), (&PatKind::TupleStruct(ref lp, ref la, ls), &PatKind::TupleStruct(ref rp, ref ra, rs)) => { @@ -299,7 +298,11 @@ impl<'a, 'tcx> SpanlessEq<'a, 'tcx> { } } -fn swap_binop<'a>(binop: BinOpKind, lhs: &'a Expr, rhs: &'a Expr) -> Option<(BinOpKind, &'a Expr, &'a Expr)> { +fn swap_binop<'a>( + binop: BinOpKind, + lhs: &'a Expr<'a>, + rhs: &'a Expr<'a>, +) -> Option<(BinOpKind, &'a Expr<'a>, &'a Expr<'a>)> { match binop { BinOpKind::Add | BinOpKind::Mul @@ -365,8 +368,8 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { self.s.finish() } - pub fn hash_block(&mut self, b: &Block) { - for s in &b.stmts { + pub fn hash_block(&mut self, b: &Block<'_>) { + for s in b.stmts { self.hash_stmt(s); } @@ -384,7 +387,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { } #[allow(clippy::many_single_char_names, clippy::too_many_lines)] - pub fn hash_expr(&mut self, e: &Expr) { + pub fn hash_expr(&mut self, e: &Expr<'_>) { let simple_const = constant_simple(self.cx, self.tables, e); // const hashing may result in the same hash as some unrelated node, so add a sort of @@ -442,7 +445,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { ExprKind::Box(ref e) | ExprKind::DropTemps(ref e) | ExprKind::Yield(ref e, _) => { self.hash_expr(e); }, - ExprKind::Call(ref fun, ref args) => { + ExprKind::Call(ref fun, args) => { self.hash_expr(fun); self.hash_exprs(args); }, @@ -477,7 +480,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { self.hash_name(i.ident.name); } }, - ExprKind::Match(ref e, ref arms, ref s) => { + ExprKind::Match(ref e, arms, ref s) => { self.hash_expr(e); for arm in arms { @@ -490,7 +493,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { s.hash(&mut self.s); }, - ExprKind::MethodCall(ref path, ref _tys, ref args) => { + ExprKind::MethodCall(ref path, ref _tys, args) => { self.hash_name(path.ident.name); self.hash_exprs(args); }, @@ -506,7 +509,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { ExprKind::Path(ref qpath) => { self.hash_qpath(qpath); }, - ExprKind::Struct(ref path, ref fields, ref expr) => { + ExprKind::Struct(ref path, fields, ref expr) => { self.hash_qpath(path); for f in fields { @@ -518,10 +521,10 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { self.hash_expr(e); } }, - ExprKind::Tup(ref tup) => { + ExprKind::Tup(tup) => { self.hash_exprs(tup); }, - ExprKind::Array(ref v) => { + ExprKind::Array(v) => { self.hash_exprs(v); }, ExprKind::Unary(lop, ref le) => { @@ -531,7 +534,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { } } - pub fn hash_exprs(&mut self, e: &P<[Expr]>) { + pub fn hash_exprs(&mut self, e: &[Expr<'_>]) { for e in e { self.hash_expr(e); } @@ -560,7 +563,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { } } - pub fn hash_stmt(&mut self, b: &Stmt) { + pub fn hash_stmt(&mut self, b: &Stmt<'_>) { std::mem::discriminant(&b.kind).hash(&mut self.s); match &b.kind { @@ -576,7 +579,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { } } - pub fn hash_guard(&mut self, g: &Guard) { + pub fn hash_guard(&mut self, g: &Guard<'_>) { match g { Guard::If(ref expr) => { self.hash_expr(expr); diff --git a/clippy_lints/src/utils/inspector.rs b/clippy_lints/src/utils/inspector.rs index ca933c65d6f5..87ef4c7799e9 100644 --- a/clippy_lints/src/utils/inspector.rs +++ b/clippy_lints/src/utils/inspector.rs @@ -91,14 +91,14 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DeepCodeInspector { // } // - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) { + fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr<'_>) { if !has_attr(cx.sess(), &expr.attrs) { return; } print_expr(cx, expr, 0); } - fn check_arm(&mut self, cx: &LateContext<'a, 'tcx>, arm: &'tcx hir::Arm) { + fn check_arm(&mut self, cx: &LateContext<'a, 'tcx>, arm: &'tcx hir::Arm<'_>) { if !has_attr(cx.sess(), &arm.attrs) { return; } @@ -111,7 +111,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DeepCodeInspector { print_expr(cx, &arm.body, 1); } - fn check_stmt(&mut self, cx: &LateContext<'a, 'tcx>, stmt: &'tcx hir::Stmt) { + fn check_stmt(&mut self, cx: &LateContext<'a, 'tcx>, stmt: &'tcx hir::Stmt<'_>) { if !has_attr(cx.sess(), stmt.kind.attrs()) { return; } @@ -144,7 +144,7 @@ fn has_attr(sess: &Session, attrs: &[Attribute]) -> bool { #[allow(clippy::similar_names)] #[allow(clippy::too_many_lines)] -fn print_expr(cx: &LateContext<'_, '_>, expr: &hir::Expr, indent: usize) { +fn print_expr(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, indent: usize) { let ind = " ".repeat(indent); println!("{}+", ind); println!("{}ty: {}", ind, cx.tables.expr_ty(expr)); @@ -154,13 +154,13 @@ fn print_expr(cx: &LateContext<'_, '_>, expr: &hir::Expr, indent: usize) { println!("{}Box", ind); print_expr(cx, e, indent + 1); }, - hir::ExprKind::Array(ref v) => { + hir::ExprKind::Array(v) => { println!("{}Array", ind); for e in v { print_expr(cx, e, indent + 1); } }, - hir::ExprKind::Call(ref func, ref args) => { + hir::ExprKind::Call(ref func, args) => { println!("{}Call", ind); println!("{}function:", ind); print_expr(cx, func, indent + 1); @@ -169,14 +169,14 @@ fn print_expr(cx: &LateContext<'_, '_>, expr: &hir::Expr, indent: usize) { print_expr(cx, arg, indent + 1); } }, - hir::ExprKind::MethodCall(ref path, _, ref args) => { + hir::ExprKind::MethodCall(ref path, _, args) => { println!("{}MethodCall", ind); println!("{}method name: {}", ind, path.ident.name); for arg in args { print_expr(cx, arg, indent + 1); } }, - hir::ExprKind::Tup(ref v) => { + hir::ExprKind::Tup(v) => { println!("{}Tup", ind); for e in v { print_expr(cx, e, indent + 1); @@ -297,7 +297,7 @@ fn print_expr(cx: &LateContext<'_, '_>, expr: &hir::Expr, indent: usize) { print_expr(cx, e, indent + 1); } }, - hir::ExprKind::Struct(ref path, ref fields, ref base) => { + hir::ExprKind::Struct(ref path, fields, ref base) => { println!("{}Struct", ind); println!("{}path: {:?}", ind, path); for field in fields { @@ -400,7 +400,7 @@ fn print_item(cx: &LateContext<'_, '_>, item: &hir::Item<'_>) { #[allow(clippy::similar_names)] #[allow(clippy::too_many_lines)] -fn print_pat(cx: &LateContext<'_, '_>, pat: &hir::Pat, indent: usize) { +fn print_pat(cx: &LateContext<'_, '_>, pat: &hir::Pat<'_>, indent: usize) { let ind = " ".repeat(indent); println!("{}+", ind); match pat.kind { @@ -414,13 +414,13 @@ fn print_pat(cx: &LateContext<'_, '_>, pat: &hir::Pat, indent: usize) { print_pat(cx, inner, indent + 1); } }, - hir::PatKind::Or(ref fields) => { + hir::PatKind::Or(fields) => { println!("{}Or", ind); for field in fields { print_pat(cx, field, indent + 1); } }, - hir::PatKind::Struct(ref path, ref fields, ignore) => { + hir::PatKind::Struct(ref path, fields, ignore) => { println!("{}Struct", ind); println!( "{}name: {}", @@ -437,7 +437,7 @@ fn print_pat(cx: &LateContext<'_, '_>, pat: &hir::Pat, indent: usize) { print_pat(cx, &field.pat, indent + 1); } }, - hir::PatKind::TupleStruct(ref path, ref fields, opt_dots_position) => { + hir::PatKind::TupleStruct(ref path, fields, opt_dots_position) => { println!("{}TupleStruct", ind); println!( "{}path: {}", @@ -459,7 +459,7 @@ fn print_pat(cx: &LateContext<'_, '_>, pat: &hir::Pat, indent: usize) { println!("{}Relative Path, {:?}", ind, ty); println!("{}seg: {:?}", ind, seg); }, - hir::PatKind::Tuple(ref pats, opt_dots_position) => { + hir::PatKind::Tuple(pats, opt_dots_position) => { println!("{}Tuple", ind); if let Some(dot_position) = opt_dots_position { println!("{}dot position: {}", ind, dot_position); @@ -490,7 +490,7 @@ fn print_pat(cx: &LateContext<'_, '_>, pat: &hir::Pat, indent: usize) { hir::RangeEnd::Excluded => println!("{} end excluded", ind), } }, - hir::PatKind::Slice(ref first_pats, ref range, ref last_pats) => { + hir::PatKind::Slice(first_pats, ref range, last_pats) => { println!("{}Slice [a, b, ..i, y, z]", ind); println!("[a, b]:"); for pat in first_pats { @@ -508,7 +508,7 @@ fn print_pat(cx: &LateContext<'_, '_>, pat: &hir::Pat, indent: usize) { } } -fn print_guard(cx: &LateContext<'_, '_>, guard: &hir::Guard, indent: usize) { +fn print_guard(cx: &LateContext<'_, '_>, guard: &hir::Guard<'_>, indent: usize) { let ind = " ".repeat(indent); println!("{}+", ind); match guard { diff --git a/clippy_lints/src/utils/internal_lints.rs b/clippy_lints/src/utils/internal_lints.rs index a309dc8b8e29..83f1864bff70 100644 --- a/clippy_lints/src/utils/internal_lints.rs +++ b/clippy_lints/src/utils/internal_lints.rs @@ -239,7 +239,7 @@ struct LintCollector<'a, 'tcx> { } impl<'a, 'tcx> Visitor<'tcx> for LintCollector<'a, 'tcx> { - fn visit_expr(&mut self, expr: &'tcx Expr) { + fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { walk_expr(self, expr); } @@ -274,7 +274,7 @@ impl CompilerLintFunctions { impl_lint_pass!(CompilerLintFunctions => [COMPILER_LINT_FUNCTIONS]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CompilerLintFunctions { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { + fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { if_chain! { if let ExprKind::MethodCall(ref path, _, ref args) = expr.kind; let fn_name = path.ident; @@ -298,7 +298,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CompilerLintFunctions { declare_lint_pass!(OuterExpnDataPass => [OUTER_EXPN_EXPN_DATA]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for OuterExpnDataPass { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) { + fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr<'_>) { let (method_names, arg_lists, spans) = method_calls(expr, 2); let method_names: Vec = method_names.iter().map(|s| s.as_str()).collect(); let method_names: Vec<&str> = method_names.iter().map(|s| &**s).collect(); diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs index ba8ef2bb0f33..8988a87b7b45 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -142,7 +142,7 @@ pub fn is_type_diagnostic_item(cx: &LateContext<'_, '_>, ty: Ty<'_>, diag_item: } /// Checks if the method call given in `expr` belongs to the given trait. -pub fn match_trait_method(cx: &LateContext<'_, '_>, expr: &Expr, path: &[&str]) -> bool { +pub fn match_trait_method(cx: &LateContext<'_, '_>, expr: &Expr<'_>, path: &[&str]) -> bool { let def_id = cx.tables.type_dependent_def_id(expr.hir_id).unwrap(); let trt_id = cx.tcx.trait_of_item(def_id); if let Some(trt_id) = trt_id { @@ -153,7 +153,7 @@ pub fn match_trait_method(cx: &LateContext<'_, '_>, expr: &Expr, path: &[&str]) } /// Checks if an expression references a variable of the given name. -pub fn match_var(expr: &Expr, var: Name) -> bool { +pub fn match_var(expr: &Expr<'_>, var: Name) -> bool { if let ExprKind::Path(QPath::Resolved(None, ref path)) = expr.kind { if path.segments.len() == 1 && path.segments[0].ident.name == var { return true; @@ -362,7 +362,10 @@ pub fn has_drop<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty<'tcx>) -> bool { /// Returns the method names and argument list of nested method call expressions that make up /// `expr`. method/span lists are sorted with the most recent call first. -pub fn method_calls(expr: &Expr, max_depth: usize) -> (Vec, Vec<&[Expr]>, Vec) { +pub fn method_calls<'tcx>( + expr: &'tcx Expr<'tcx>, + max_depth: usize, +) -> (Vec, Vec<&'tcx [Expr<'tcx>]>, Vec) { let mut method_names = Vec::with_capacity(max_depth); let mut arg_lists = Vec::with_capacity(max_depth); let mut spans = Vec::with_capacity(max_depth); @@ -391,7 +394,7 @@ pub fn method_calls(expr: &Expr, max_depth: usize) -> (Vec, Vec<&[Expr]> /// `matched_method_chain(expr, &["bar", "baz"])` will return a `Vec` /// containing the `Expr`s for /// `.bar()` and `.baz()` -pub fn method_chain_args<'a>(expr: &'a Expr, methods: &[&str]) -> Option> { +pub fn method_chain_args<'a>(expr: &'a Expr<'_>, methods: &[&str]) -> Option]>> { let mut current = expr; let mut matched = Vec::with_capacity(methods.len()); for method_name in methods.iter().rev() { @@ -423,7 +426,7 @@ pub fn is_entrypoint_fn(cx: &LateContext<'_, '_>, def_id: DefId) -> bool { } /// Gets the name of the item the expression is in, if available. -pub fn get_item_name(cx: &LateContext<'_, '_>, expr: &Expr) -> Option { +pub fn get_item_name(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> Option { let parent_id = cx.tcx.hir().get_parent_item(expr.hir_id); match cx.tcx.hir().find(parent_id) { Some(Node::Item(&Item { ref ident, .. })) => Some(ident.name), @@ -435,7 +438,7 @@ pub fn get_item_name(cx: &LateContext<'_, '_>, expr: &Expr) -> Option { } /// Gets the name of a `Pat`, if any. -pub fn get_pat_name(pat: &Pat) -> Option { +pub fn get_pat_name(pat: &Pat<'_>) -> Option { match pat.kind { PatKind::Binding(.., ref spname, _) => Some(spname.name), PatKind::Path(ref qpath) => single_segment_path(qpath).map(|ps| ps.ident.name), @@ -461,7 +464,7 @@ impl<'tcx> Visitor<'tcx> for ContainsName { } /// Checks if an `Expr` contains a certain name. -pub fn contains_name(name: Name, expr: &Expr) -> bool { +pub fn contains_name(name: Name, expr: &Expr<'_>) -> bool { let mut cn = ContainsName { name, result: false }; cn.visit_expr(expr); cn.result @@ -554,7 +557,12 @@ pub fn last_line_of_span(cx: &T, span: Span) -> Span { /// Like `snippet_block`, but add braces if the expr is not an `ExprKind::Block`. /// Also takes an `Option` which can be put inside the braces. -pub fn expr_block<'a, T: LintContext>(cx: &T, expr: &Expr, option: Option, default: &'a str) -> Cow<'a, str> { +pub fn expr_block<'a, T: LintContext>( + cx: &T, + expr: &Expr<'_>, + option: Option, + default: &'a str, +) -> Cow<'a, str> { let code = snippet_block(cx, expr.span, default); let string = option.unwrap_or_default(); if expr.span.from_expansion() { @@ -610,7 +618,7 @@ fn trim_multiline_inner(s: Cow<'_, str>, ignore_first: bool, ch: char) -> Cow<'_ } /// Gets the parent expression, if any –- this is useful to constrain a lint. -pub fn get_parent_expr<'c>(cx: &'c LateContext<'_, '_>, e: &Expr) -> Option<&'c Expr> { +pub fn get_parent_expr<'c>(cx: &'c LateContext<'_, '_>, e: &Expr<'_>) -> Option<&'c Expr<'c>> { let map = &cx.tcx.hir(); let hir_id = e.hir_id; let parent_id = map.get_parent_node(hir_id); @@ -626,7 +634,7 @@ pub fn get_parent_expr<'c>(cx: &'c LateContext<'_, '_>, e: &Expr) -> Option<&'c }) } -pub fn get_enclosing_block<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, hir_id: HirId) -> Option<&'tcx Block> { +pub fn get_enclosing_block<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, hir_id: HirId) -> Option<&'tcx Block<'tcx>> { let map = &cx.tcx.hir(); let enclosing_node = map .get_enclosing_scope(hir_id) @@ -682,7 +690,7 @@ pub fn walk_ptrs_ty_depth(ty: Ty<'_>) -> (Ty<'_>, usize) { /// Checks whether the given expression is a constant integer of the given value. /// unlike `is_integer_literal`, this version does const folding -pub fn is_integer_const(cx: &LateContext<'_, '_>, e: &Expr, value: u128) -> bool { +pub fn is_integer_const(cx: &LateContext<'_, '_>, e: &Expr<'_>, value: u128) -> bool { if is_integer_literal(e, value) { return true; } @@ -699,7 +707,7 @@ pub fn is_integer_const(cx: &LateContext<'_, '_>, e: &Expr, value: u128) -> bool } /// Checks whether the given expression is a constant literal of the given value. -pub fn is_integer_literal(expr: &Expr, value: u128) -> bool { +pub fn is_integer_literal(expr: &Expr<'_>, value: u128) -> bool { // FIXME: use constant folding if let ExprKind::Lit(ref spanned) = expr.kind { if let LitKind::Int(v, _) = spanned.node { @@ -716,7 +724,7 @@ pub fn is_integer_literal(expr: &Expr, value: u128) -> bool { /// /// See `rustc::ty::adjustment::Adjustment` and `rustc_typeck::check::coercion` for more /// information on adjustments and coercions. -pub fn is_adjusted(cx: &LateContext<'_, '_>, e: &Expr) -> bool { +pub fn is_adjusted(cx: &LateContext<'_, '_>, e: &Expr<'_>) -> bool { cx.tables.adjustments().get(e.hir_id).is_some() } @@ -802,7 +810,7 @@ pub fn is_copy<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty<'tcx>) -> bool { } /// Checks if an expression is constructing a tuple-like enum variant or struct -pub fn is_ctor_or_promotable_const_function(cx: &LateContext<'_, '_>, expr: &Expr) -> bool { +pub fn is_ctor_or_promotable_const_function(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool { if let ExprKind::Call(ref fun, _) = expr.kind { if let ExprKind::Path(ref qp) = fun.kind { let res = cx.tables.qpath_res(qp, fun.hir_id); @@ -817,7 +825,7 @@ pub fn is_ctor_or_promotable_const_function(cx: &LateContext<'_, '_>, expr: &Exp } /// Returns `true` if a pattern is refutable. -pub fn is_refutable(cx: &LateContext<'_, '_>, pat: &Pat) -> bool { +pub fn is_refutable(cx: &LateContext<'_, '_>, pat: &Pat<'_>) -> bool { fn is_enum_variant(cx: &LateContext<'_, '_>, qpath: &QPath, id: HirId) -> bool { matches!( cx.tables.qpath_res(qpath, id), @@ -825,7 +833,7 @@ pub fn is_refutable(cx: &LateContext<'_, '_>, pat: &Pat) -> bool { ) } - fn are_refutable<'a, I: Iterator>(cx: &LateContext<'_, '_>, mut i: I) -> bool { + fn are_refutable<'a, I: Iterator>>(cx: &LateContext<'_, '_>, mut i: I) -> bool { i.any(|pat| is_refutable(cx, pat)) } @@ -865,7 +873,7 @@ pub fn is_automatically_derived(attrs: &[ast::Attribute]) -> bool { /// /// Ie. `x`, `{ x }` and `{{{{ x }}}}` all give `x`. `{ x; y }` and `{}` return /// themselves. -pub fn remove_blocks(expr: &Expr) -> &Expr { +pub fn remove_blocks<'tcx>(expr: &'tcx Expr<'tcx>) -> &'tcx Expr<'tcx> { if let ExprKind::Block(ref block, _) = expr.kind { if block.stmts.is_empty() { if let Some(ref expr) = block.expr { @@ -876,7 +884,7 @@ pub fn remove_blocks(expr: &Expr) -> &Expr { expr } -pub fn is_self(slf: &Param) -> bool { +pub fn is_self(slf: &Param<'_>) -> bool { if let PatKind::Binding(.., name, _) = slf.pat.kind { name.name == kw::SelfLower } else { @@ -896,14 +904,14 @@ pub fn is_self_ty(slf: &hir::Ty) -> bool { false } -pub fn iter_input_pats<'tcx>(decl: &FnDecl, body: &'tcx Body<'_>) -> impl Iterator { +pub fn iter_input_pats<'tcx>(decl: &FnDecl, body: &'tcx Body<'_>) -> impl Iterator> { (0..decl.inputs.len()).map(move |i| &body.params[i]) } /// Checks if a given expression is a match expression expanded from the `?` /// operator or the `try` macro. -pub fn is_try(expr: &Expr) -> Option<&Expr> { - fn is_ok(arm: &Arm) -> bool { +pub fn is_try<'tcx>(expr: &'tcx Expr<'tcx>) -> Option<&'tcx Expr<'tcx>> { + fn is_ok(arm: &Arm<'_>) -> bool { if_chain! { if let PatKind::TupleStruct(ref path, ref pat, None) = arm.pat.kind; if match_qpath(path, &paths::RESULT_OK[1..]); @@ -918,7 +926,7 @@ pub fn is_try(expr: &Expr) -> Option<&Expr> { false } - fn is_err(arm: &Arm) -> bool { + fn is_err(arm: &Arm<'_>) -> bool { if let PatKind::TupleStruct(ref path, _, _) = arm.pat.kind { match_qpath(path, &paths::RESULT_ERR[1..]) } else { @@ -954,7 +962,7 @@ pub fn is_allowed(cx: &LateContext<'_, '_>, lint: &'static Lint, id: HirId) -> b cx.tcx.lint_level_at_node(lint, id).0 == Level::Allow } -pub fn get_arg_name(pat: &Pat) -> Option { +pub fn get_arg_name(pat: &Pat<'_>) -> Option { match pat.kind { PatKind::Binding(.., ident, None) => Some(ident.name), PatKind::Ref(ref subpat, _) => get_arg_name(subpat), @@ -1088,9 +1096,9 @@ pub fn has_iter_method(cx: &LateContext<'_, '_>, probably_ref_ty: Ty<'_>) -> Opt /// ``` pub fn match_function_call<'a, 'tcx>( cx: &LateContext<'a, 'tcx>, - expr: &'tcx Expr, + expr: &'tcx Expr<'_>, path: &[&str], -) -> Option<&'tcx [Expr]> { +) -> Option<&'tcx [Expr<'tcx>]> { if_chain! { if let ExprKind::Call(ref fun, ref args) = expr.kind; if let ExprKind::Path(ref qpath) = fun.kind; @@ -1193,9 +1201,11 @@ pub fn match_def_path<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, did: DefId, syms: &[ /// sequence of `if/else`. /// E.g., this returns `([a, b], [c, d, e])` for the expression /// `if a { c } else if b { d } else { e }`. -pub fn if_sequence(mut expr: &Expr) -> (SmallVec<[&Expr; 1]>, SmallVec<[&Block; 1]>) { +pub fn if_sequence<'tcx>( + mut expr: &'tcx Expr<'tcx>, +) -> (SmallVec<[&'tcx Expr<'tcx>; 1]>, SmallVec<[&'tcx Block<'tcx>; 1]>) { let mut conds = SmallVec::new(); - let mut blocks: SmallVec<[&Block; 1]> = SmallVec::new(); + let mut blocks: SmallVec<[&Block<'_>; 1]> = SmallVec::new(); while let Some((ref cond, ref then_expr, ref else_expr)) = higher::if_block(&expr) { conds.push(&**cond); @@ -1222,7 +1232,7 @@ pub fn if_sequence(mut expr: &Expr) -> (SmallVec<[&Expr; 1]>, SmallVec<[&Block; (conds, blocks) } -pub fn parent_node_is_if_expr<'a, 'b>(expr: &Expr, cx: &LateContext<'a, 'b>) -> bool { +pub fn parent_node_is_if_expr<'a, 'b>(expr: &Expr<'_>, cx: &LateContext<'a, 'b>) -> bool { let map = cx.tcx.hir(); let parent_id = map.get_parent_node(expr.hir_id); let parent_node = map.get(parent_id); @@ -1280,7 +1290,7 @@ pub fn is_must_use_ty<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty<'tcx>) -> boo } // check if expr is calling method or function with #[must_use] attribyte -pub fn is_must_use_func_call(cx: &LateContext<'_, '_>, expr: &Expr) -> bool { +pub fn is_must_use_func_call(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool { let did = match expr.kind { ExprKind::Call(ref path, _) => if_chain! { if let ExprKind::Path(ref qpath) = path.kind; diff --git a/clippy_lints/src/utils/ptr.rs b/clippy_lints/src/utils/ptr.rs index dd7132965922..206ce7b4521f 100644 --- a/clippy_lints/src/utils/ptr.rs +++ b/clippy_lints/src/utils/ptr.rs @@ -52,7 +52,7 @@ struct PtrCloneVisitor<'a, 'tcx> { } impl<'a, 'tcx> Visitor<'tcx> for PtrCloneVisitor<'a, 'tcx> { - fn visit_expr(&mut self, expr: &'tcx Expr) { + fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { if self.abort { return; } @@ -80,6 +80,6 @@ impl<'a, 'tcx> Visitor<'tcx> for PtrCloneVisitor<'a, 'tcx> { } } -fn get_binding_name(arg: &Param) -> Option { +fn get_binding_name(arg: &Param<'_>) -> Option { get_pat_name(&arg.pat) } diff --git a/clippy_lints/src/utils/sugg.rs b/clippy_lints/src/utils/sugg.rs index 7050ea4cb2d5..94e09e95f73d 100644 --- a/clippy_lints/src/utils/sugg.rs +++ b/clippy_lints/src/utils/sugg.rs @@ -43,7 +43,7 @@ impl Display for Sugg<'_> { #[allow(clippy::wrong_self_convention)] // ok, because of the function `as_ty` method impl<'a> Sugg<'a> { /// Prepare a suggestion from an expression. - pub fn hir_opt(cx: &LateContext<'_, '_>, expr: &hir::Expr) -> Option { + pub fn hir_opt(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>) -> Option { snippet_opt(cx, expr.span).map(|snippet| { let snippet = Cow::Owned(snippet); Self::hir_from_snippet(cx, expr, snippet) @@ -52,7 +52,7 @@ impl<'a> Sugg<'a> { /// Convenience function around `hir_opt` for suggestions with a default /// text. - pub fn hir(cx: &LateContext<'_, '_>, expr: &hir::Expr, default: &'a str) -> Self { + pub fn hir(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, default: &'a str) -> Self { Self::hir_opt(cx, expr).unwrap_or_else(|| Sugg::NonParen(Cow::Borrowed(default))) } @@ -65,7 +65,7 @@ impl<'a> Sugg<'a> { /// `HasPlaceholders` pub fn hir_with_applicability( cx: &LateContext<'_, '_>, - expr: &hir::Expr, + expr: &hir::Expr<'_>, default: &'a str, applicability: &mut Applicability, ) -> Self { @@ -81,7 +81,7 @@ impl<'a> Sugg<'a> { } /// Same as `hir`, but will use the pre expansion span if the `expr` was in a macro. - pub fn hir_with_macro_callsite(cx: &LateContext<'_, '_>, expr: &hir::Expr, default: &'a str) -> Self { + pub fn hir_with_macro_callsite(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, default: &'a str) -> Self { let snippet = snippet_with_macro_callsite(cx, expr.span, default); Self::hir_from_snippet(cx, expr, snippet) @@ -89,7 +89,7 @@ impl<'a> Sugg<'a> { /// Generate a suggestion for an expression with the given snippet. This is used by the `hir_*` /// function variants of `Sugg`, since these use different snippet functions. - fn hir_from_snippet(cx: &LateContext<'_, '_>, expr: &hir::Expr, snippet: Cow<'a, str>) -> Self { + fn hir_from_snippet(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, snippet: Cow<'a, str>) -> Self { if let Some(range) = higher::range(cx, expr) { let op = match range.limits { ast::RangeLimits::HalfOpen => AssocOp::DotDot, diff --git a/clippy_lints/src/utils/usage.rs b/clippy_lints/src/utils/usage.rs index 089ebafbb7fd..576fc51aec0d 100644 --- a/clippy_lints/src/utils/usage.rs +++ b/clippy_lints/src/utils/usage.rs @@ -6,7 +6,7 @@ use rustc_data_structures::fx::FxHashSet; use rustc_typeck::expr_use_visitor::*; /// Returns a set of mutated local variable IDs, or `None` if mutations could not be determined. -pub fn mutated_variables<'a, 'tcx>(expr: &'tcx Expr, cx: &'a LateContext<'a, 'tcx>) -> Option> { +pub fn mutated_variables<'a, 'tcx>(expr: &'tcx Expr<'_>, cx: &'a LateContext<'a, 'tcx>) -> Option> { let mut delegate = MutVarsDelegate { used_mutably: FxHashSet::default(), skip: false, @@ -22,7 +22,11 @@ pub fn mutated_variables<'a, 'tcx>(expr: &'tcx Expr, cx: &'a LateContext<'a, 'tc Some(delegate.used_mutably) } -pub fn is_potentially_mutated<'a, 'tcx>(variable: &'tcx Path, expr: &'tcx Expr, cx: &'a LateContext<'a, 'tcx>) -> bool { +pub fn is_potentially_mutated<'a, 'tcx>( + variable: &'tcx Path, + expr: &'tcx Expr<'_>, + cx: &'a LateContext<'a, 'tcx>, +) -> bool { if let Res::Local(id) = variable.res { mutated_variables(expr, cx).map_or(true, |mutated| mutated.contains(&id)) } else { diff --git a/clippy_lints/src/vec.rs b/clippy_lints/src/vec.rs index 2779c4b86c72..091be3bc2936 100644 --- a/clippy_lints/src/vec.rs +++ b/clippy_lints/src/vec.rs @@ -29,7 +29,7 @@ declare_clippy_lint! { declare_lint_pass!(UselessVec => [USELESS_VEC]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UselessVec { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { + fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { // search for `&vec![_]` expressions where the adjusted type is `&[_]` if_chain! { if let ty::Ref(_, ty, _) = cx.tables.expr_ty_adjusted(expr).kind; diff --git a/clippy_lints/src/zero_div_zero.rs b/clippy_lints/src/zero_div_zero.rs index ec380360e547..06d4aa00f6b0 100644 --- a/clippy_lints/src/zero_div_zero.rs +++ b/clippy_lints/src/zero_div_zero.rs @@ -26,7 +26,7 @@ declare_clippy_lint! { declare_lint_pass!(ZeroDiv => [ZERO_DIVIDED_BY_ZERO]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ZeroDiv { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { + fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { // check for instances of 0.0/0.0 if_chain! { if let ExprKind::Binary(ref op, ref left, ref right) = expr.kind;