Skip to content

Commit 368223a

Browse files
committed
Use types rather than strings
1 parent 350036a commit 368223a

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

clippy_lints/src/default_trait_access.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,18 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DefaultTraitAccess {
4848
then {
4949
match qpath {
5050
QPath::Resolved(..) => {
51-
if let ExprKind::Call(ref method, ref _args) = expr.node {
52-
if format!("{:?}", method).contains(" as Default>") {
53-
return
51+
if_chain! {
52+
// Detect and ignore <Foo as Default>::default() because these calls do
53+
// explicitly name the type.
54+
if let ExprKind::Call(ref method, ref _args) = expr.node;
55+
if let ExprKind::Path(ref p) = method.node;
56+
if let QPath::Resolved(ref ty, ref _path) = p;
57+
if ty.is_some();
58+
then {
59+
return;
5460
}
5561
}
5662

57-
5863
// TODO: Work out a way to put "whatever the imported way of referencing
5964
// this type in this file" rather than a fully-qualified type.
6065
let expr_ty = cx.tables.expr_ty(expr);

0 commit comments

Comments
 (0)