@@ -334,8 +334,10 @@ pub(crate) fn highlight_branches(
334
334
match token. kind ( ) {
335
335
T ! [ match ] => {
336
336
for token in sema. descend_into_macros ( token. clone ( ) ) {
337
- let Some ( match_expr) =
338
- sema. token_ancestors_with_macros ( token) . find_map ( ast:: MatchExpr :: cast)
337
+ let Some ( match_expr) = sema
338
+ . token_ancestors_with_macros ( token)
339
+ . take_while ( |node| !ast:: MacroCall :: can_cast ( node. kind ( ) ) )
340
+ . find_map ( ast:: MatchExpr :: cast)
339
341
else {
340
342
continue ;
341
343
} ;
@@ -355,11 +357,14 @@ pub(crate) fn highlight_branches(
355
357
}
356
358
T ! [ =>] => {
357
359
for token in sema. descend_into_macros ( token. clone ( ) ) {
358
- let Some ( arm) =
359
- sema. token_ancestors_with_macros ( token) . find_map ( ast:: MatchArm :: cast)
360
+ let Some ( arm) = sema
361
+ . token_ancestors_with_macros ( token)
362
+ . take_while ( |node| !ast:: MacroCall :: can_cast ( node. kind ( ) ) )
363
+ . find_map ( ast:: MatchArm :: cast)
360
364
else {
361
365
continue ;
362
366
} ;
367
+
363
368
let file_id = sema. hir_file_for ( arm. syntax ( ) ) ;
364
369
let range = arm. fat_arrow_token ( ) . map ( |token| token. text_range ( ) ) ;
365
370
push_to_highlights ( file_id, range, & mut highlights) ;
@@ -368,9 +373,11 @@ pub(crate) fn highlight_branches(
368
373
}
369
374
}
370
375
T ! [ if ] => {
371
- for tok in sema. descend_into_macros ( token. clone ( ) ) {
372
- let Some ( if_expr) =
373
- sema. token_ancestors_with_macros ( tok) . find_map ( ast:: IfExpr :: cast)
376
+ for token in sema. descend_into_macros ( token. clone ( ) ) {
377
+ let Some ( if_expr) = sema
378
+ . token_ancestors_with_macros ( token)
379
+ . take_while ( |node| !ast:: MacroCall :: can_cast ( node. kind ( ) ) )
380
+ . find_map ( ast:: IfExpr :: cast)
374
381
else {
375
382
continue ;
376
383
} ;
@@ -2481,6 +2488,27 @@ fn main() {
2481
2488
)
2482
2489
}
2483
2490
2491
+ #[ test]
2492
+ fn match_in_macro ( ) {
2493
+ // We should not highlight the outer `match` expression.
2494
+ check (
2495
+ r#"
2496
+ macro_rules! M {
2497
+ (match) => { 1 };
2498
+ }
2499
+
2500
+ fn main() {
2501
+ match Some(1) {
2502
+ Some(x) => x,
2503
+ None => {
2504
+ M!(match$0)
2505
+ }
2506
+ }
2507
+ }
2508
+ "# ,
2509
+ )
2510
+ }
2511
+
2484
2512
#[ test]
2485
2513
fn labeled_block_tail_expr ( ) {
2486
2514
check (
0 commit comments