@@ -23,7 +23,7 @@ use syntax::attr;
2323use syntax:: ptr:: P ;
2424use syntax:: symbol:: keywords;
2525use syntax_pos:: Span ;
26- use util:: nodemap:: { DefIdMap , FxHashMap , FxHashSet , NodeMap , NodeSet } ;
26+ use util:: nodemap:: { DefIdMap , FxHashMap , FxHashSet , HirIdMap , HirIdSet } ;
2727
2828use hir:: intravisit:: { self , NestedVisitorMap , Visitor } ;
2929use hir:: { self , GenericParamKind , LifetimeParamKind } ;
@@ -151,7 +151,7 @@ impl Region {
151151 if let Region :: EarlyBound ( index, _, _) = self {
152152 params
153153 . nth ( index as usize )
154- . and_then ( |lifetime| map. defs . get ( & lifetime. id ) . cloned ( ) )
154+ . and_then ( |lifetime| map. defs . get ( & lifetime. hir_id ) . cloned ( ) )
155155 } else {
156156 Some ( self )
157157 }
@@ -195,16 +195,16 @@ pub type ObjectLifetimeDefault = Set1<Region>;
195195struct NamedRegionMap {
196196 // maps from every use of a named (not anonymous) lifetime to a
197197 // `Region` describing how that region is bound
198- pub defs : NodeMap < Region > ,
198+ pub defs : HirIdMap < Region > ,
199199
200200 // the set of lifetime def ids that are late-bound; a region can
201201 // be late-bound if (a) it does NOT appear in a where-clause and
202202 // (b) it DOES appear in the arguments.
203- pub late_bound : NodeSet ,
203+ pub late_bound : HirIdSet ,
204204
205205 // For each type and trait definition, maps type parameters
206206 // to the trait object lifetime defaults computed from them.
207- pub object_lifetime_defaults : NodeMap < Vec < ObjectLifetimeDefault > > ,
207+ pub object_lifetime_defaults : HirIdMap < Vec < ObjectLifetimeDefault > > ,
208208}
209209
210210/// See `NamedRegionMap`.
@@ -387,20 +387,17 @@ fn resolve_lifetimes<'tcx>(
387387
388388 let mut rl = ResolveLifetimes :: default ( ) ;
389389
390- for ( k, v) in named_region_map. defs {
391- let hir_id = tcx. hir ( ) . node_to_hir_id ( k) ;
390+ for ( hir_id, v) in named_region_map. defs {
392391 let map = rl. defs . entry ( hir_id. owner_local_def_id ( ) ) . or_default ( ) ;
393392 Lrc :: get_mut ( map) . unwrap ( ) . insert ( hir_id. local_id , v) ;
394393 }
395- for k in named_region_map. late_bound {
396- let hir_id = tcx. hir ( ) . node_to_hir_id ( k) ;
394+ for hir_id in named_region_map. late_bound {
397395 let map = rl. late_bound
398396 . entry ( hir_id. owner_local_def_id ( ) )
399397 . or_default ( ) ;
400398 Lrc :: get_mut ( map) . unwrap ( ) . insert ( hir_id. local_id ) ;
401399 }
402- for ( k, v) in named_region_map. object_lifetime_defaults {
403- let hir_id = tcx. hir ( ) . node_to_hir_id ( k) ;
400+ for ( hir_id, v) in named_region_map. object_lifetime_defaults {
404401 let map = rl. object_lifetime_defaults
405402 . entry ( hir_id. owner_local_def_id ( ) )
406403 . or_default ( ) ;
@@ -634,7 +631,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
634631 hir:: TyKind :: Rptr ( ref lifetime_ref, ref mt) => {
635632 self . visit_lifetime ( lifetime_ref) ;
636633 let scope = Scope :: ObjectLifetimeDefault {
637- lifetime : self . map . defs . get ( & lifetime_ref. id ) . cloned ( ) ,
634+ lifetime : self . map . defs . get ( & lifetime_ref. hir_id ) . cloned ( ) ,
638635 s : self . scope ,
639636 } ;
640637 self . with ( scope, |_, this| this. visit_ty ( & mt. ty ) ) ;
@@ -677,7 +674,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
677674 // and ban them. Type variables instantiated inside binders aren't
678675 // well-supported at the moment, so this doesn't work.
679676 // In the future, this should be fixed and this error should be removed.
680- let def = self . map . defs . get ( & lifetime. id ) . cloned ( ) ;
677+ let def = self . map . defs . get ( & lifetime. hir_id ) . cloned ( ) ;
681678 if let Some ( Region :: LateBound ( _, def_id, _) ) = def {
682679 if let Some ( node_id) = self . tcx . hir ( ) . as_local_node_id ( def_id) {
683680 // Ensure that the parent of the def is an item, not HRTB
@@ -1267,8 +1264,8 @@ fn extract_labels(ctxt: &mut LifetimeContext<'_, '_>, body: &hir::Body) {
12671264
12681265fn compute_object_lifetime_defaults (
12691266 tcx : TyCtxt < ' _ , ' _ , ' _ > ,
1270- ) -> NodeMap < Vec < ObjectLifetimeDefault > > {
1271- let mut map = NodeMap :: default ( ) ;
1267+ ) -> HirIdMap < Vec < ObjectLifetimeDefault > > {
1268+ let mut map = HirIdMap :: default ( ) ;
12721269 for item in tcx. hir ( ) . krate ( ) . items . values ( ) {
12731270 match item. node {
12741271 hir:: ItemKind :: Struct ( _, ref generics)
@@ -1312,7 +1309,7 @@ fn compute_object_lifetime_defaults(
13121309 tcx. sess . span_err ( item. span , & object_lifetime_default_reprs) ;
13131310 }
13141311
1315- map. insert ( item. id , result) ;
1312+ map. insert ( item. hir_id , result) ;
13161313 }
13171314 _ => { }
13181315 }
@@ -1711,7 +1708,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
17111708 . iter ( )
17121709 . filter_map ( |param| match param. kind {
17131710 GenericParamKind :: Lifetime { .. } => {
1714- if self . map . late_bound . contains ( & param. id ) {
1711+ if self . map . late_bound . contains ( & param. hir_id ) {
17151712 Some ( Region :: late ( & self . tcx . hir ( ) , param) )
17161713 } else {
17171714 Some ( Region :: early ( & self . tcx . hir ( ) , & mut index, param) )
@@ -1957,8 +1954,10 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
19571954 } ;
19581955
19591956 let map = & self . map ;
1960- let unsubst = if let Some ( id) = self . tcx . hir ( ) . as_local_node_id ( def_id) {
1961- & map. object_lifetime_defaults [ & id]
1957+ let hir = self . tcx . hir ( ) ;
1958+ let unsubst = if let Some ( node_id) = hir. as_local_node_id ( def_id) {
1959+ let hir_id = hir. definitions ( ) . node_to_hir_id ( node_id) ;
1960+ & map. object_lifetime_defaults [ & hir_id]
19621961 } else {
19631962 let tcx = self . tcx ;
19641963 self . xcrate_object_lifetime_defaults
@@ -2145,7 +2144,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
21452144 if let hir:: TyKind :: Rptr ( lifetime_ref, ref mt) = inputs[ 0 ] . node {
21462145 if let hir:: TyKind :: Path ( hir:: QPath :: Resolved ( None , ref path) ) = mt. ty . node {
21472146 if is_self_ty ( path. def ) {
2148- if let Some ( & lifetime) = self . map . defs . get ( & lifetime_ref. id ) {
2147+ if let Some ( & lifetime) = self . map . defs . get ( & lifetime_ref. hir_id ) {
21492148 let scope = Scope :: Elision {
21502149 elide : Elide :: Exact ( lifetime) ,
21512150 s : self . scope ,
@@ -2264,7 +2263,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
22642263 }
22652264
22662265 fn visit_lifetime ( & mut self , lifetime_ref : & hir:: Lifetime ) {
2267- if let Some ( & lifetime) = self . map . defs . get ( & lifetime_ref. id ) {
2266+ if let Some ( & lifetime) = self . map . defs . get ( & lifetime_ref. hir_id ) {
22682267 match lifetime {
22692268 Region :: LateBound ( debruijn, _, _) | Region :: LateBoundAnon ( debruijn, _)
22702269 if debruijn < self . outer_index =>
@@ -2669,7 +2668,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
26692668 def,
26702669 self . tcx. sess. source_map( ) . span_to_string( lifetime_ref. span)
26712670 ) ;
2672- self . map . defs . insert ( lifetime_ref. id , def) ;
2671+ self . map . defs . insert ( lifetime_ref. hir_id , def) ;
26732672
26742673 match def {
26752674 Region :: LateBoundAnon ( ..) | Region :: Static => {
@@ -2701,7 +2700,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
27012700 /// error (esp. around impl trait). In that case, we remove the
27022701 /// entry into `map.defs` so as not to confuse later code.
27032702 fn uninsert_lifetime_on_error ( & mut self , lifetime_ref : & ' tcx hir:: Lifetime , bad_def : Region ) {
2704- let old_value = self . map . defs . remove ( & lifetime_ref. id ) ;
2703+ let old_value = self . map . defs . remove ( & lifetime_ref. hir_id ) ;
27052704 assert_eq ! ( old_value, Some ( bad_def) ) ;
27062705 }
27072706}
@@ -2793,7 +2792,7 @@ fn insert_late_bound_lifetimes(
27932792 param. id
27942793 ) ;
27952794
2796- let inserted = map. late_bound . insert ( param. id ) ;
2795+ let inserted = map. late_bound . insert ( param. hir_id ) ;
27972796 assert ! ( inserted, "visited lifetime {:?} twice" , param. id) ;
27982797 }
27992798
0 commit comments