]> git.lizzy.rs Git - rust.git/blobdiff - clippy_lints/src/default_trait_access.rs
Merge pull request #2985 from phansch/riir_update_lints
[rust.git] / clippy_lints / src / default_trait_access.rs
index 900dabc96505b44232ca56faddad0285e00e411c..e7c90f041889a591627fc3053f295428397ec167 100644 (file)
@@ -1,6 +1,8 @@
 use rustc::hir::*;
-use rustc::lint::*;
-use rustc::ty::TypeVariants;
+use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
+use rustc::{declare_tool_lint, lint_array};
+use if_chain::if_chain;
+use rustc::ty::TyKind;
 
 use crate::utils::{any_parent_is_automatically_derived, match_def_path, opt_def_id, paths, span_lint_and_sugg};
 
@@ -46,10 +48,21 @@ fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
             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 TypeVariants::TyAdt(..) = expr_ty.sty {
+                        if let TyKind::Adt(..) = expr_ty.sty {
                             let replacement = format!("{}::default()", expr_ty);
                             span_lint_and_sugg(
                                 cx,