@@ -43,16 +43,15 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryMapOnConstructor {
4343 return ;
4444 } ;
4545
46- let ( constructor_path, constructor_item) = if_chain ! {
47- if let hir:: ExprKind :: Call ( constructor, constructor_args) = recv. kind;
48- if let hir:: ExprKind :: Path ( constructor_path) = constructor. kind;
49- if let Some ( arg) = constructor_args. get( 0 ) ;
50- then {
46+ let ( constructor_path, constructor_item) =
47+ if let hir:: ExprKind :: Call ( constructor, constructor_args) = recv. kind
48+ && let hir:: ExprKind :: Path ( constructor_path) = constructor. kind
49+ && let Some ( arg) = constructor_args. get ( 0 )
50+ {
5151 ( constructor_path, arg)
5252 } else {
5353 return ;
54- }
55- } ;
54+ } ;
5655 let constructor_symbol = match constructor_path {
5756 hir:: QPath :: Resolved ( _, path) => {
5857 if let Some ( path_segment) = path. segments . last ( ) {
@@ -70,25 +69,23 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryMapOnConstructor {
7069 _ => return ,
7170 }
7271
73- if_chain ! {
74- if let Some ( arg) = args. get( 0 ) ;
75- if let hir:: ExprKind :: Path ( fun) = arg. kind;
76- then {
77- let mut applicability = Applicability :: MachineApplicable ;
78- let constructor_snippet =
79- snippet_with_applicability( cx, constructor_path. span( ) , "_" , & mut applicability) ;
80- let constructor_arg_snippet =
81- snippet_with_applicability( cx, constructor_item. span, "_" , & mut applicability) ;
82- span_lint_and_sugg(
83- cx,
84- UNNECESSARY_MAP_ON_CONSTRUCTOR ,
85- expr. span,
86- & format!( "unnecessary {} on contstuctor {constructor_snippet}(_)" , path. ident. name) ,
87- "try" ,
88- format!( "{constructor_snippet}({}({constructor_arg_snippet}))" , path. ident. name) ,
89- applicability,
90- ) ;
91- }
72+ if let Some ( arg) = args. get ( 0 )
73+ && let hir:: ExprKind :: Path ( fun) = arg. kind
74+ {
75+ let mut applicability = Applicability :: MachineApplicable ;
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 ! ( "unnecessary {} on contstuctor {constructor_snippet}(_)" , path. ident. name) ,
85+ "try" ,
86+ format ! ( "{constructor_snippet}({}({constructor_arg_snippet}))" , path. ident. name) ,
87+ applicability,
88+ ) ;
9289 }
9390 }
9491 }
0 commit comments