]> git.lizzy.rs Git - rust.git/blobdiff - clippy_lints/src/default_trait_access.rs
Auto merge of #3596 - xfix:remove-crate-from-paths, r=flip1995
[rust.git] / clippy_lints / src / default_trait_access.rs
index bc5643a0bed00ead15034a214096dcb53b478173..9dc404efd7e0ba17cede72a704892c8a5c11153c 100644 (file)
@@ -7,12 +7,12 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-use crate::rustc::hir::*;
-use crate::rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
-use crate::rustc::ty::TyKind;
-use crate::rustc::{declare_tool_lint, lint_array};
-use crate::rustc_errors::Applicability;
 use if_chain::if_chain;
+use rustc::hir::*;
+use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
+use rustc::ty;
+use rustc::{declare_tool_lint, lint_array};
+use rustc_errors::Applicability;
 
 use crate::utils::{any_parent_is_automatically_derived, match_def_path, opt_def_id, paths, span_lint_and_sugg};
 
@@ -49,44 +49,44 @@ fn get_lints(&self) -> LintArray {
 impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DefaultTraitAccess {
     fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
         if_chain! {
-           if let ExprKind::Call(ref path, ..) = expr.node;
-           if !any_parent_is_automatically_derived(cx.tcx, expr.id);
-           if let ExprKind::Path(ref qpath) = path.node;
-           if let Some(def_id) = opt_def_id(cx.tables.qpath_def(qpath, path.hir_id));
-           if match_def_path(cx.tcx, def_id, &paths::DEFAULT_TRAIT_METHOD);
-           then {
-               match qpath {
-                   QPath::Resolved(..) => {
-                       if_chain! {
-                           // Detect and ignore <Foo as Default>::default() because these calls do
-                           // explicitly name the type.
-                           if let ExprKind::Call(ref method, ref _args) = expr.node;
-                           if let ExprKind::Path(ref p) = method.node;
-                           if let QPath::Resolved(Some(_ty), _path) = p;
-                           then {
-                               return;
-                           }
-                       }
-
-                       // TODO: Work out a way to put "whatever the imported way of referencing
-                       // this type in this file" rather than a fully-qualified type.
-                       let expr_ty = cx.tables.expr_ty(expr);
-                       if let TyKind::Adt(..) = expr_ty.sty {
-                           let replacement = format!("{}::default()", expr_ty);
-                           span_lint_and_sugg(
-                               cx,
-                               DEFAULT_TRAIT_ACCESS,
-                               expr.span,
-                               &format!("Calling {} is more clear than this expression", replacement),
-                               "try",
-                               replacement,
-                               Applicability::Unspecified, // First resolve the TODO above
-                           );
+            if let ExprKind::Call(ref path, ..) = expr.node;
+            if !any_parent_is_automatically_derived(cx.tcx, expr.id);
+            if let ExprKind::Path(ref qpath) = path.node;
+            if let Some(def_id) = opt_def_id(cx.tables.qpath_def(qpath, path.hir_id));
+            if match_def_path(cx.tcx, def_id, &paths::DEFAULT_TRAIT_METHOD);
+            then {
+                match qpath {
+                    QPath::Resolved(..) => {
+                        if_chain! {
+                            // Detect and ignore <Foo as Default>::default() because these calls do
+                            // explicitly name the type.
+                            if let ExprKind::Call(ref method, ref _args) = expr.node;
+                            if let ExprKind::Path(ref p) = method.node;
+                            if let QPath::Resolved(Some(_ty), _path) = p;
+                            then {
+                                return;
+                            }
                         }
-                   },
-                   QPath::TypeRelative(..) => {},
-               }
-           }
+
+                        // TODO: Work out a way to put "whatever the imported way of referencing
+                        // this type in this file" rather than a fully-qualified type.
+                        let expr_ty = cx.tables.expr_ty(expr);
+                        if let ty::Adt(..) = expr_ty.sty {
+                            let replacement = format!("{}::default()", expr_ty);
+                            span_lint_and_sugg(
+                                cx,
+                                DEFAULT_TRAIT_ACCESS,
+                                expr.span,
+                                &format!("Calling {} is more clear than this expression", replacement),
+                                "try",
+                                replacement,
+                                Applicability::Unspecified, // First resolve the TODO above
+                            );
+                         }
+                    },
+                    QPath::TypeRelative(..) => {},
+                }
+            }
         }
     }
 }