@@ -12,6 +12,7 @@ use rustc_middle::hir::nested_filter::OnlyBodies;
12
12
use rustc_middle:: ty:: adjustment:: Adjust ;
13
13
use rustc_span:: symbol:: sym;
14
14
use rustc_span:: Symbol ;
15
+ use std:: ops:: ControlFlow ;
15
16
16
17
pub ( super ) fn check < ' tcx > ( cx : & LateContext < ' tcx > , expr : & ' tcx Expr < ' _ > ) {
17
18
if let Some ( higher:: WhileLet { if_then, let_pat, let_expr, .. } ) = higher:: WhileLet :: hir ( expr)
@@ -204,22 +205,23 @@ fn uses_iter<'tcx>(cx: &LateContext<'tcx>, iter_expr: &IterExpr, container: &'tc
204
205
uses_iter : bool ,
205
206
}
206
207
impl < ' tcx > Visitor < ' tcx > for V < ' _ , ' _ , ' tcx > {
207
- fn visit_expr ( & mut self , e : & ' tcx Expr < ' _ > ) {
208
- if self . uses_iter {
209
- // return
210
- } else if is_expr_same_child_or_parent_field ( self . cx , e, & self . iter_expr . fields , self . iter_expr . path ) {
208
+ type Result = ControlFlow < ( ) > ;
209
+ fn visit_expr ( & mut self , e : & ' tcx Expr < ' _ > ) -> ControlFlow < ( ) > {
210
+ if is_expr_same_child_or_parent_field ( self . cx , e, & self . iter_expr . fields , self . iter_expr . path ) {
211
211
self . uses_iter = true ;
212
+ return ControlFlow :: Break ( ( ) ) ;
212
213
} else if let ( e, true ) = skip_fields_and_path ( e) {
213
214
if let Some ( e) = e {
214
215
self . visit_expr ( e) ;
215
216
}
216
217
} else if let ExprKind :: Closure ( & Closure { body : id, .. } ) = e. kind {
217
218
if is_res_used ( self . cx , self . iter_expr . path , id) {
218
219
self . uses_iter = true ;
220
+ return ControlFlow :: Break ( ( ) ) ;
219
221
}
220
- } else {
221
- walk_expr ( self , e) ;
222
222
}
223
+ walk_expr ( self , e) ;
224
+ ControlFlow :: Continue ( ( ) )
223
225
}
224
226
}
225
227
@@ -243,31 +245,34 @@ fn needs_mutable_borrow(cx: &LateContext<'_>, iter_expr: &IterExpr, loop_expr: &
243
245
}
244
246
impl < ' tcx > Visitor < ' tcx > for AfterLoopVisitor < ' _ , ' _ , ' tcx > {
245
247
type NestedFilter = OnlyBodies ;
248
+ type Result = ControlFlow < ( ) > ;
246
249
fn nested_visit_map ( & mut self ) -> Self :: Map {
247
250
self . cx . tcx . hir ( )
248
251
}
249
252
250
- fn visit_expr ( & mut self , e : & ' tcx Expr < ' _ > ) {
251
- if self . used_iter {
252
- return ;
253
- }
253
+ fn visit_expr ( & mut self , e : & ' tcx Expr < ' _ > ) -> ControlFlow < ( ) > {
254
254
if self . after_loop {
255
255
if is_expr_same_child_or_parent_field ( self . cx , e, & self . iter_expr . fields , self . iter_expr . path ) {
256
256
self . used_iter = true ;
257
+ return ControlFlow :: Break ( ( ) ) ;
257
258
} else if let ( e, true ) = skip_fields_and_path ( e) {
258
259
if let Some ( e) = e {
259
260
self . visit_expr ( e) ;
260
261
}
261
262
} else if let ExprKind :: Closure ( & Closure { body : id, .. } ) = e. kind {
262
- self . used_iter = is_res_used ( self . cx , self . iter_expr . path , id) ;
263
+ if is_res_used ( self . cx , self . iter_expr . path , id) {
264
+ self . used_iter = true ;
265
+ return ControlFlow :: Break ( ( ) ) ;
266
+ }
263
267
} else {
264
268
walk_expr ( self , e) ;
265
269
}
266
270
} else if self . loop_id == e. hir_id {
267
271
self . after_loop = true ;
268
- } else {
269
- walk_expr ( self , e) ;
270
272
}
273
+
274
+ walk_expr ( self , e) ;
275
+ ControlFlow :: Continue ( ( ) )
271
276
}
272
277
}
273
278
0 commit comments