]> git.lizzy.rs Git - rust.git/blobdiff - clippy_lints/src/pattern_type_mismatch.rs
Auto merge of #84401 - crlf0710:impl_main_by_path, r=petrochenkov
[rust.git] / clippy_lints / src / pattern_type_mismatch.rs
index 4550b367da4bf92fd9a39493554c9e105dc2621b..9bab783998aa5693088f8352a3319e55f23086a1 100644 (file)
@@ -10,6 +10,7 @@
 use rustc_middle::ty::{AdtDef, FieldDef, Ty, TyKind, VariantDef};
 use rustc_session::{declare_lint_pass, declare_tool_lint};
 use rustc_span::source_map::Span;
+use std::iter;
 
 declare_clippy_lint! {
     /// **What it does:** Checks for patterns that aren't exact representations of the types
@@ -86,7 +87,7 @@
 
 impl<'tcx> LateLintPass<'tcx> for PatternTypeMismatch {
     fn check_stmt(&mut self, cx: &LateContext<'tcx>, stmt: &'tcx Stmt<'_>) {
-        if let StmtKind::Local(ref local) = stmt.kind {
+        if let StmtKind::Local(local) = stmt.kind {
             if let Some(init) = &local.init {
                 if let Some(init_ty) = cx.typeck_results().node_type_opt(init.hir_id) {
                     let pat = &local.pat;
@@ -104,7 +105,7 @@ fn check_stmt(&mut self, cx: &LateContext<'tcx>, stmt: &'tcx Stmt<'_>) {
     }
 
     fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
-        if let ExprKind::Match(ref expr, arms, source) = expr.kind {
+        if let ExprKind::Match(expr, arms, source) = expr.kind {
             match source {
                 MatchSource::Normal | MatchSource::IfLetDesugar { .. } | MatchSource::WhileLetDesugar => {
                     if let Some(expr_ty) = cx.typeck_results().node_type_opt(expr.hir_id) {
@@ -134,8 +135,8 @@ fn check_fn(
         hir_id: HirId,
     ) {
         if let Some(fn_sig) = cx.typeck_results().liberated_fn_sigs().get(hir_id) {
-            for (param, ty) in body.params.iter().zip(fn_sig.inputs().iter()) {
-                apply_lint(cx, &param.pat, ty, DerefPossible::Impossible);
+            for (param, ty) in iter::zip(body.params, fn_sig.inputs()) {
+                apply_lint(cx, param.pat, ty, DerefPossible::Impossible);
             }
         }
     }
@@ -187,7 +188,7 @@ fn find_first_mismatch<'tcx>(
     ty: Ty<'tcx>,
     level: Level,
 ) -> Option<(Span, Mutability, Level)> {
-    if let PatKind::Ref(ref sub_pat, _) = pat.kind {
+    if let PatKind::Ref(sub_pat, _) = pat.kind {
         if let TyKind::Ref(_, sub_ty, _) = ty.kind() {
             return find_first_mismatch(cx, sub_pat, sub_ty, Level::Lower);
         }
@@ -199,8 +200,8 @@ fn find_first_mismatch<'tcx>(
         }
     }
 
-    if let PatKind::Struct(ref qpath, ref field_pats, _) = pat.kind {
-        if let TyKind::Adt(ref adt_def, ref substs_ref) = ty.kind() {
+    if let PatKind::Struct(ref qpath, field_pats, _) = pat.kind {
+        if let TyKind::Adt(adt_def, substs_ref) = ty.kind() {
             if let Some(variant) = get_variant(adt_def, qpath) {
                 let field_defs = &variant.fields;
                 return find_first_mismatch_in_struct(cx, field_pats, field_defs, substs_ref);
@@ -208,8 +209,8 @@ fn find_first_mismatch<'tcx>(
         }
     }
 
-    if let PatKind::TupleStruct(ref qpath, ref pats, _) = pat.kind {
-        if let TyKind::Adt(ref adt_def, ref substs_ref) = ty.kind() {
+    if let PatKind::TupleStruct(ref qpath, pats, _) = pat.kind {
+        if let TyKind::Adt(adt_def, substs_ref) = ty.kind() {
             if let Some(variant) = get_variant(adt_def, qpath) {
                 let field_defs = &variant.fields;
                 let ty_iter = field_defs.iter().map(|field_def| field_def.ty(cx.tcx, substs_ref));
@@ -218,7 +219,7 @@ fn find_first_mismatch<'tcx>(
         }
     }
 
-    if let PatKind::Tuple(ref pats, _) = pat.kind {
+    if let PatKind::Tuple(pats, _) = pat.kind {
         if let TyKind::Tuple(..) = ty.kind() {
             return find_first_mismatch_in_tuple(cx, pats, ty.tuple_fields());
         }