@@ -12,7 +12,6 @@ use hir_expand::{
12
12
} ;
13
13
use intern:: Interned ;
14
14
use la_arena:: { Arena , RawIdx } ;
15
- use once_cell:: unsync:: Lazy ;
16
15
use stdx:: impl_from;
17
16
use syntax:: ast:: { self , HasGenericParams , HasName , HasTypeBounds } ;
18
17
use triomphe:: Arc ;
@@ -394,11 +393,16 @@ impl GenericParams {
394
393
395
394
// Don't create an `Expander` if not needed since this
396
395
// could cause a reparse after the `ItemTree` has been created due to the spanmap.
397
- let mut expander = Lazy :: new ( || {
398
- ( module. def_map ( db) , Expander :: new ( db, loc. id . file_id ( ) , module) )
399
- } ) ;
396
+ let mut expander = None ;
400
397
for param in func_data. params . iter ( ) {
401
- generic_params. fill_implicit_impl_trait_args ( db, & mut expander, param) ;
398
+ generic_params. fill_implicit_impl_trait_args (
399
+ db,
400
+ & mut expander,
401
+ & mut || {
402
+ ( module. def_map ( db) , Expander :: new ( db, loc. id . file_id ( ) , module) )
403
+ } ,
404
+ param,
405
+ ) ;
402
406
}
403
407
Interned :: new ( generic_params. finish ( ) )
404
408
}
@@ -597,7 +601,9 @@ impl GenericParamsCollector {
597
601
fn fill_implicit_impl_trait_args (
598
602
& mut self ,
599
603
db : & dyn DefDatabase ,
600
- exp : & mut Lazy < ( Arc < DefMap > , Expander ) , impl FnOnce ( ) -> ( Arc < DefMap > , Expander ) > ,
604
+ // FIXME: Change this back to `LazyCell` if https://github.com/rust-lang/libs-team/issues/429 is accepted.
605
+ exp : & mut Option < ( Arc < DefMap > , Expander ) > ,
606
+ exp_fill : & mut dyn FnMut ( ) -> ( Arc < DefMap > , Expander ) ,
601
607
type_ref : & TypeRef ,
602
608
) {
603
609
type_ref. walk ( & mut |type_ref| {
@@ -617,7 +623,7 @@ impl GenericParamsCollector {
617
623
}
618
624
if let TypeRef :: Macro ( mc) = type_ref {
619
625
let macro_call = mc. to_node ( db. upcast ( ) ) ;
620
- let ( def_map, expander) = & mut * * exp ;
626
+ let ( def_map, expander) = exp . get_or_insert_with ( & mut * exp_fill ) ;
621
627
622
628
let module = expander. module . local_id ;
623
629
let resolver = |path : & _ | {
@@ -637,8 +643,8 @@ impl GenericParamsCollector {
637
643
{
638
644
let ctx = expander. ctx ( db) ;
639
645
let type_ref = TypeRef :: from_ast ( & ctx, expanded. tree ( ) ) ;
640
- self . fill_implicit_impl_trait_args ( db, & mut * exp, & type_ref) ;
641
- exp. 1 . exit ( mark) ;
646
+ self . fill_implicit_impl_trait_args ( db, & mut * exp, exp_fill , & type_ref) ;
647
+ exp. get_or_insert_with ( & mut * exp_fill ) . 1 . exit ( mark) ;
642
648
}
643
649
}
644
650
} ) ;
0 commit comments