@@ -48,12 +48,11 @@ use rustc_ast_pretty::pprust;
4848use rustc_data_structures:: captures:: Captures ;
4949use rustc_data_structures:: fx:: FxIndexSet ;
5050use rustc_data_structures:: sorted_map:: SortedMap ;
51- use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher } ;
5251use rustc_data_structures:: steal:: Steal ;
5352use rustc_data_structures:: sync:: Lrc ;
5453use rustc_data_structures:: unord:: ExtendUnord ;
5554use rustc_errors:: { DiagArgFromDisplay , DiagCtxtHandle , StashKey } ;
56- use rustc_hir:: def:: { DefKind , LifetimeRes , Namespace , PartialRes , PerNS , Res } ;
55+ use rustc_hir:: def:: { DefKind , FreshLifetimeResId , LifetimeRes , Namespace , PartialRes , PerNS , Res } ;
5756use rustc_hir:: def_id:: { LocalDefId , LocalDefIdMap , LOCAL_CRATE } ;
5857use rustc_hir:: { self as hir} ;
5958use rustc_hir:: {
@@ -156,11 +155,7 @@ struct LoweringContext<'hir> {
156155}
157156
158157impl < ' hir > LoweringContext < ' hir > {
159- fn new (
160- tcx : TyCtxt < ' hir > ,
161- resolver : & ' hir ResolverAstLowering ,
162- owner : NodeId ,
163- ) -> Self {
158+ fn new ( tcx : TyCtxt < ' hir > , resolver : & ' hir ResolverAstLowering , owner : NodeId ) -> Self {
164159 let current_hir_id_owner = hir:: OwnerId { def_id : resolver. node_id_to_def_id [ & owner] } ;
165160 Self {
166161 // Pseudo-globals.
@@ -428,7 +423,6 @@ fn index_ast<'tcx>(tcx: TyCtxt<'tcx>, (): ()) -> &'tcx IndexVec<LocalDefId, Stea
428423 visit:: walk_item ( self , item) ;
429424 self . insert ( item. id , AstOwnerRef :: Item ( item) ) ;
430425 }
431-
432426
433427 fn visit_assoc_item ( & mut self , item : & ' ast AssocItem , ctxt : visit:: AssocCtxt ) {
434428 visit:: walk_item ( self , item) ;
@@ -820,6 +814,14 @@ impl<'hir> LoweringContext<'hir> {
820814 Ident :: new ( ident. name , self . lower_span ( ident. span ) )
821815 }
822816
817+ fn lower_fresh_lifetime_res ( & mut self , id : FreshLifetimeResId , node_id : NodeId ) -> LocalDefId {
818+ let def_id = self . tcx . fresh_lifetime_def_id ( id) ;
819+ // make sure that this `NodeId` is known to us.
820+ self . node_id_to_def_id . insert ( node_id, def_id) ;
821+ trace ! ( ?self . current_hir_id_owner, ?def_id) ;
822+ def_id
823+ }
824+
823825 /// Converts a lifetime into a new generic parameter.
824826 #[ instrument( level = "debug" , skip( self ) ) ]
825827 fn lifetime_res_to_generic_param (
@@ -833,17 +835,9 @@ impl<'hir> LoweringContext<'hir> {
833835 LifetimeRes :: Param { .. } => {
834836 ( hir:: ParamName :: Plain ( ident) , hir:: LifetimeParamKind :: Explicit )
835837 }
836- LifetimeRes :: Fresh { param, kind, .. } => {
837- // Late resolution delegates to us the creation of the `LocalDefId`.
838- let _def_id = self . create_def (
839- self . current_hir_id_owner . def_id ,
840- param,
841- kw:: UnderscoreLifetime ,
842- DefKind :: LifetimeParam ,
843- ident. span ,
844- ) ;
845- debug ! ( ?_def_id) ;
846-
838+ LifetimeRes :: Fresh { id, kind, param, .. } => {
839+ debug_assert_eq ! ( param, node_id) ;
840+ self . lower_fresh_lifetime_res ( id, node_id) ;
847841 ( hir:: ParamName :: Fresh , hir:: LifetimeParamKind :: Elided ( kind) )
848842 }
849843 LifetimeRes :: Static | LifetimeRes :: Error => return None ,
@@ -1697,15 +1691,9 @@ impl<'hir> LoweringContext<'hir> {
16971691 let ( old_def_id, missing_kind) = match res {
16981692 LifetimeRes :: Param { param : old_def_id, binder : _ } => ( old_def_id, None ) ,
16991693
1700- LifetimeRes :: Fresh { param , kind, .. } => {
1694+ LifetimeRes :: Fresh { id , kind, param , .. } => {
17011695 debug_assert_eq ! ( lifetime. ident. name, kw:: UnderscoreLifetime ) ;
1702- if let Some ( old_def_id) = self . orig_opt_local_def_id ( param) {
1703- ( old_def_id, Some ( kind) )
1704- } else {
1705- self . dcx ( )
1706- . span_delayed_bug ( lifetime. ident . span , "no def-id for fresh lifetime" ) ;
1707- continue ;
1708- }
1696+ ( self . tcx . fresh_lifetime_def_id ( id) , Some ( kind) )
17091697 }
17101698
17111699 // Opaques do not capture `'static`
@@ -2117,8 +2105,8 @@ impl<'hir> LoweringContext<'hir> {
21172105 let param = self . get_remapped_def_id ( param) ;
21182106 hir:: LifetimeName :: Param ( param)
21192107 }
2120- LifetimeRes :: Fresh { param , .. } => {
2121- let param = self . local_def_id ( param ) ;
2108+ LifetimeRes :: Fresh { id , .. } => {
2109+ let param = self . get_remapped_def_id ( self . tcx . fresh_lifetime_def_id ( id ) ) ;
21222110 hir:: LifetimeName :: Param ( param)
21232111 }
21242112 LifetimeRes :: Infer => hir:: LifetimeName :: Infer ,
0 commit comments