@@ -77,7 +77,7 @@ impl EarlyLintPass for RedundantClosureCall {
7777 cx,
7878 REDUNDANT_CLOSURE_CALL ,
7979 expr. span,
80- "try not to call a closure in the expression where it is declared. " ,
80+ "try not to call a closure in the expression where it is declared" ,
8181 |diag| {
8282 if decl. inputs. is_empty( ) {
8383 let mut app = Applicability :: MachineApplicable ;
@@ -95,12 +95,17 @@ impl EarlyLintPass for RedundantClosureCall {
9595
9696impl < ' tcx > LateLintPass < ' tcx > for RedundantClosureCall {
9797 fn check_block ( & mut self , cx : & LateContext < ' tcx > , block : & ' tcx hir:: Block < ' _ > ) {
98- fn count_closure_usage < ' tcx > ( block : & ' tcx hir:: Block < ' _ > , path : & ' tcx hir:: Path < ' tcx > ) -> usize {
99- struct ClosureUsageCount < ' tcx > {
98+ fn count_closure_usage < ' a , ' tcx > (
99+ cx : & ' a LateContext < ' tcx > ,
100+ block : & ' tcx hir:: Block < ' _ > ,
101+ path : & ' tcx hir:: Path < ' tcx > ,
102+ ) -> usize {
103+ struct ClosureUsageCount < ' a , ' tcx > {
104+ cx : & ' a LateContext < ' tcx > ,
100105 path : & ' tcx hir:: Path < ' tcx > ,
101106 count : usize ,
102107 } ;
103- impl < ' tcx > hir_visit:: Visitor < ' tcx > for ClosureUsageCount < ' tcx > {
108+ impl < ' a , ' tcx > hir_visit:: Visitor < ' tcx > for ClosureUsageCount < ' a , ' tcx > {
104109 type Map = Map < ' tcx > ;
105110
106111 fn visit_expr ( & mut self , expr : & ' tcx hir:: Expr < ' tcx > ) {
@@ -117,10 +122,10 @@ impl<'tcx> LateLintPass<'tcx> for RedundantClosureCall {
117122 }
118123
119124 fn nested_visit_map ( & mut self ) -> hir_visit:: NestedVisitorMap < Self :: Map > {
120- hir_visit:: NestedVisitorMap :: None
125+ hir_visit:: NestedVisitorMap :: OnlyBodies ( self . cx . tcx . hir ( ) )
121126 }
122127 } ;
123- let mut closure_usage_count = ClosureUsageCount { path, count : 0 } ;
128+ let mut closure_usage_count = ClosureUsageCount { cx , path, count : 0 } ;
124129 closure_usage_count. visit_block ( block) ;
125130 closure_usage_count. count
126131 }
@@ -136,7 +141,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantClosureCall {
136141 if let hir:: ExprKind :: Call ( ref closure, _) = call. kind;
137142 if let hir:: ExprKind :: Path ( hir:: QPath :: Resolved ( _, ref path) ) = closure. kind;
138143 if ident == path. segments[ 0 ] . ident;
139- if count_closure_usage( block, path) == 1 ;
144+ if count_closure_usage( cx , block, path) == 1 ;
140145 then {
141146 span_lint(
142147 cx,
0 commit comments