]> git.lizzy.rs Git - rust.git/blobdiff - clippy_lints/src/redundant_pattern_matching.rs
Auto merge of #4551 - mikerite:fix-ice-reporting, r=llogiq
[rust.git] / clippy_lints / src / redundant_pattern_matching.rs
index 9f4788372405735ed0bc1b70a2df4a6126d6f863..68862f838cb051e2d2315d0701a031d3bf66696a 100644 (file)
@@ -1,11 +1,10 @@
 use crate::utils::{match_qpath, paths, snippet, span_lint_and_then};
+use rustc::hir::ptr::P;
 use rustc::hir::*;
 use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
 use rustc::{declare_lint_pass, declare_tool_lint};
 use rustc_errors::Applicability;
 use syntax::ast::LitKind;
-use syntax::ptr::P;
-use syntax::symbol::Symbol;
 
 declare_clippy_lint! {
     /// **What it does:** Lint for redundant pattern matching over `Result` or
@@ -62,11 +61,11 @@ fn find_sugg_for_if_let<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr,
         let good_method = match arms[0].pats[0].node {
             PatKind::TupleStruct(ref path, ref patterns, _) if patterns.len() == 1 => {
                 if let PatKind::Wild = patterns[0].node {
-                    if match_qpath(path, &*paths::RESULT_OK) {
+                    if match_qpath(path, &paths::RESULT_OK) {
                         "is_ok()"
-                    } else if match_qpath(path, &*paths::RESULT_ERR) {
+                    } else if match_qpath(path, &paths::RESULT_ERR) {
                         "is_err()"
-                    } else if match_qpath(path, &*paths::OPTION_SOME) {
+                    } else if match_qpath(path, &paths::OPTION_SOME) {
                         "is_some()"
                     } else {
                         return;
@@ -76,7 +75,7 @@ fn find_sugg_for_if_let<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr,
                 }
             },
 
-            PatKind::Path(ref path) if match_qpath(path, &*paths::OPTION_NONE) => "is_none()",
+            PatKind::Path(ref path) if match_qpath(path, &paths::OPTION_NONE) => "is_none()",
 
             _ => return,
         };
@@ -91,13 +90,11 @@ fn find_sugg_for_if_let<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr,
                 db.span_suggestion(
                     span,
                     "try this",
-                    format!("if {}.{}", snippet(cx, op.span, "_"), good_method),
-                    Applicability::MachineApplicable, // snippet
+                    format!("{}.{}", snippet(cx, op.span, "_"), good_method),
+                    Applicability::MaybeIncorrect, // snippet
                 );
             },
         );
-    } else {
-        return;
     }
 }
 
@@ -115,8 +112,8 @@ fn find_sugg_for_match<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr, o
                         arms,
                         path_left,
                         path_right,
-                        &*paths::RESULT_OK,
-                        &*paths::RESULT_ERR,
+                        &paths::RESULT_OK,
+                        &paths::RESULT_ERR,
                         "is_ok()",
                         "is_err()",
                     )
@@ -133,8 +130,8 @@ fn find_sugg_for_match<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr, o
                         arms,
                         path_left,
                         path_right,
-                        &*paths::OPTION_SOME,
-                        &*paths::OPTION_NONE,
+                        &paths::OPTION_SOME,
+                        &paths::OPTION_NONE,
                         "is_some()",
                         "is_none()",
                     )
@@ -157,13 +154,11 @@ fn find_sugg_for_match<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr, o
                         span,
                         "try this",
                         format!("{}.{}", snippet(cx, op.span, "_"), good_method),
-                        Applicability::MachineApplicable, // snippet
+                        Applicability::MaybeIncorrect, // snippet
                     );
                 },
             );
         }
-    } else {
-        return;
     }
 }
 
@@ -171,8 +166,8 @@ fn find_good_method_for_match<'a>(
     arms: &HirVec<Arm>,
     path_left: &QPath,
     path_right: &QPath,
-    expected_left: &[Symbol],
-    expected_right: &[Symbol],
+    expected_left: &[&str],
+    expected_right: &[&str],
     should_be_left: &'a str,
     should_be_right: &'a str,
 ) -> Option<&'a str> {