@@ -13,7 +13,7 @@ use crate::ty::{self, DefIdTree, GenericParamDefKind, TyCtxt};
1313
1414use crate :: rustc:: lint;
1515use crate :: session:: Session ;
16- use crate :: util:: nodemap:: { DefIdMap , FxHashMap , FxHashSet , NodeMap , NodeSet } ;
16+ use crate :: util:: nodemap:: { DefIdMap , FxHashMap , FxHashSet , HirIdMap , NodeMap , NodeSet } ;
1717use errors:: { Applicability , DiagnosticBuilder } ;
1818use rustc_data_structures:: sync:: Lrc ;
1919use std:: borrow:: Cow ;
@@ -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,7 +195,7 @@ 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
@@ -385,8 +385,7 @@ fn resolve_lifetimes<'tcx>(
385385
386386 let mut rl = ResolveLifetimes :: default ( ) ;
387387
388- for ( k, v) in named_region_map. defs {
389- let hir_id = tcx. hir ( ) . node_to_hir_id ( k) ;
388+ for ( hir_id, v) in named_region_map. defs {
390389 let map = rl. defs . entry ( hir_id. owner_local_def_id ( ) ) . or_default ( ) ;
391390 Lrc :: get_mut ( map) . unwrap ( ) . insert ( hir_id. local_id , v) ;
392391 }
@@ -570,7 +569,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
570569 }
571570
572571 fn visit_ty ( & mut self , ty : & ' tcx hir:: Ty ) {
573- debug ! ( "visit_ty: id={:?} ty={:?}" , ty. id , ty) ;
572+ debug ! ( "visit_ty: id={:?} ty={:?}" , ty. hir_id , ty) ;
574573 match ty. node {
575574 hir:: TyKind :: BareFn ( ref c) => {
576575 let next_early_index = self . next_early_index ( ) ;
@@ -629,7 +628,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
629628 hir:: TyKind :: Rptr ( ref lifetime_ref, ref mt) => {
630629 self . visit_lifetime ( lifetime_ref) ;
631630 let scope = Scope :: ObjectLifetimeDefault {
632- lifetime : self . map . defs . get ( & lifetime_ref. id ) . cloned ( ) ,
631+ lifetime : self . map . defs . get ( & lifetime_ref. hir_id ) . cloned ( ) ,
633632 s : self . scope ,
634633 } ;
635634 self . with ( scope, |_, this| this. visit_ty ( & mt. ty ) ) ;
@@ -672,7 +671,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
672671 // and ban them. Type variables instantiated inside binders aren't
673672 // well-supported at the moment, so this doesn't work.
674673 // In the future, this should be fixed and this error should be removed.
675- let def = self . map . defs . get ( & lifetime. id ) . cloned ( ) ;
674+ let def = self . map . defs . get ( & lifetime. hir_id ) . cloned ( ) ;
676675 if let Some ( Region :: LateBound ( _, def_id, _) ) = def {
677676 if let Some ( node_id) = self . tcx . hir ( ) . as_local_node_id ( def_id) {
678677 // Ensure that the parent of the def is an item, not HRTB
@@ -1501,8 +1500,10 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
15011500 }
15021501 }
15031502 } ;
1504- if let Node :: Lifetime ( hir_lifetime) = self . tcx . hir ( ) . get ( lifetime. id ) {
1505- if let Some ( parent) = self . tcx . hir ( ) . find ( self . tcx . hir ( ) . get_parent ( hir_lifetime. id ) ) {
1503+ if let Node :: Lifetime ( hir_lifetime) = self . tcx . hir ( ) . get_by_hir_id ( lifetime. hir_id ) {
1504+ if let Some ( parent) = self . tcx . hir ( ) . find_by_hir_id (
1505+ self . tcx . hir ( ) . get_parent_item ( hir_lifetime. hir_id ) )
1506+ {
15061507 match parent {
15071508 Node :: Item ( item) => {
15081509 if let hir:: ItemKind :: Fn ( decl, _, _, _) = & item. node {
@@ -1582,22 +1583,22 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
15821583 debug ! ( "node id first={:?}" , node_id) ;
15831584 if let Some ( ( id, span, name) ) = match self . tcx . hir ( ) . get ( node_id) {
15841585 Node :: Lifetime ( hir_lifetime) => Some ( (
1585- hir_lifetime. id ,
1586+ hir_lifetime. hir_id ,
15861587 hir_lifetime. span ,
15871588 hir_lifetime. name . ident ( ) ,
15881589 ) ) ,
15891590 Node :: GenericParam ( param) => {
1590- Some ( ( param. id , param. span , param. name . ident ( ) ) )
1591+ Some ( ( param. hir_id , param. span , param. name . ident ( ) ) )
15911592 }
15921593 _ => None ,
15931594 } {
1594- debug ! ( "id = {:?} span = {:?} name = {:?}" , node_id , span, name) ;
1595+ debug ! ( "id = {:?} span = {:?} name = {:?}" , id , span, name) ;
15951596
15961597 if name == keywords:: UnderscoreLifetime . ident ( ) {
15971598 continue ;
15981599 }
15991600
1600- let mut err = self . tcx . struct_span_lint_node (
1601+ let mut err = self . tcx . struct_span_lint_hir (
16011602 lint:: builtin:: SINGLE_USE_LIFETIMES ,
16021603 id,
16031604 span,
@@ -1622,17 +1623,17 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
16221623 let node_id = self . tcx . hir ( ) . as_local_node_id ( def_id) . unwrap ( ) ;
16231624 if let Some ( ( id, span, name) ) = match self . tcx . hir ( ) . get ( node_id) {
16241625 Node :: Lifetime ( hir_lifetime) => Some ( (
1625- hir_lifetime. id ,
1626+ hir_lifetime. hir_id ,
16261627 hir_lifetime. span ,
16271628 hir_lifetime. name . ident ( ) ,
16281629 ) ) ,
16291630 Node :: GenericParam ( param) => {
1630- Some ( ( param. id , param. span , param. name . ident ( ) ) )
1631+ Some ( ( param. hir_id , param. span , param. name . ident ( ) ) )
16311632 }
16321633 _ => None ,
16331634 } {
1634- debug ! ( "id ={:?} span = {:?} name = {:?}" , node_id , span, name) ;
1635- let mut err = self . tcx . struct_span_lint_node (
1635+ debug ! ( "id ={:?} span = {:?} name = {:?}" , id , span, name) ;
1636+ let mut err = self . tcx . struct_span_lint_hir (
16361637 lint:: builtin:: UNUSED_LIFETIMES ,
16371638 id,
16381639 span,
@@ -2049,8 +2050,8 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
20492050 // and whether there's a `self` argument (treated specially).
20502051 let mut assoc_item_kind = None ;
20512052 let mut impl_self = None ;
2052- let parent = self . tcx . hir ( ) . get_parent_node ( output. id ) ;
2053- let body = match self . tcx . hir ( ) . get ( parent) {
2053+ let parent = self . tcx . hir ( ) . get_parent_node_by_hir_id ( output. hir_id ) ;
2054+ let body = match self . tcx . hir ( ) . get_by_hir_id ( parent) {
20542055 // `fn` definitions and methods.
20552056 Node :: Item ( & hir:: Item {
20562057 node : hir:: ItemKind :: Fn ( .., body) ,
@@ -2063,12 +2064,13 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
20632064 } ) => {
20642065 if let hir:: ItemKind :: Trait ( .., ref trait_items) = self . tcx
20652066 . hir ( )
2066- . expect_item ( self . tcx . hir ( ) . get_parent ( parent) )
2067+ . expect_item_by_hir_id ( self . tcx . hir ( ) . get_parent_item ( parent) )
20672068 . node
20682069 {
2070+ let parent_node_id = self . tcx . hir ( ) . hir_to_node_id ( parent) ;
20692071 assoc_item_kind = trait_items
20702072 . iter ( )
2071- . find ( |ti| ti. id . node_id == parent )
2073+ . find ( |ti| ti. id . node_id == parent_node_id )
20722074 . map ( |ti| ti. kind ) ;
20732075 }
20742076 match * m {
@@ -2083,13 +2085,14 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
20832085 } ) => {
20842086 if let hir:: ItemKind :: Impl ( .., ref self_ty, ref impl_items) = self . tcx
20852087 . hir ( )
2086- . expect_item ( self . tcx . hir ( ) . get_parent ( parent) )
2088+ . expect_item_by_hir_id ( self . tcx . hir ( ) . get_parent_item ( parent) )
20872089 . node
20882090 {
20892091 impl_self = Some ( self_ty) ;
2092+ let parent_node_id = self . tcx . hir ( ) . hir_to_node_id ( parent) ;
20902093 assoc_item_kind = impl_items
20912094 . iter ( )
2092- . find ( |ii| ii. id . node_id == parent )
2095+ . find ( |ii| ii. id . node_id == parent_node_id )
20932096 . map ( |ii| ii. kind ) ;
20942097 }
20952098 Some ( body)
@@ -2143,7 +2146,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
21432146 if let hir:: TyKind :: Rptr ( lifetime_ref, ref mt) = inputs[ 0 ] . node {
21442147 if let hir:: TyKind :: Path ( hir:: QPath :: Resolved ( None , ref path) ) = mt. ty . node {
21452148 if is_self_ty ( path. def ) {
2146- if let Some ( & lifetime) = self . map . defs . get ( & lifetime_ref. id ) {
2149+ if let Some ( & lifetime) = self . map . defs . get ( & lifetime_ref. hir_id ) {
21472150 let scope = Scope :: Elision {
21482151 elide : Elide :: Exact ( lifetime) ,
21492152 s : self . scope ,
@@ -2262,7 +2265,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
22622265 }
22632266
22642267 fn visit_lifetime ( & mut self , lifetime_ref : & hir:: Lifetime ) {
2265- if let Some ( & lifetime) = self . map . defs . get ( & lifetime_ref. id ) {
2268+ if let Some ( & lifetime) = self . map . defs . get ( & lifetime_ref. hir_id ) {
22662269 match lifetime {
22672270 Region :: LateBound ( debruijn, _, _) | Region :: LateBoundAnon ( debruijn, _)
22682271 if debruijn < self . outer_index =>
@@ -2653,7 +2656,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
26532656 }
26542657
26552658 fn insert_lifetime ( & mut self , lifetime_ref : & ' tcx hir:: Lifetime , def : Region ) {
2656- if lifetime_ref. id == ast :: DUMMY_NODE_ID {
2659+ if lifetime_ref. hir_id == hir :: DUMMY_HIR_ID {
26572660 span_bug ! (
26582661 lifetime_ref. span,
26592662 "lifetime reference not renumbered, \
@@ -2663,11 +2666,11 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
26632666
26642667 debug ! (
26652668 "insert_lifetime: {} resolved to {:?} span={:?}" ,
2666- self . tcx. hir( ) . node_to_string ( lifetime_ref. id ) ,
2669+ self . tcx. hir( ) . hir_to_string ( lifetime_ref. hir_id ) ,
26672670 def,
26682671 self . tcx. sess. source_map( ) . span_to_string( lifetime_ref. span)
26692672 ) ;
2670- self . map . defs . insert ( lifetime_ref. id , def) ;
2673+ self . map . defs . insert ( lifetime_ref. hir_id , def) ;
26712674
26722675 match def {
26732676 Region :: LateBoundAnon ( ..) | Region :: Static => {
@@ -2699,7 +2702,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
26992702 /// error (esp. around impl trait). In that case, we remove the
27002703 /// entry into `map.defs` so as not to confuse later code.
27012704 fn uninsert_lifetime_on_error ( & mut self , lifetime_ref : & ' tcx hir:: Lifetime , bad_def : Region ) {
2702- let old_value = self . map . defs . remove ( & lifetime_ref. id ) ;
2705+ let old_value = self . map . defs . remove ( & lifetime_ref. hir_id ) ;
27032706 assert_eq ! ( old_value, Some ( bad_def) ) ;
27042707 }
27052708}
0 commit comments