@@ -185,19 +185,15 @@ struct IterFunctionVisitor<'a, 'tcx> {
185
185
impl < ' tcx > Visitor < ' tcx > for IterFunctionVisitor < ' _ , ' tcx > {
186
186
fn visit_block ( & mut self , block : & ' tcx Block < ' tcx > ) {
187
187
for ( expr, hir_id) in block. stmts . iter ( ) . filter_map ( get_expr_and_hir_id_from_stmt) {
188
- if is_loop ( expr) {
188
+ if check_loop_kind ( expr) . is_some ( ) {
189
189
continue ;
190
190
}
191
191
self . visit_block_expr ( expr, hir_id) ;
192
192
}
193
193
if let Some ( expr) = block. expr {
194
- if is_loop ( expr) {
195
- if let Some ( higher:: WhileLet { let_expr, .. } ) = higher:: WhileLet :: hir ( expr) {
196
- self . visit_block_expr ( let_expr, None ) ;
197
- } else if let Some ( higher:: While { condition, .. } ) = higher:: While :: hir ( expr) {
198
- self . visit_block_expr ( condition, None ) ;
199
- } else if let Some ( higher:: ForLoop { arg, .. } ) = higher:: ForLoop :: hir ( expr) {
200
- self . visit_block_expr ( arg, None ) ;
194
+ if let Some ( loop_kind) = check_loop_kind ( expr) {
195
+ if let LoopKind :: Conditional ( block_expr) = loop_kind {
196
+ self . visit_block_expr ( block_expr, None ) ;
201
197
}
202
198
} else {
203
199
self . visit_block_expr ( expr, None ) ;
@@ -278,21 +274,26 @@ impl<'tcx> Visitor<'tcx> for IterFunctionVisitor<'_, 'tcx> {
278
274
}
279
275
}
280
276
281
- fn is_loop ( expr : & Expr < ' _ > ) -> bool {
282
- if let Some ( higher:: WhileLet { .. } ) = higher:: WhileLet :: hir ( expr) {
283
- return true ;
277
+ enum LoopKind < ' tcx > {
278
+ Conditional ( & ' tcx Expr < ' tcx > ) ,
279
+ Loop ,
280
+ }
281
+
282
+ fn check_loop_kind < ' tcx > ( expr : & Expr < ' tcx > ) -> Option < LoopKind < ' tcx > > {
283
+ if let Some ( higher:: WhileLet { let_expr, .. } ) = higher:: WhileLet :: hir ( expr) {
284
+ return Some ( LoopKind :: Conditional ( let_expr) ) ;
284
285
}
285
- if let Some ( higher:: While { .. } ) = higher:: While :: hir ( expr) {
286
- return true ;
286
+ if let Some ( higher:: While { condition , .. } ) = higher:: While :: hir ( expr) {
287
+ return Some ( LoopKind :: Conditional ( condition ) ) ;
287
288
}
288
- if let Some ( higher:: ForLoop { .. } ) = higher:: ForLoop :: hir ( expr) {
289
- return true ;
289
+ if let Some ( higher:: ForLoop { arg , .. } ) = higher:: ForLoop :: hir ( expr) {
290
+ return Some ( LoopKind :: Conditional ( arg ) ) ;
290
291
}
291
292
if let ExprKind :: Loop { .. } = expr. kind {
292
- return true ;
293
+ return Some ( LoopKind :: Loop ) ;
293
294
}
294
295
295
- false
296
+ None
296
297
}
297
298
298
299
impl < ' tcx > IterFunctionVisitor < ' _ , ' tcx > {
0 commit comments