@@ -55,7 +55,7 @@ use rustc_hir::definitions::PerParentDisambiguatorState;
5555use rustc_hir:: lints:: DelayedLint ;
5656use rustc_hir:: {
5757 self as hir, AngleBrackets , ConstArg , GenericArg , HirId , ItemLocalMap , LifetimeSource ,
58- LifetimeSyntax , ParamName , Target , TraitCandidate , find_attr,
58+ LifetimeSyntax , MissingLifetimeKind , ParamName , Target , TraitCandidate , find_attr,
5959} ;
6060use rustc_index:: { Idx , IndexSlice , IndexVec } ;
6161use rustc_macros:: extension;
@@ -293,24 +293,14 @@ impl<'tcx> ResolverAstLowering<'tcx> {
293293 self . import_res_map . get ( & id) . copied ( ) . unwrap_or_default ( )
294294 }
295295
296- /// Obtains resolution for a label with the given `NodeId`.
297- fn get_label_res ( & self , id : NodeId ) -> Option < NodeId > {
298- self . label_res_map . get ( & id) . copied ( )
299- }
300-
301- /// Obtains resolution for a lifetime with the given `NodeId`.
302- fn get_lifetime_res ( & self , id : NodeId ) -> Option < LifetimeRes > {
303- self . lifetimes_res_map . get ( & id) . copied ( )
304- }
305-
306296 /// Obtain the list of lifetimes parameters to add to an item.
307297 ///
308298 /// Extra lifetime parameters should only be added in places that can appear
309299 /// as a `binder` in `LifetimeRes`.
310300 ///
311301 /// The extra lifetimes that appear from the parenthesized `Fn`-trait desugaring
312302 /// should appear at the enclosing `PolyTraitRef`.
313- fn extra_lifetime_params ( & self , id : NodeId ) -> & [ ( Ident , NodeId , LifetimeRes ) ] {
303+ fn extra_lifetime_params ( & self , id : NodeId ) -> & [ ( Ident , NodeId , MissingLifetimeKind ) ] {
314304 self . extra_lifetime_params_map . get ( & id) . map_or ( & [ ] , |v| & v[ ..] )
315305 }
316306
@@ -321,10 +311,6 @@ impl<'tcx> ResolverAstLowering<'tcx> {
321311 fn owner_def_id ( & self , id : NodeId ) -> LocalDefId {
322312 self . owners [ & id] . def_id
323313 }
324-
325- fn lifetime_elision_allowed ( & self , id : NodeId ) -> bool {
326- self . lifetime_elision_allowed . contains ( & id)
327- }
328314}
329315
330316/// How relaxed bounds `?Trait` should be treated.
@@ -542,7 +528,7 @@ pub fn lower_to_hir(tcx: TyCtxt<'_>, (): ()) -> mid_hir::Crate<'_> {
542528 let ast_index = index_crate ( & resolver, & krate) ;
543529 let mut owners = IndexVec :: from_fn_n (
544530 |_| hir:: MaybeOwner :: Phantom ,
545- tcx. definitions_untracked ( ) . def_index_count ( ) ,
531+ tcx. definitions_untracked ( ) . num_definitions ( ) ,
546532 ) ;
547533
548534 let mut lowerer = item:: ItemLowerer {
@@ -948,43 +934,30 @@ impl<'hir> LoweringContext<'_, 'hir> {
948934 & mut self ,
949935 ident : Ident ,
950936 node_id : NodeId ,
951- res : LifetimeRes ,
937+ kind : MissingLifetimeKind ,
952938 source : hir:: GenericParamSource ,
953- ) -> Option < hir:: GenericParam < ' hir > > {
954- let ( name, kind) = match res {
955- LifetimeRes :: Param { .. } => {
956- ( hir:: ParamName :: Plain ( ident) , hir:: LifetimeParamKind :: Explicit )
957- }
958- LifetimeRes :: Fresh { param, kind, .. } => {
959- // Late resolution delegates to us the creation of the `LocalDefId`.
960- let _def_id = self . create_def (
961- param,
962- Some ( kw:: UnderscoreLifetime ) ,
963- DefKind :: LifetimeParam ,
964- ident. span ,
965- ) ;
966- debug ! ( ?_def_id) ;
939+ ) -> hir:: GenericParam < ' hir > {
940+ // Late resolution delegates to us the creation of the `LocalDefId`.
941+ let _def_id = self . create_def (
942+ node_id,
943+ Some ( kw:: UnderscoreLifetime ) ,
944+ DefKind :: LifetimeParam ,
945+ ident. span ,
946+ ) ;
947+ debug ! ( ?_def_id) ;
967948
968- ( hir:: ParamName :: Fresh , hir:: LifetimeParamKind :: Elided ( kind) )
969- }
970- LifetimeRes :: Static { .. } | LifetimeRes :: Error ( ..) => return None ,
971- res => panic ! (
972- "Unexpected lifetime resolution {:?} for {:?} at {:?}" ,
973- res, ident, ident. span
974- ) ,
975- } ;
976949 let hir_id = self . lower_node_id ( node_id) ;
977950 let def_id = self . local_def_id ( node_id) ;
978- Some ( hir:: GenericParam {
951+ hir:: GenericParam {
979952 hir_id,
980953 def_id,
981- name,
954+ name : hir :: ParamName :: Fresh ,
982955 span : self . lower_span ( ident. span ) ,
983956 pure_wrt_drop : false ,
984- kind : hir:: GenericParamKind :: Lifetime { kind } ,
957+ kind : hir:: GenericParamKind :: Lifetime { kind : hir :: LifetimeParamKind :: Elided ( kind ) } ,
985958 colon_span : None ,
986959 source,
987- } )
960+ }
988961 }
989962
990963 /// Lowers a lifetime binder that defines `generic_params`, returning the corresponding HIR
@@ -1005,7 +978,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
1005978 debug ! ( ?extra_lifetimes) ;
1006979 let extra_lifetimes: Vec < _ > = extra_lifetimes
1007980 . iter ( )
1008- . filter_map ( |& ( ident, node_id, res) | {
981+ . map ( |& ( ident, node_id, res) | {
1009982 self . lifetime_res_to_generic_param (
1010983 ident,
1011984 node_id,
@@ -1625,7 +1598,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
16251598
16261599 None => {
16271600 let id = if let Some ( LifetimeRes :: ElidedAnchor { start, end } ) =
1628- self . resolver . get_lifetime_res ( t. id )
1601+ self . owner . get_lifetime_res ( t. id )
16291602 {
16301603 assert_eq ! ( start. plus( 1 ) , end) ;
16311604 start
@@ -1866,7 +1839,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
18661839 _ => hir:: ImplicitSelfKind :: None ,
18671840 }
18681841 } ) )
1869- . set_lifetime_elision_allowed ( self . resolver . lifetime_elision_allowed ( fn_node_id) )
1842+ . set_lifetime_elision_allowed (
1843+ self . owner . id == fn_node_id && self . owner . lifetime_elision_allowed ,
1844+ )
18701845 . set_c_variadic ( c_variadic) ;
18711846
18721847 self . arena . alloc ( hir:: FnDecl { inputs, output, fn_decl_kind } )
@@ -2032,7 +2007,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
20322007 source : LifetimeSource ,
20332008 syntax : LifetimeSyntax ,
20342009 ) -> & ' hir hir:: Lifetime {
2035- let res = if let Some ( res) = self . resolver . get_lifetime_res ( id) {
2010+ let res = if let Some ( res) = self . owner . get_lifetime_res ( id) {
20362011 match res {
20372012 LifetimeRes :: Param { param, .. } => hir:: LifetimeKind :: Param ( param) ,
20382013 LifetimeRes :: Fresh { param, .. } => {
@@ -2118,13 +2093,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
21182093 // AST resolution emitted an error on those parameters, so we lower them using
21192094 // `ParamName::Error`.
21202095 let ident = self . lower_ident ( param. ident ) ;
2121- let param_name = if let Some ( LifetimeRes :: Error ( ..) ) =
2122- self . resolver . get_lifetime_res ( param. id )
2123- {
2124- ParamName :: Error ( ident)
2125- } else {
2126- ParamName :: Plain ( ident)
2127- } ;
2096+ let param_name =
2097+ if let Some ( LifetimeRes :: Error ( ..) ) = self . owner . get_lifetime_res ( param. id ) {
2098+ ParamName :: Error ( ident)
2099+ } else {
2100+ ParamName :: Plain ( ident)
2101+ } ;
21282102 let kind =
21292103 hir:: GenericParamKind :: Lifetime { kind : hir:: LifetimeParamKind :: Explicit } ;
21302104
0 commit comments