@@ -465,11 +465,12 @@ impl<'db> SemanticsImpl<'db> {
465
465
} ;
466
466
let sa = self . analyze ( & parent) ;
467
467
let mut queue = vec ! [ InFile :: new( sa. file_id, token) ] ;
468
+ let mut cache = self . expansion_info_cache . borrow_mut ( ) ;
468
469
let mut res = smallvec ! [ ] ;
469
470
while let Some ( token) = queue. pop ( ) {
470
471
self . db . unwind_if_cancelled ( ) ;
471
472
472
- let mapped = ( || {
473
+ let was_not_remapped = ( || {
473
474
for node in token. value . ancestors ( ) {
474
475
match_ast ! {
475
476
match node {
@@ -487,7 +488,6 @@ impl<'db> SemanticsImpl<'db> {
487
488
return None ;
488
489
}
489
490
let file_id = sa. expand( self . db, token. with_value( & macro_call) ) ?;
490
- let mut cache = self . expansion_info_cache. borrow_mut( ) ;
491
491
let tokens = cache
492
492
. entry( file_id)
493
493
. or_insert_with( || file_id. expansion_info( self . db. upcast( ) ) )
@@ -503,36 +503,31 @@ impl<'db> SemanticsImpl<'db> {
503
503
return ( queue. len( ) != len) . then( || ( ) ) ;
504
504
} ,
505
505
ast:: Item ( item) => {
506
- match self . with_ctx( |ctx| ctx. item_to_macro_call( token. with_value( item) ) ) {
507
- Some ( call_id) => {
508
- let file_id = call_id. as_file( ) ;
509
- let mut cache = self . expansion_info_cache. borrow_mut( ) ;
510
- let tokens = cache
511
- . entry( file_id)
512
- . or_insert_with( || file_id. expansion_info( self . db. upcast( ) ) )
513
- . as_ref( ) ?
514
- . map_token_down( self . db. upcast( ) , None , token. as_ref( ) ) ?;
515
-
516
- let len = queue. len( ) ;
517
- queue. extend( tokens. inspect( |token| {
518
- if let Some ( parent) = token. value. parent( ) {
519
- self . cache( find_root( & parent) , token. file_id) ;
520
- }
521
- } ) ) ;
522
- return ( queue. len( ) != len) . then( || ( ) ) ;
523
- }
524
- None => { }
506
+ if let Some ( call_id) = self . with_ctx( |ctx| ctx. item_to_macro_call( token. with_value( item. clone( ) ) ) ) {
507
+ let file_id = call_id. as_file( ) ;
508
+ let tokens = cache
509
+ . entry( file_id)
510
+ . or_insert_with( || file_id. expansion_info( self . db. upcast( ) ) )
511
+ . as_ref( ) ?
512
+ . map_token_down( self . db. upcast( ) , Some ( item) , token. as_ref( ) ) ?;
513
+
514
+ let len = queue. len( ) ;
515
+ queue. extend( tokens. inspect( |token| {
516
+ if let Some ( parent) = token. value. parent( ) {
517
+ self . cache( find_root( & parent) , token. file_id) ;
518
+ }
519
+ } ) ) ;
520
+ return ( queue. len( ) != len) . then( || ( ) ) ;
525
521
}
526
522
} ,
527
523
_ => { }
528
524
}
529
525
}
530
526
}
531
527
None
532
- } ) ( ) ;
533
- match mapped {
534
- Some ( ( ) ) => ( ) ,
535
- None => res. push ( token. value ) ,
528
+ } ) ( ) . is_none ( ) ;
529
+ if was_not_remapped {
530
+ res. push ( token. value )
536
531
}
537
532
}
538
533
res
0 commit comments