@@ -38,37 +38,23 @@ impl<'tcx> LateLintPass<'tcx> for DefaultTraitAccess {
38
38
if let ExprKind :: Path ( ref qpath) = path. kind;
39
39
if let Some ( def_id) = cx. qpath_res( qpath, path. hir_id) . opt_def_id( ) ;
40
40
if match_def_path( cx, def_id, & paths:: DEFAULT_TRAIT_METHOD ) ;
41
+ // Detect and ignore <Foo as Default>::default() because these calls do explicitly name the type.
42
+ if let QPath :: Resolved ( None , _path) = qpath;
41
43
then {
42
- match qpath {
43
- QPath :: Resolved ( ..) => {
44
- if_chain! {
45
- // Detect and ignore <Foo as Default>::default() because these calls do
46
- // explicitly name the type.
47
- if let ExprKind :: Call ( ref method, ref _args) = expr. kind;
48
- if let ExprKind :: Path ( ref p) = method. kind;
49
- if let QPath :: Resolved ( Some ( _ty) , _path) = p;
50
- then {
51
- return ;
52
- }
53
- }
54
-
55
- // TODO: Work out a way to put "whatever the imported way of referencing
56
- // this type in this file" rather than a fully-qualified type.
57
- let expr_ty = cx. typeck_results( ) . expr_ty( expr) ;
58
- if let ty:: Adt ( def, ..) = expr_ty. kind {
59
- let replacement = format!( "{}::default()" , cx. tcx. def_path_str( def. did) ) ;
60
- span_lint_and_sugg(
61
- cx,
62
- DEFAULT_TRAIT_ACCESS ,
63
- expr. span,
64
- & format!( "calling `{}` is more clear than this expression" , replacement) ,
65
- "try" ,
66
- replacement,
67
- Applicability :: Unspecified , // First resolve the TODO above
68
- ) ;
69
- }
70
- } ,
71
- QPath :: TypeRelative ( ..) | QPath :: LangItem ( ..) => { } ,
44
+ let expr_ty = cx. typeck_results( ) . expr_ty( expr) ;
45
+ if let ty:: Adt ( def, ..) = expr_ty. kind {
46
+ // TODO: Work out a way to put "whatever the imported way of referencing
47
+ // this type in this file" rather than a fully-qualified type.
48
+ let replacement = format!( "{}::default()" , cx. tcx. def_path_str( def. did) ) ;
49
+ span_lint_and_sugg(
50
+ cx,
51
+ DEFAULT_TRAIT_ACCESS ,
52
+ expr. span,
53
+ & format!( "calling `{}` is more clear than this expression" , replacement) ,
54
+ "try" ,
55
+ replacement,
56
+ Applicability :: Unspecified , // First resolve the TODO above
57
+ ) ;
72
58
}
73
59
}
74
60
}
0 commit comments