]> git.lizzy.rs Git - rust.git/commitdiff
Fix dogfood
authorCameron Steffen <cam.steffen94@gmail.com>
Thu, 26 Aug 2021 15:25:14 +0000 (10:25 -0500)
committerflip1995 <philipp.krones@embecosm.com>
Thu, 2 Sep 2021 11:39:54 +0000 (12:39 +0100)
18 files changed:
clippy_lints/src/assertions_on_constants.rs
clippy_lints/src/floating_point_arithmetic.rs
clippy_lints/src/functions/must_use.rs
clippy_lints/src/if_let_some_result.rs
clippy_lints/src/loops/mod.rs
clippy_lints/src/loops/while_let_loop.rs
clippy_lints/src/matches.rs
clippy_lints/src/pattern_type_mismatch.rs
clippy_lints/src/question_mark.rs
clippy_lints/src/ranges.rs
clippy_lints/src/redundant_closure_call.rs
clippy_lints/src/returns.rs
clippy_lints/src/unused_async.rs
clippy_lints/src/utils/inspector.rs
clippy_lints/src/vec.rs
clippy_utils/src/higher.rs
clippy_utils/src/hir_utils.rs
clippy_utils/src/lib.rs

index 891e865b245dda516c07987e4a5ce3827d0a094a..d834a1d317a0f1d7e9d3344fb764cc3a2ab866d4 100644 (file)
@@ -118,7 +118,7 @@ enum AssertKind {
 fn match_assert_with_message<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Option<AssertKind> {
     if_chain! {
         if let Some(higher::If { cond, then, .. }) = higher::If::hir(expr);
-        if let ExprKind::Unary(UnOp::Not, ref expr) = cond.kind;
+        if let ExprKind::Unary(UnOp::Not, expr) = cond.kind;
         // bind the first argument of the `assert!` macro
         if let Some((Constant::Bool(is_true), _)) = constant(cx, cx.typeck_results(), expr);
         // block
index d12482e7b7bb9531bb4fe569e29321b1976d121c..a643b3eb8f1b8fa32495259cdf90edf613cd4647 100644 (file)
@@ -332,8 +332,6 @@ fn check_powi(cx: &LateContext<'_>, expr: &Expr<'_>, args: &[Expr<'_>]) {
                         ),
                         Applicability::MachineApplicable,
                     );
-
-                    return;
                 }
             }
         }
