@@ -252,6 +252,11 @@ pub fn is_pattern_cond(expr: ast::Expr) -> bool {
252
252
/// Note that modifying the tree while iterating it will cause undefined iteration which might
253
253
/// potentially results in an out of bounds panic.
254
254
pub fn for_each_tail_expr ( expr : & ast:: Expr , cb : & mut dyn FnMut ( & ast:: Expr ) ) {
255
+ let walk_loop = |cb : & mut dyn FnMut ( & ast:: Expr ) , label, body : Option < ast:: BlockExpr > | {
256
+ for_each_break_expr ( label, body. and_then ( |it| it. stmt_list ( ) ) , & mut |b| {
257
+ cb ( & ast:: Expr :: BreakExpr ( b) )
258
+ } )
259
+ } ;
255
260
match expr {
256
261
ast:: Expr :: BlockExpr ( b) => {
257
262
match b. modifier ( ) {
@@ -291,11 +296,9 @@ pub fn for_each_tail_expr(expr: &ast::Expr, cb: &mut dyn FnMut(&ast::Expr)) {
291
296
}
292
297
}
293
298
}
294
- ast:: Expr :: LoopExpr ( l) => {
295
- for_each_break_expr ( l. label ( ) , l. loop_body ( ) . and_then ( |it| it. stmt_list ( ) ) , & mut |b| {
296
- cb ( & ast:: Expr :: BreakExpr ( b) )
297
- } )
298
- }
299
+ ast:: Expr :: LoopExpr ( l) => walk_loop ( cb, l. label ( ) , l. loop_body ( ) ) ,
300
+ ast:: Expr :: WhileExpr ( w) => walk_loop ( cb, w. label ( ) , w. loop_body ( ) ) ,
301
+ ast:: Expr :: ForExpr ( f) => walk_loop ( cb, f. label ( ) , f. loop_body ( ) ) ,
299
302
ast:: Expr :: MatchExpr ( m) => {
300
303
if let Some ( arms) = m. match_arm_list ( ) {
301
304
arms. arms ( ) . filter_map ( |arm| arm. expr ( ) ) . for_each ( |e| for_each_tail_expr ( & e, cb) ) ;
@@ -311,7 +314,6 @@ pub fn for_each_tail_expr(expr: &ast::Expr, cb: &mut dyn FnMut(&ast::Expr)) {
311
314
| ast:: Expr :: ClosureExpr ( _)
312
315
| ast:: Expr :: ContinueExpr ( _)
313
316
| ast:: Expr :: FieldExpr ( _)
314
- | ast:: Expr :: ForExpr ( _)
315
317
| ast:: Expr :: IndexExpr ( _)
316
318
| ast:: Expr :: Literal ( _)
317
319
| ast:: Expr :: MacroExpr ( _)
@@ -325,7 +327,6 @@ pub fn for_each_tail_expr(expr: &ast::Expr, cb: &mut dyn FnMut(&ast::Expr)) {
325
327
| ast:: Expr :: ReturnExpr ( _)
326
328
| ast:: Expr :: TryExpr ( _)
327
329
| ast:: Expr :: TupleExpr ( _)
328
- | ast:: Expr :: WhileExpr ( _)
329
330
| ast:: Expr :: LetExpr ( _)
330
331
| ast:: Expr :: UnderscoreExpr ( _)
331
332
| ast:: Expr :: YieldExpr ( _)
0 commit comments