@@ -35,18 +35,17 @@ declare_lint_pass!(UnnecessaryMapOnConstructor => [UNNECESSARY_MAP_ON_CONSTRUCTO
3535
3636impl < ' tcx > LateLintPass < ' tcx > for UnnecessaryMapOnConstructor {
3737 fn check_expr ( & mut self , cx : & LateContext < ' tcx > , expr : & ' tcx rustc_hir:: Expr < ' tcx > ) {
38- if expr. span . from_expansion ( ) {
39- return ;
40- }
41- if let hir:: ExprKind :: MethodCall ( path , recv , [ map_arg ] , .. ) = expr . kind
38+ if ! expr. span . from_expansion ( )
39+ && let hir :: ExprKind :: MethodCall ( path , recv , [ map_arg ] , .. ) = expr . kind
40+ && !map_arg . span . from_expansion ( )
41+ && let hir:: ExprKind :: Path ( fun ) = map_arg . kind
4242 && let Some ( sym:: Option | sym:: Result ) = cx. typeck_results ( ) . expr_ty ( recv) . opt_diag_name ( cx)
4343 {
4444 let ( constructor_path, constructor_item) = if let hir:: ExprKind :: Call ( constructor, [ arg, ..] ) = recv. kind
4545 && let hir:: ExprKind :: Path ( constructor_path) = constructor. kind
46+ && !constructor. span . from_expansion ( )
47+ && !arg. span . from_expansion ( )
4648 {
47- if constructor. span . from_expansion ( ) || arg. span . from_expansion ( ) {
48- return ;
49- }
5049 ( constructor_path, arg)
5150 } else {
5251 return ;
@@ -67,29 +66,22 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryMapOnConstructor {
6766 _ => return ,
6867 }
6968
70- if let hir:: ExprKind :: Path ( fun) = map_arg. kind {
71- if map_arg. span . from_expansion ( ) {
72- return ;
73- }
74- let mut applicability = Applicability :: MachineApplicable ;
75- let fun_snippet = snippet_with_applicability ( cx, fun. span ( ) , "_" , & mut applicability) ;
76- let constructor_snippet =
77- snippet_with_applicability ( cx, constructor_path. span ( ) , "_" , & mut applicability) ;
78- let constructor_arg_snippet =
79- snippet_with_applicability ( cx, constructor_item. span , "_" , & mut applicability) ;
80- span_lint_and_sugg (
81- cx,
82- UNNECESSARY_MAP_ON_CONSTRUCTOR ,
83- expr. span ,
84- format ! (
85- "unnecessary {} on constructor {constructor_snippet}(_)" ,
86- path. ident. name
87- ) ,
88- "try" ,
89- format ! ( "{constructor_snippet}({fun_snippet}({constructor_arg_snippet}))" ) ,
90- applicability,
91- ) ;
92- }
69+ let mut app = Applicability :: MachineApplicable ;
70+ let fun_snippet = snippet_with_applicability ( cx, fun. span ( ) , "_" , & mut app) ;
71+ let constructor_snippet = snippet_with_applicability ( cx, constructor_path. span ( ) , "_" , & mut app) ;
72+ let constructor_arg_snippet = snippet_with_applicability ( cx, constructor_item. span , "_" , & mut app) ;
73+ span_lint_and_sugg (
74+ cx,
75+ UNNECESSARY_MAP_ON_CONSTRUCTOR ,
76+ expr. span ,
77+ format ! (
78+ "unnecessary `{}` on constructor `{constructor_snippet}(_)`" ,
79+ path. ident. name
80+ ) ,
81+ "try" ,
82+ format ! ( "{constructor_snippet}({fun_snippet}({constructor_arg_snippet}))" ) ,
83+ app,
84+ ) ;
9385 }
9486 }
9587}
0 commit comments