@@ -12,6 +12,7 @@ use rustc_middle::hir::nested_filter::OnlyBodies;
1212use rustc_middle:: ty:: adjustment:: Adjust ;
1313use rustc_span:: symbol:: sym;
1414use rustc_span:: Symbol ;
15+ use std:: ops:: ControlFlow ;
1516
1617pub ( super ) fn check < ' tcx > ( cx : & LateContext < ' tcx > , expr : & ' tcx Expr < ' _ > ) {
1718 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
204205 uses_iter : bool ,
205206 }
206207 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 ) {
211211 self . uses_iter = true ;
212+ return ControlFlow :: Break ( ( ) ) ;
212213 } else if let ( e, true ) = skip_fields_and_path ( e) {
213214 if let Some ( e) = e {
214215 self . visit_expr ( e) ;
215216 }
216217 } else if let ExprKind :: Closure ( & Closure { body : id, .. } ) = e. kind {
217218 if is_res_used ( self . cx , self . iter_expr . path , id) {
218219 self . uses_iter = true ;
220+ return ControlFlow :: Break ( ( ) ) ;
219221 }
220- } else {
221- walk_expr ( self , e) ;
222222 }
223+ walk_expr ( self , e) ;
224+ ControlFlow :: Continue ( ( ) )
223225 }
224226 }
225227
@@ -243,31 +245,34 @@ fn needs_mutable_borrow(cx: &LateContext<'_>, iter_expr: &IterExpr, loop_expr: &
243245 }
244246 impl < ' tcx > Visitor < ' tcx > for AfterLoopVisitor < ' _ , ' _ , ' tcx > {
245247 type NestedFilter = OnlyBodies ;
248+ type Result = ControlFlow < ( ) > ;
246249 fn nested_visit_map ( & mut self ) -> Self :: Map {
247250 self . cx . tcx . hir ( )
248251 }
249252
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 < ( ) > {
254254 if self . after_loop {
255255 if is_expr_same_child_or_parent_field ( self . cx , e, & self . iter_expr . fields , self . iter_expr . path ) {
256256 self . used_iter = true ;
257+ return ControlFlow :: Break ( ( ) ) ;
257258 } else if let ( e, true ) = skip_fields_and_path ( e) {
258259 if let Some ( e) = e {
259260 self . visit_expr ( e) ;
260261 }
261262 } 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+ }
263267 } else {
264268 walk_expr ( self , e) ;
265269 }
266270 } else if self . loop_id == e. hir_id {
267271 self . after_loop = true ;
268- } else {
269- walk_expr ( self , e) ;
270272 }
273+
274+ walk_expr ( self , e) ;
275+ ControlFlow :: Continue ( ( ) )
271276 }
272277 }
273278
0 commit comments