@@ -77,7 +77,7 @@ impl EarlyLintPass for RedundantClosureCall {
77
77
cx,
78
78
REDUNDANT_CLOSURE_CALL ,
79
79
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" ,
81
81
|diag| {
82
82
if decl. inputs. is_empty( ) {
83
83
let mut app = Applicability :: MachineApplicable ;
@@ -95,12 +95,17 @@ impl EarlyLintPass for RedundantClosureCall {
95
95
96
96
impl < ' tcx > LateLintPass < ' tcx > for RedundantClosureCall {
97
97
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 > ,
100
105
path : & ' tcx hir:: Path < ' tcx > ,
101
106
count : usize ,
102
107
} ;
103
- impl < ' tcx > hir_visit:: Visitor < ' tcx > for ClosureUsageCount < ' tcx > {
108
+ impl < ' a , ' tcx > hir_visit:: Visitor < ' tcx > for ClosureUsageCount < ' a , ' tcx > {
104
109
type Map = Map < ' tcx > ;
105
110
106
111
fn visit_expr ( & mut self , expr : & ' tcx hir:: Expr < ' tcx > ) {
@@ -117,10 +122,10 @@ impl<'tcx> LateLintPass<'tcx> for RedundantClosureCall {
117
122
}
118
123
119
124
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 ( ) )
121
126
}
122
127
} ;
123
- let mut closure_usage_count = ClosureUsageCount { path, count : 0 } ;
128
+ let mut closure_usage_count = ClosureUsageCount { cx , path, count : 0 } ;
124
129
closure_usage_count. visit_block ( block) ;
125
130
closure_usage_count. count
126
131
}
@@ -136,7 +141,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantClosureCall {
136
141
if let hir:: ExprKind :: Call ( ref closure, _) = call. kind;
137
142
if let hir:: ExprKind :: Path ( hir:: QPath :: Resolved ( _, ref path) ) = closure. kind;
138
143
if ident == path. segments[ 0 ] . ident;
139
- if count_closure_usage( block, path) == 1 ;
144
+ if count_closure_usage( cx , block, path) == 1 ;
140
145
then {
141
146
span_lint(
142
147
cx,
0 commit comments