From 42efd211bcee72bfbcff340cc45db51a5b8906be Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Thu, 24 Jun 2021 21:01:37 +0200 Subject: [PATCH] Highlight label value block tails --- crates/ide/src/highlight_related.rs | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/crates/ide/src/highlight_related.rs b/crates/ide/src/highlight_related.rs index bc5e5eaebc5..8ec123cf8a7 100644 --- a/crates/ide/src/highlight_related.rs +++ b/crates/ide/src/highlight_related.rs @@ -294,7 +294,13 @@ fn for_each_inner_tail(expr: &ast::Expr, cb: &mut dyn FnMut(&ast::Expr)) { } } ast::Expr::EffectExpr(e) => match e.effect() { - ast::Effect::Label(_) | ast::Effect::Unsafe(_) => { + ast::Effect::Label(label) => { + for_each_break(Some(label), e.block_expr(), &mut |b| cb(&ast::Expr::BreakExpr(b))); + if let Some(b) = e.block_expr() { + for_each_inner_tail(&ast::Expr::BlockExpr(b), cb); + } + } + ast::Effect::Unsafe(_) => { if let Some(e) = e.block_expr().and_then(|b| b.tail_expr()) { for_each_inner_tail(&e, cb); } @@ -672,6 +678,27 @@ fn foo() ->$0 u32 { ); } + #[test] + fn test_hl_inner_tail_exit_points_labeled_block() { + check( + r#" +fn foo() ->$0 u32 { + 'foo: { + break 'foo 0; + // ^^^^^ + loop { + break; + break 'foo 0; + // ^^^^^ + } + 0 + // ^ + } +} +"#, + ); + } + #[test] fn test_hl_break_loop() { check(