@@ -38,37 +38,23 @@ impl<'tcx> LateLintPass<'tcx> for DefaultTraitAccess {
3838 if let ExprKind :: Path ( ref qpath) = path. kind;
3939 if let Some ( def_id) = cx. qpath_res( qpath, path. hir_id) . opt_def_id( ) ;
4040 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;
4143 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+ ) ;
7258 }
7359 }
7460 }
0 commit comments