From 368223a341059c235e44ead210788c0047a4e6ad Mon Sep 17 00:00:00 2001 From: Daniel Wagner-Hall Date: Sun, 2 Sep 2018 23:37:28 +0100 Subject: [PATCH] Use types rather than strings --- clippy_lints/src/default_trait_access.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/clippy_lints/src/default_trait_access.rs b/clippy_lints/src/default_trait_access.rs index d3598a5bdaae..83b824631bc8 100644 --- a/clippy_lints/src/default_trait_access.rs +++ b/clippy_lints/src/default_trait_access.rs @@ -48,13 +48,18 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DefaultTraitAccess { then { match qpath { QPath::Resolved(..) => { - if let ExprKind::Call(ref method, ref _args) = expr.node { - if format!("{:?}", method).contains(" as Default>") { - return + if_chain! { + // Detect and ignore ::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(ref ty, ref _path) = p; + if ty.is_some(); + 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);