@@ -252,6 +252,11 @@ pub fn is_pattern_cond(expr: ast::Expr) -> bool {
252252/// Note that modifying the tree while iterating it will cause undefined iteration which might
253253/// potentially results in an out of bounds panic.
254254pub 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+ } ;
255260 match expr {
256261 ast:: Expr :: BlockExpr ( b) => {
257262 match b. modifier ( ) {
@@ -291,11 +296,9 @@ pub fn for_each_tail_expr(expr: &ast::Expr, cb: &mut dyn FnMut(&ast::Expr)) {
291296 }
292297 }
293298 }
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 ( ) ) ,
299302 ast:: Expr :: MatchExpr ( m) => {
300303 if let Some ( arms) = m. match_arm_list ( ) {
301304 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)) {
311314 | ast:: Expr :: ClosureExpr ( _)
312315 | ast:: Expr :: ContinueExpr ( _)
313316 | ast:: Expr :: FieldExpr ( _)
314- | ast:: Expr :: ForExpr ( _)
315317 | ast:: Expr :: IndexExpr ( _)
316318 | ast:: Expr :: Literal ( _)
317319 | ast:: Expr :: MacroExpr ( _)
@@ -325,7 +327,6 @@ pub fn for_each_tail_expr(expr: &ast::Expr, cb: &mut dyn FnMut(&ast::Expr)) {
325327 | ast:: Expr :: ReturnExpr ( _)
326328 | ast:: Expr :: TryExpr ( _)
327329 | ast:: Expr :: TupleExpr ( _)
328- | ast:: Expr :: WhileExpr ( _)
329330 | ast:: Expr :: LetExpr ( _)
330331 | ast:: Expr :: UnderscoreExpr ( _)
331332 | ast:: Expr :: YieldExpr ( _)
0 commit comments