index ea6193acbe84518ade96aef8d33277b5c5bedac7..77d08081c07f1d2bf07911b33de74f4a9f0148ef 100644 (file)
@@ -26,7 +26,6 @@ pub(super) fn check_item(cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) {
         let fn_header_span = item.span.with_hi(sig.decl.output.span().hi());
         if let Some(attr) = attr {
             check_needless_must_use(cx, sig.decl, item.hir_id(), item.span, fn_header_span, attr);
-            return;
         } else if is_public && !is_proc_macro(cx.sess(), attrs) && !attrs.iter().any(|a| a.has_name(sym::no_mangle)) {
             check_must_use_candidate(
                 cx,
index fb5637fcec183559a9b18cc5c53a13784031c943..33eba02dae063c54603a40d192bbb36281271bdc 100644 (file)
@@ -46,8 +46,8 @@ impl<'tcx> LateLintPass<'tcx> for OkIfLet {
     fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
         if_chain! { //begin checking variables
             if let Some(higher::IfLet { let_pat, let_expr, .. }) = higher::IfLet::hir(cx, expr);
-            if let ExprKind::MethodCall(_, ok_span, ref result_types, _) = let_expr.kind; //check is expr.ok() has type Result<T,E>.ok(, _)
-            if let PatKind::TupleStruct(QPath::Resolved(_, ref x), ref y, _)  = let_pat.kind; //get operation
+            if let ExprKind::MethodCall(_, ok_span, result_types, _) = let_expr.kind; //check is expr.ok() has type Result<T,E>.ok(, _)
+            if let PatKind::TupleStruct(QPath::Resolved(_, x), y, _)  = let_pat.kind; //get operation
             if method_chain_args(let_expr, &["ok"]).is_some(); //test to see if using ok() methoduse std::marker::Sized;
             if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(&result_types[0]), sym::result_type);
             if rustc_hir_pretty::to_string(rustc_hir_pretty::NO_ANN, |s| s.print_path(x, false)) == "Some";
index bd9de5e08d736e877f013b15bcf878afe8666877..9c224445b15925bc5be88c6fb6a1cfa215d5513f 100644 (file)
@@ -580,7 +580,7 @@ fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
 
         while_let_on_iterator::check(cx, expr);
 
-        if let Some(higher::While { if_cond, if_then, .. }) = higher::While::hir(&expr) {
+        if let Some(higher::While { if_cond, if_then, .. }) = higher::While::hir(expr) {
             while_immutable_condition::check(cx, if_cond, if_then);
         }
 
index d6d3315e0a83ed8c2ec69afb27dc6feb5826e45e..1848f5b5de2f2fca48c3f2c1d1d2ce00ce6a9d3a 100644 (file)
@@ -24,13 +24,13 @@ pub(super) fn check(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, loop_block: &'
             }
         }
 
-        if let ExprKind::Match(ref matchexpr, ref arms, MatchSource::Normal) = inner.kind {
+        if let ExprKind::Match(matchexpr, arms, MatchSource::Normal) = inner.kind {
             if arms.len() == 2
                 && arms[0].guard.is_none()
                 && arms[1].guard.is_none()
-                && is_simple_break_expr(&arms[1].body)
+                && is_simple_break_expr(arms[1].body)
             {
-                could_be_while_let(cx, expr, &arms[0].pat, matchexpr);
+                could_be_while_let(cx, expr, arms[0].pat, matchexpr);
             }
         }
     }
index 131ed1d8925f07b7c53d0bffb31c9f8805d466c6..2f1ff567e844f803c7e4f8930aefd1a5f1187eda 100644 (file)
@@ -631,7 +631,7 @@ fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
                 check_match_single_binding(cx, ex, arms, expr);
             }
         }
-        if let ExprKind::Match(ref ex, ref arms, _) = expr.kind {
+        if let ExprKind::Match(ex, arms, _) = expr.kind {
             check_match_ref_pats(cx, ex, arms.iter().map(|el| el.pat), expr);
         }
         if let Some(higher::IfLet { let_pat, let_expr, .. }) = higher::IfLet::hir(cx, expr) {
@@ -1194,7 +1194,7 @@ fn check_match_ref_pats<'a, 'b, I>(cx: &LateContext<'_>, ex: &Expr<'_>, pats: I,
 
     let (first_sugg, msg, title);
     let span = ex.span.source_callsite();
-    if let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Not, ref inner) = ex.kind {
+    if let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Not, inner) = ex.kind {
         first_sugg = once((span, Sugg::hir_with_macro_callsite(cx, inner, "..").to_string()));
         msg = "try";
         title = "you don't need to add `&` to both the expression and the patterns";
@@ -1205,7 +1205,7 @@ fn check_match_ref_pats<'a, 'b, I>(cx: &LateContext<'_>, ex: &Expr<'_>, pats: I,
     }
 
     let remaining_suggs = pats.filter_map(|pat| {
-        if let PatKind::Ref(ref refp, _) = pat.kind {
+        if let PatKind::Ref(refp, _) = pat.kind {
             Some((pat.span, snippet(cx, refp.span, "..").to_string()))
         } else {
             None
@@ -1365,7 +1365,7 @@ fn find_matches_sugg<'a, 'b, I>(
                 find_bool_lit(&arm.2.kind, is_if_let).map_or(false, |b| b == b0) && arm.3.is_none() && arm.0.is_empty()
             });
         then {
-            if let Some(ref last_pat) = last_pat_opt {
+            if let Some(last_pat) = last_pat_opt {
                 if !is_wild(last_pat) {
                     return false;
                 }
@@ -1827,13 +1827,13 @@ pub fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
             ..
         }) = higher::IfLet::hir(cx, expr)
         {
-            find_sugg_for_if_let(cx, expr, let_pat, let_expr, "if", if_else.is_some())
+            find_sugg_for_if_let(cx, expr, let_pat, let_expr, "if", if_else.is_some());
         }
         if let ExprKind::Match(op, arms, MatchSource::Normal) = &expr.kind {
-            find_sugg_for_match(cx, expr, op, arms)
+            find_sugg_for_match(cx, expr, op, arms);
         }
         if let Some(higher::WhileLet { let_pat, let_expr, .. }) = higher::WhileLet::hir(expr) {
-            find_sugg_for_if_let(cx, expr, let_pat, let_expr, "while", false)
+            find_sugg_for_if_let(cx, expr, let_pat, let_expr, "while", false);
         }
     }
 
index 35cff4141a903b40cdf58c3f176a9a599aeca3dc..e7bc24465908b43851b87e2af2483e6ac7758028 100644 (file)
@@ -118,7 +118,7 @@ fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
             }
         }
         if let ExprKind::Let(let_pat, let_expr, _) = expr.kind {
-            if let Some(ref expr_ty) = cx.typeck_results().node_type_opt(let_expr.hir_id) {
+            if let Some(expr_ty) = cx.typeck_results().node_type_opt(let_expr.hir_id) {
                 if in_external_macro(cx.sess(), let_pat.span) {
                     return;
                 }
index 17c9e3e7541cadf72f6ed3f868b9bb10267c1eb0..e79cd7ed4ec4a969c95a2c0db407735712130d81 100644 (file)
@@ -106,7 +106,7 @@ fn check_if_let_some_and_early_return_none(cx: &LateContext<'_>, expr: &Expr<'_>
             if let PatKind::Binding(annot, bind_id, _, _) = fields[0].kind;
             let by_ref = matches!(annot, BindingAnnotation::Ref | BindingAnnotation::RefMut);
 
-            if let ExprKind::Block(ref block, None) = if_then.kind;
+            if let ExprKind::Block(block, None) = if_then.kind;
             if block.stmts.is_empty();
             if let Some(trailing_expr) = &block.expr;
             if path_to_local_id(trailing_expr, bind_id);
index 4fa361fedafac434dbd26510c421506bed51e0b8..87364a88ed0dcc8267c6e955c64e83874ab38aaf 100644 (file)
@@ -337,7 +337,7 @@ fn check_range_zip_with_len(cx: &LateContext<'_>, path: &PathSegment<'_>, args:
         // `.iter()` and `.len()` called on same `Path`
         if let ExprKind::Path(QPath::Resolved(_, iter_path)) = iter_args[0].kind;
         if let ExprKind::Path(QPath::Resolved(_, len_path)) = len_args[0].kind;
-        if SpanlessEq::new(cx).eq_path_segments(&iter_path.segments, &len_path.segments);
+        if SpanlessEq::new(cx).eq_path_segments(iter_path.segments, len_path.segments);
         then {
             span_lint(cx,
                 RANGE_ZIP_WITH_LEN,
index 7314bce83e03867d83c8e6f7e2300d9485360f60..90e3c3f4b3e98f78121f2d23f43bc4a1c89148f6 100644 (file)
@@ -51,9 +51,7 @@ fn new() -> Self {
 
 impl<'ast> ast_visit::Visitor<'ast> for ReturnVisitor {
     fn visit_expr(&mut self, ex: &'ast ast::Expr) {
-        if let ast::ExprKind::Ret(_) = ex.kind {
-            self.found_return = true;
-        } else if let ast::ExprKind::Try(_) = ex.kind {
+        if let ast::ExprKind::Ret(_) | ast::ExprKind::Try(_) = ex.kind {
             self.found_return = true;
         }
 
index 681baed8c3696f0323cda6a590bea11e8b325798..341b5a61631dff896fb93510799316fb6cb324a3 100644 (file)
@@ -206,13 +206,10 @@ fn check_final_expr<'tcx>(
         // an if/if let expr, check both exprs
         // note, if without else is going to be a type checking error anyways
         // (except for unit type functions) so we don't match it
-        ExprKind::Match(_, arms, source) => match source {
-            MatchSource::Normal => {
-                for arm in arms.iter() {
-                    check_final_expr(cx, arm.body, Some(arm.body.span), RetReplacement::Block);
-                }
-            },
-            _ => (),
+        ExprKind::Match(_, arms, MatchSource::Normal) => {
+            for arm in arms.iter() {
+                check_final_expr(cx, arm.body, Some(arm.body.span), RetReplacement::Block);
+            }
         },
         ExprKind::DropTemps(expr) => check_final_expr(cx, expr, None, RetReplacement::Empty),
         _ => (),
index 3a6a07c522630b22ce7b2dab5297c3828a6eb68f..f4808682b69279dc1e4445d7c00770c030748866 100644 (file)
@@ -1,6 +1,6 @@
 use clippy_utils::diagnostics::span_lint_and_help;
 use rustc_hir::intravisit::{walk_expr, walk_fn, FnKind, NestedVisitorMap, Visitor};
-use rustc_hir::{Body, Expr, ExprKind, FnDecl, FnHeader, HirId, IsAsync, Item, ItemKind, YieldSource};
+use rustc_hir::{Body, Expr, ExprKind, FnDecl, FnHeader, HirId, IsAsync, YieldSource};
 use rustc_lint::{LateContext, LateLintPass};
 use rustc_middle::hir::map::Map;
 use rustc_session::{declare_lint_pass, declare_tool_lint};
@@ -57,11 +57,6 @@ fn nested_visit_map(&mut self) -> NestedVisitorMap<Self::Map> {
 }
 
 impl<'tcx> LateLintPass<'tcx> for UnusedAsync {
-    fn check_item(&mut self, _: &LateContext<'tcx>, item: &'tcx Item<'tcx>) {
-        if let ItemKind::Trait(..) = item.kind {
-            return;
-        }
-    }
     fn check_fn(
         &mut self,
         cx: &LateContext<'tcx>,
index e97983a2e1451d373e77609e8f13f456f7dbbfde..43590cc786236f2640c751f69877b3ee4f96ca6b 100644 (file)
@@ -142,7 +142,7 @@ fn print_expr(cx: &LateContext<'_>, expr: &hir::Expr<'_>, indent: usize) {
                 print_expr(cx, arg, indent + 1);
             }
         },
-        hir::ExprKind::Let(ref pat, ref expr, _) => {
+        hir::ExprKind::Let(pat, expr, _) => {
             print_pat(cx, pat, indent + 1);
             print_expr(cx, expr, indent + 1);
         },
index 95a45fa937f11ab8d9a7f79fa4eae96016bad9d8..85ff292c53a4d22fe1bb18ed5b1396a1893d696c 100644 (file)
@@ -49,7 +49,7 @@ fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
         if_chain! {
             if let ty::Ref(_, ty, _) = cx.typeck_results().expr_ty_adjusted(expr).kind();
             if let ty::Slice(..) = ty.kind();
-            if let ExprKind::AddrOf(BorrowKind::Ref, mutability, ref addressee) = expr.kind;
+            if let ExprKind::AddrOf(BorrowKind::Ref, mutability, addressee) = expr.kind;
             if let Some(vec_args) = higher::VecArgs::hir(cx, addressee);
             then {
                 self.check_vec_macro(cx, &vec_args, mutability, expr.span);
index 61e672781f8409a5ff010e2fe459a9f7f37f5b69..4bb31868bafb9b3c445c73e0df23e36db5c01b80 100644 (file)
@@ -23,16 +23,16 @@ impl<'tcx> ForLoop<'tcx> {
     #[inline]
     pub fn hir(expr: &Expr<'tcx>) -> Option<Self> {
         if_chain! {
-            if let hir::ExprKind::Match(ref iterexpr, ref arms, hir::MatchSource::ForLoopDesugar) = expr.kind;
+            if let hir::ExprKind::Match(iterexpr, arms, hir::MatchSource::ForLoopDesugar) = expr.kind;
             if let Some(first_arm) = arms.get(0);
-            if let hir::ExprKind::Call(_, ref iterargs) = iterexpr.kind;
+            if let hir::ExprKind::Call(_, iterargs) = iterexpr.kind;
             if let Some(first_arg) = iterargs.get(0);
             if iterargs.len() == 1 && arms.len() == 1 && first_arm.guard.is_none();
-            if let hir::ExprKind::Loop(ref block, ..) = first_arm.body.kind;
+            if let hir::ExprKind::Loop(block, ..) = first_arm.body.kind;
             if block.expr.is_none();
             if let [ _, _, ref let_stmt, ref body ] = *block.stmts;
-            if let hir::StmtKind::Local(ref local) = let_stmt.kind;
-            if let hir::StmtKind::Expr(ref body_expr) = body.kind;
+            if let hir::StmtKind::Local(local) = let_stmt.kind;
+            if let hir::StmtKind::Expr(body_expr) = body.kind;
             then {
                 return Some(Self {
                     pat: &*local.pat,
@@ -189,7 +189,7 @@ fn get_field<'c>(name: &str, fields: &'c [hir::ExprField<'_>]) -> Option<&'c hir
         }
 
         match expr.kind {
-            hir::ExprKind::Call(ref path, ref args)
+            hir::ExprKind::Call(path, args)
                 if matches!(
                     path.kind,
                     hir::ExprKind::Path(hir::QPath::LangItem(hir::LangItem::RangeInclusiveNew, _))
@@ -201,7 +201,7 @@ fn get_field<'c>(name: &str, fields: &'c [hir::ExprField<'_>]) -> Option<&'c hir
                     limits: ast::RangeLimits::Closed,
                 })
             },
-            hir::ExprKind::Struct(ref path, ref fields, None) => match path {
+            hir::ExprKind::Struct(path, fields, None) => match &path {
                 hir::QPath::LangItem(hir::LangItem::RangeFull, _) => Some(Range {
                     start: None,
                     end: None,
@@ -247,7 +247,7 @@ impl<'a> VecArgs<'a> {
     /// from `vec!`.
     pub fn hir(cx: &LateContext<'_>, expr: &'a hir::Expr<'_>) -> Option<VecArgs<'a>> {
         if_chain! {
-            if let hir::ExprKind::Call(ref fun, ref args) = expr.kind;
+            if let hir::ExprKind::Call(fun, args) = expr.kind;
             if let hir::ExprKind::Path(ref qpath) = fun.kind;
             if is_expn_of(fun.span, "vec").is_some();
             if let Some(fun_def_id) = cx.qpath_res(qpath, fun.hir_id).opt_def_id();
@@ -259,10 +259,10 @@ pub fn hir(cx: &LateContext<'_>, expr: &'a hir::Expr<'_>) -> Option<VecArgs<'a>>
                 else if match_def_path(cx, fun_def_id, &paths::SLICE_INTO_VEC) && args.len() == 1 {
                     // `vec![a, b, c]` case
                     if_chain! {
-                        if let hir::ExprKind::Box(ref boxed) = args[0].kind;
-                        if let hir::ExprKind::Array(ref args) = boxed.kind;
+                        if let hir::ExprKind::Box(boxed) = args[0].kind;
+                        if let hir::ExprKind::Array(args) = boxed.kind;
                         then {
-                            return Some(VecArgs::Vec(&*args));
+                            return Some(VecArgs::Vec(args));
                         }
                     }
 
@@ -566,7 +566,7 @@ pub fn is_from_for_desugar(local: &hir::Local<'_>) -> bool {
     // }
     // ```
     if_chain! {
-        if let Some(ref expr) = local.init;
+        if let Some(expr) = local.init;
         if let hir::ExprKind::Match(_, _, hir::MatchSource::ForLoopDesugar) = expr.kind;
         then {
             return true;
index a44f2df2fd631e9793dd022cc50517a48caa7e07..6e9a1de21eef5cb010d32f668a82565ba1713a35 100644 (file)
@@ -232,9 +232,7 @@ pub fn eq_expr(&mut self, left: &Expr<'_>, right: &Expr<'_>) -> bool {
             (&ExprKind::If(lc, lt, ref le), &ExprKind::If(rc, rt, ref re)) => {
                 self.eq_expr(lc, rc) && self.eq_expr(&**lt, &**rt) && both(le, re, |l, r| self.eq_expr(l, r))
             },
-            (&ExprKind::Let(ref lp, ref le, _), &ExprKind::Let(ref rp, ref re, _)) => {
-                self.eq_pat(lp, rp) && self.eq_expr(le, re)
-            },
+            (&ExprKind::Let(lp, le, _), &ExprKind::Let(rp, re, _)) => self.eq_pat(lp, rp) && self.eq_expr(le, re),
             (&ExprKind::Lit(ref l), &ExprKind::Lit(ref r)) => l.node == r.node,
             (&ExprKind::Loop(lb, ref ll, ref lls, _), &ExprKind::Loop(rb, ref rl, ref rls, _)) => {
                 lls == rls && self.eq_block(lb, rb) && both(ll, rl, |l, r| l.ident.name == r.ident.name)
@@ -668,7 +666,7 @@ pub fn hash_expr(&mut self, e: &Expr<'_>) {
                     }
                 }
             },
-            ExprKind::Let(ref pat, ref expr, _) => {
+            ExprKind::Let(pat, expr, _) => {
                 self.hash_expr(expr);
                 self.hash_pat(pat);
             },
index 6cecdd6b1996395685299f9070af006b4648f527..40d7963a5e545152d0e7ebb0be5e1b782509187f 100644 (file)
@@ -1603,13 +1603,13 @@ pub fn if_sequence<'tcx>(mut expr: &'tcx Expr<'tcx>) -> (Vec<&'tcx Expr<'tcx>>,
 
     while let Some(higher::IfOrIfLet { cond, then, r#else }) = higher::IfOrIfLet::hir(expr) {
         conds.push(&*cond);
-        if let ExprKind::Block(ref block, _) = then.kind {
+        if let ExprKind::Block(block, _) = then.kind {
             blocks.push(block);
         } else {
             panic!("ExprKind::If node is not an ExprKind::Block");
         }
 
-        if let Some(ref else_expr) = r#else {
+        if let Some(else_expr) = r#else {
             expr = else_expr;
         } else {
             break;