@@ -23,7 +23,7 @@ use syntax::attr;
23
23
use syntax:: ptr:: P ;
24
24
use syntax:: symbol:: keywords;
25
25
use syntax_pos:: Span ;
26
- use util:: nodemap:: { DefIdMap , FxHashMap , FxHashSet , NodeMap , NodeSet } ;
26
+ use util:: nodemap:: { DefIdMap , FxHashMap , FxHashSet , HirIdMap , HirIdSet } ;
27
27
28
28
use hir:: intravisit:: { self , NestedVisitorMap , Visitor } ;
29
29
use hir:: { self , GenericParamKind , LifetimeParamKind } ;
@@ -151,7 +151,7 @@ impl Region {
151
151
if let Region :: EarlyBound ( index, _, _) = self {
152
152
params
153
153
. 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 ( ) )
155
155
} else {
156
156
Some ( self )
157
157
}
@@ -195,16 +195,16 @@ pub type ObjectLifetimeDefault = Set1<Region>;
195
195
struct NamedRegionMap {
196
196
// maps from every use of a named (not anonymous) lifetime to a
197
197
// `Region` describing how that region is bound
198
- pub defs : NodeMap < Region > ,
198
+ pub defs : HirIdMap < Region > ,
199
199
200
200
// the set of lifetime def ids that are late-bound; a region can
201
201
// be late-bound if (a) it does NOT appear in a where-clause and
202
202
// (b) it DOES appear in the arguments.
203
- pub late_bound : NodeSet ,
203
+ pub late_bound : HirIdSet ,
204
204
205
205
// For each type and trait definition, maps type parameters
206
206
// 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 > > ,
208
208
}
209
209
210
210
/// See `NamedRegionMap`.
@@ -387,20 +387,17 @@ fn resolve_lifetimes<'tcx>(
387
387
388
388
let mut rl = ResolveLifetimes :: default ( ) ;
389
389
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 {
392
391
let map = rl. defs . entry ( hir_id. owner_local_def_id ( ) ) . or_default ( ) ;
393
392
Lrc :: get_mut ( map) . unwrap ( ) . insert ( hir_id. local_id , v) ;
394
393
}
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 {
397
395
let map = rl. late_bound
398
396
. entry ( hir_id. owner_local_def_id ( ) )
399
397
. or_default ( ) ;
400
398
Lrc :: get_mut ( map) . unwrap ( ) . insert ( hir_id. local_id ) ;
401
399
}
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 {
404
401
let map = rl. object_lifetime_defaults
405
402
. entry ( hir_id. owner_local_def_id ( ) )
406
403
. or_default ( ) ;
@@ -634,7 +631,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
634
631
hir:: TyKind :: Rptr ( ref lifetime_ref, ref mt) => {
635
632
self . visit_lifetime ( lifetime_ref) ;
636
633
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 ( ) ,
638
635
s : self . scope ,
639
636
} ;
640
637
self . with ( scope, |_, this| this. visit_ty ( & mt. ty ) ) ;
@@ -677,7 +674,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
677
674
// and ban them. Type variables instantiated inside binders aren't
678
675
// well-supported at the moment, so this doesn't work.
679
676
// 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 ( ) ;
681
678
if let Some ( Region :: LateBound ( _, def_id, _) ) = def {
682
679
if let Some ( node_id) = self . tcx . hir ( ) . as_local_node_id ( def_id) {
683
680
// 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) {
1267
1264
1268
1265
fn compute_object_lifetime_defaults (
1269
1266
tcx : TyCtxt < ' _ , ' _ , ' _ > ,
1270
- ) -> NodeMap < Vec < ObjectLifetimeDefault > > {
1271
- let mut map = NodeMap :: default ( ) ;
1267
+ ) -> HirIdMap < Vec < ObjectLifetimeDefault > > {
1268
+ let mut map = HirIdMap :: default ( ) ;
1272
1269
for item in tcx. hir ( ) . krate ( ) . items . values ( ) {
1273
1270
match item. node {
1274
1271
hir:: ItemKind :: Struct ( _, ref generics)
@@ -1312,7 +1309,7 @@ fn compute_object_lifetime_defaults(
1312
1309
tcx. sess . span_err ( item. span , & object_lifetime_default_reprs) ;
1313
1310
}
1314
1311
1315
- map. insert ( item. id , result) ;
1312
+ map. insert ( item. hir_id , result) ;
1316
1313
}
1317
1314
_ => { }
1318
1315
}
@@ -1711,7 +1708,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
1711
1708
. iter ( )
1712
1709
. filter_map ( |param| match param. kind {
1713
1710
GenericParamKind :: Lifetime { .. } => {
1714
- if self . map . late_bound . contains ( & param. id ) {
1711
+ if self . map . late_bound . contains ( & param. hir_id ) {
1715
1712
Some ( Region :: late ( & self . tcx . hir ( ) , param) )
1716
1713
} else {
1717
1714
Some ( Region :: early ( & self . tcx . hir ( ) , & mut index, param) )
@@ -1957,8 +1954,10 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
1957
1954
} ;
1958
1955
1959
1956
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]
1962
1961
} else {
1963
1962
let tcx = self . tcx ;
1964
1963
self . xcrate_object_lifetime_defaults
@@ -2145,7 +2144,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
2145
2144
if let hir:: TyKind :: Rptr ( lifetime_ref, ref mt) = inputs[ 0 ] . node {
2146
2145
if let hir:: TyKind :: Path ( hir:: QPath :: Resolved ( None , ref path) ) = mt. ty . node {
2147
2146
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 ) {
2149
2148
let scope = Scope :: Elision {
2150
2149
elide : Elide :: Exact ( lifetime) ,
2151
2150
s : self . scope ,
@@ -2264,7 +2263,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
2264
2263
}
2265
2264
2266
2265
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 ) {
2268
2267
match lifetime {
2269
2268
Region :: LateBound ( debruijn, _, _) | Region :: LateBoundAnon ( debruijn, _)
2270
2269
if debruijn < self . outer_index =>
@@ -2669,7 +2668,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
2669
2668
def,
2670
2669
self . tcx. sess. source_map( ) . span_to_string( lifetime_ref. span)
2671
2670
) ;
2672
- self . map . defs . insert ( lifetime_ref. id , def) ;
2671
+ self . map . defs . insert ( lifetime_ref. hir_id , def) ;
2673
2672
2674
2673
match def {
2675
2674
Region :: LateBoundAnon ( ..) | Region :: Static => {
@@ -2701,7 +2700,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
2701
2700
/// error (esp. around impl trait). In that case, we remove the
2702
2701
/// entry into `map.defs` so as not to confuse later code.
2703
2702
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 ) ;
2705
2704
assert_eq ! ( old_value, Some ( bad_def) ) ;
2706
2705
}
2707
2706
}
@@ -2793,7 +2792,7 @@ fn insert_late_bound_lifetimes(
2793
2792
param. id
2794
2793
) ;
2795
2794
2796
- let inserted = map. late_bound . insert ( param. id ) ;
2795
+ let inserted = map. late_bound . insert ( param. hir_id ) ;
2797
2796
assert ! ( inserted, "visited lifetime {:?} twice" , param. id) ;
2798
2797
}
2799
2798
0 commit comments