@@ -13,7 +13,7 @@ use crate::ty::{self, DefIdTree, GenericParamDefKind, TyCtxt};
13
13
14
14
use crate :: rustc:: lint;
15
15
use crate :: session:: Session ;
16
- use crate :: util:: nodemap:: { DefIdMap , FxHashMap , FxHashSet , NodeMap , NodeSet } ;
16
+ use crate :: util:: nodemap:: { DefIdMap , FxHashMap , FxHashSet , HirIdMap , NodeMap , NodeSet } ;
17
17
use errors:: { Applicability , DiagnosticBuilder } ;
18
18
use rustc_data_structures:: sync:: Lrc ;
19
19
use std:: borrow:: Cow ;
@@ -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,7 +195,7 @@ 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
@@ -385,8 +385,7 @@ fn resolve_lifetimes<'tcx>(
385
385
386
386
let mut rl = ResolveLifetimes :: default ( ) ;
387
387
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 {
390
389
let map = rl. defs . entry ( hir_id. owner_local_def_id ( ) ) . or_default ( ) ;
391
390
Lrc :: get_mut ( map) . unwrap ( ) . insert ( hir_id. local_id , v) ;
392
391
}
@@ -570,7 +569,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
570
569
}
571
570
572
571
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) ;
574
573
match ty. node {
575
574
hir:: TyKind :: BareFn ( ref c) => {
576
575
let next_early_index = self . next_early_index ( ) ;
@@ -629,7 +628,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
629
628
hir:: TyKind :: Rptr ( ref lifetime_ref, ref mt) => {
630
629
self . visit_lifetime ( lifetime_ref) ;
631
630
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 ( ) ,
633
632
s : self . scope ,
634
633
} ;
635
634
self . with ( scope, |_, this| this. visit_ty ( & mt. ty ) ) ;
@@ -672,7 +671,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
672
671
// and ban them. Type variables instantiated inside binders aren't
673
672
// well-supported at the moment, so this doesn't work.
674
673
// 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 ( ) ;
676
675
if let Some ( Region :: LateBound ( _, def_id, _) ) = def {
677
676
if let Some ( node_id) = self . tcx . hir ( ) . as_local_node_id ( def_id) {
678
677
// Ensure that the parent of the def is an item, not HRTB
@@ -1501,8 +1500,10 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
1501
1500
}
1502
1501
}
1503
1502
} ;
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
+ {
1506
1507
match parent {
1507
1508
Node :: Item ( item) => {
1508
1509
if let hir:: ItemKind :: Fn ( decl, _, _, _) = & item. node {
@@ -1582,22 +1583,22 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
1582
1583
debug ! ( "node id first={:?}" , node_id) ;
1583
1584
if let Some ( ( id, span, name) ) = match self . tcx . hir ( ) . get ( node_id) {
1584
1585
Node :: Lifetime ( hir_lifetime) => Some ( (
1585
- hir_lifetime. id ,
1586
+ hir_lifetime. hir_id ,
1586
1587
hir_lifetime. span ,
1587
1588
hir_lifetime. name . ident ( ) ,
1588
1589
) ) ,
1589
1590
Node :: GenericParam ( param) => {
1590
- Some ( ( param. id , param. span , param. name . ident ( ) ) )
1591
+ Some ( ( param. hir_id , param. span , param. name . ident ( ) ) )
1591
1592
}
1592
1593
_ => None ,
1593
1594
} {
1594
- debug ! ( "id = {:?} span = {:?} name = {:?}" , node_id , span, name) ;
1595
+ debug ! ( "id = {:?} span = {:?} name = {:?}" , id , span, name) ;
1595
1596
1596
1597
if name == keywords:: UnderscoreLifetime . ident ( ) {
1597
1598
continue ;
1598
1599
}
1599
1600
1600
- let mut err = self . tcx . struct_span_lint_node (
1601
+ let mut err = self . tcx . struct_span_lint_hir (
1601
1602
lint:: builtin:: SINGLE_USE_LIFETIMES ,
1602
1603
id,
1603
1604
span,
@@ -1622,17 +1623,17 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
1622
1623
let node_id = self . tcx . hir ( ) . as_local_node_id ( def_id) . unwrap ( ) ;
1623
1624
if let Some ( ( id, span, name) ) = match self . tcx . hir ( ) . get ( node_id) {
1624
1625
Node :: Lifetime ( hir_lifetime) => Some ( (
1625
- hir_lifetime. id ,
1626
+ hir_lifetime. hir_id ,
1626
1627
hir_lifetime. span ,
1627
1628
hir_lifetime. name . ident ( ) ,
1628
1629
) ) ,
1629
1630
Node :: GenericParam ( param) => {
1630
- Some ( ( param. id , param. span , param. name . ident ( ) ) )
1631
+ Some ( ( param. hir_id , param. span , param. name . ident ( ) ) )
1631
1632
}
1632
1633
_ => None ,
1633
1634
} {
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 (
1636
1637
lint:: builtin:: UNUSED_LIFETIMES ,
1637
1638
id,
1638
1639
span,
@@ -2049,8 +2050,8 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
2049
2050
// and whether there's a `self` argument (treated specially).
2050
2051
let mut assoc_item_kind = None ;
2051
2052
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) {
2054
2055
// `fn` definitions and methods.
2055
2056
Node :: Item ( & hir:: Item {
2056
2057
node : hir:: ItemKind :: Fn ( .., body) ,
@@ -2063,12 +2064,13 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
2063
2064
} ) => {
2064
2065
if let hir:: ItemKind :: Trait ( .., ref trait_items) = self . tcx
2065
2066
. hir ( )
2066
- . expect_item ( self . tcx . hir ( ) . get_parent ( parent) )
2067
+ . expect_item_by_hir_id ( self . tcx . hir ( ) . get_parent_item ( parent) )
2067
2068
. node
2068
2069
{
2070
+ let parent_node_id = self . tcx . hir ( ) . hir_to_node_id ( parent) ;
2069
2071
assoc_item_kind = trait_items
2070
2072
. iter ( )
2071
- . find ( |ti| ti. id . node_id == parent )
2073
+ . find ( |ti| ti. id . node_id == parent_node_id )
2072
2074
. map ( |ti| ti. kind ) ;
2073
2075
}
2074
2076
match * m {
@@ -2083,13 +2085,14 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
2083
2085
} ) => {
2084
2086
if let hir:: ItemKind :: Impl ( .., ref self_ty, ref impl_items) = self . tcx
2085
2087
. hir ( )
2086
- . expect_item ( self . tcx . hir ( ) . get_parent ( parent) )
2088
+ . expect_item_by_hir_id ( self . tcx . hir ( ) . get_parent_item ( parent) )
2087
2089
. node
2088
2090
{
2089
2091
impl_self = Some ( self_ty) ;
2092
+ let parent_node_id = self . tcx . hir ( ) . hir_to_node_id ( parent) ;
2090
2093
assoc_item_kind = impl_items
2091
2094
. iter ( )
2092
- . find ( |ii| ii. id . node_id == parent )
2095
+ . find ( |ii| ii. id . node_id == parent_node_id )
2093
2096
. map ( |ii| ii. kind ) ;
2094
2097
}
2095
2098
Some ( body)
@@ -2143,7 +2146,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
2143
2146
if let hir:: TyKind :: Rptr ( lifetime_ref, ref mt) = inputs[ 0 ] . node {
2144
2147
if let hir:: TyKind :: Path ( hir:: QPath :: Resolved ( None , ref path) ) = mt. ty . node {
2145
2148
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 ) {
2147
2150
let scope = Scope :: Elision {
2148
2151
elide : Elide :: Exact ( lifetime) ,
2149
2152
s : self . scope ,
@@ -2262,7 +2265,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
2262
2265
}
2263
2266
2264
2267
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 ) {
2266
2269
match lifetime {
2267
2270
Region :: LateBound ( debruijn, _, _) | Region :: LateBoundAnon ( debruijn, _)
2268
2271
if debruijn < self . outer_index =>
@@ -2653,7 +2656,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
2653
2656
}
2654
2657
2655
2658
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 {
2657
2660
span_bug ! (
2658
2661
lifetime_ref. span,
2659
2662
"lifetime reference not renumbered, \
@@ -2663,11 +2666,11 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
2663
2666
2664
2667
debug ! (
2665
2668
"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 ) ,
2667
2670
def,
2668
2671
self . tcx. sess. source_map( ) . span_to_string( lifetime_ref. span)
2669
2672
) ;
2670
- self . map . defs . insert ( lifetime_ref. id , def) ;
2673
+ self . map . defs . insert ( lifetime_ref. hir_id , def) ;
2671
2674
2672
2675
match def {
2673
2676
Region :: LateBoundAnon ( ..) | Region :: Static => {
@@ -2699,7 +2702,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
2699
2702
/// error (esp. around impl trait). In that case, we remove the
2700
2703
/// entry into `map.defs` so as not to confuse later code.
2701
2704
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 ) ;
2703
2706
assert_eq ! ( old_value, Some ( bad_def) ) ;
2704
2707
}
2705
2708
}
0 commit comments