File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed
src/tools/rust-analyzer/crates/ide/src Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -232,6 +232,23 @@ fn highlight_references(
232232 }
233233 }
234234
235+ // highlight the tail expr of the labelled block
236+ if matches ! ( def, Definition :: Label ( _) ) {
237+ let label = token. parent_ancestors ( ) . nth ( 1 ) . and_then ( ast:: Label :: cast) ;
238+ if let Some ( block) =
239+ label. and_then ( |label| label. syntax ( ) . parent ( ) ) . and_then ( ast:: BlockExpr :: cast)
240+ {
241+ for_each_tail_expr ( & block. into ( ) , & mut |tail| {
242+ if !matches ! ( tail, ast:: Expr :: BreakExpr ( _) ) {
243+ res. insert ( HighlightedRange {
244+ range : tail. syntax ( ) . text_range ( ) ,
245+ category : ReferenceCategory :: empty ( ) ,
246+ } ) ;
247+ }
248+ } ) ;
249+ }
250+ }
251+
235252 // highlight the defs themselves
236253 match def {
237254 Definition :: Local ( local) => {
@@ -2098,6 +2115,26 @@ fn foo() {
20982115 // ^
20992116 }
21002117}
2118+ "# ,
2119+ ) ;
2120+ }
2121+
2122+ #[ test]
2123+ fn labeled_block_tail_expr_2 ( ) {
2124+ check (
2125+ r#"
2126+ fn foo() {
2127+ let _ = 'b$0lk: {
2128+ // ^^^^
2129+ let x = 1;
2130+ if true { break 'blk 42; }
2131+ // ^^^^
2132+ if false { break 'blk 24; }
2133+ // ^^^^
2134+ 100
2135+ // ^^^
2136+ };
2137+ }
21012138"# ,
21022139 ) ;
21032140 }
You can’t perform that action at this time.
0 commit comments