@@ -12,7 +12,6 @@ use hir_expand::{
1212} ;
1313use intern:: Interned ;
1414use la_arena:: { Arena , RawIdx } ;
15- use once_cell:: unsync:: Lazy ;
1615use stdx:: impl_from;
1716use syntax:: ast:: { self , HasGenericParams , HasName , HasTypeBounds } ;
1817use triomphe:: Arc ;
@@ -394,11 +393,16 @@ impl GenericParams {
394393
395394 // Don't create an `Expander` if not needed since this
396395 // 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 ;
400397 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+ ) ;
402406 }
403407 Interned :: new ( generic_params. finish ( ) )
404408 }
@@ -597,7 +601,9 @@ impl GenericParamsCollector {
597601 fn fill_implicit_impl_trait_args (
598602 & mut self ,
599603 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 ) ,
601607 type_ref : & TypeRef ,
602608 ) {
603609 type_ref. walk ( & mut |type_ref| {
@@ -617,7 +623,7 @@ impl GenericParamsCollector {
617623 }
618624 if let TypeRef :: Macro ( mc) = type_ref {
619625 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 ) ;
621627
622628 let module = expander. module . local_id ;
623629 let resolver = |path : & _ | {
@@ -637,8 +643,8 @@ impl GenericParamsCollector {
637643 {
638644 let ctx = expander. ctx ( db) ;
639645 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) ;
642648 }
643649 }
644650 } ) ;
0 commit comments