Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide_db/src/helpers.rs')
| -rw-r--r-- | crates/ide_db/src/helpers.rs | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/crates/ide_db/src/helpers.rs b/crates/ide_db/src/helpers.rs index 0fb6ca27b2..4c59629bc6 100644 --- a/crates/ide_db/src/helpers.rs +++ b/crates/ide_db/src/helpers.rs @@ -120,9 +120,7 @@ pub fn for_each_tail_expr(expr: &ast::Expr, cb: &mut dyn FnMut(&ast::Expr)) { ) => return cb(expr), Some(ast::BlockModifier::Label(label)) => { - for_each_break_expr(Some(label), b.stmt_list(), &mut |b| { - cb(&b) - }); + for_each_break_and_continue_expr(Some(label), b.stmt_list(), &mut |b| cb(&b)); } Some(ast::BlockModifier::Unsafe(_)) => (), None => (), @@ -149,16 +147,16 @@ pub fn for_each_tail_expr(expr: &ast::Expr, cb: &mut dyn FnMut(&ast::Expr)) { } } } - ast::Expr::LoopExpr(l) => { - for_each_break_expr(l.label(), l.loop_body().and_then(|it| it.stmt_list()), &mut |b| { - cb(&b) - }) - } + ast::Expr::LoopExpr(l) => for_each_break_and_continue_expr( + l.label(), + l.loop_body().and_then(|it| it.stmt_list()), + &mut |b| cb(&b), + ), ast::Expr::MatchExpr(m) => { if let Some(arms) = m.match_arm_list() { - arms.arms().filter_map(|arm| arm.expr()).for_each(|e| for_each_tail_expr(&e, &mut |b| { - cb(&b) - })); + arms.arms() + .filter_map(|arm| arm.expr()) + .for_each(|e| for_each_tail_expr(&e, &mut |b| cb(&b))); } } ast::Expr::ArrayExpr(_) @@ -192,8 +190,8 @@ pub fn for_each_tail_expr(expr: &ast::Expr, cb: &mut dyn FnMut(&ast::Expr)) { } } -/// Calls `cb` on each break expr inside of `body` that is applicable for the given label. -pub fn for_each_break_expr( +/// Calls `cb` on each break expr and continue expr inside of `body` that is applicable for the given label. +pub fn for_each_break_and_continue_expr( label: Option<ast::Label>, body: Option<ast::StmtList>, cb: &mut dyn FnMut(ast::Expr), @@ -221,6 +219,11 @@ pub fn for_each_break_expr( { cb(ast::Expr::BreakExpr(b)); } + ast::Expr::ContinueExpr(c) + if (depth == 0 && c.lifetime().is_none()) || eq_label(c.lifetime()) => + { + cb(ast::Expr::ContinueExpr(c)) + } _ => (), }, WalkEvent::Leave(expr) => match expr { |