@@ -39,22 +39,24 @@ use hir::intravisit::{self, Visitor, NestedVisitorMap};
39
39
#[ derive( Clone , Copy , PartialEq , Eq , Hash , RustcEncodable , RustcDecodable , Debug ) ]
40
40
pub enum Region {
41
41
Static ,
42
- EarlyBound ( /* index */ u32 , /* lifetime decl */ ast :: NodeId ) ,
43
- LateBound ( ty:: DebruijnIndex , /* lifetime decl */ ast :: NodeId ) ,
42
+ EarlyBound ( /* index */ u32 , /* lifetime decl */ DefId ) ,
43
+ LateBound ( ty:: DebruijnIndex , /* lifetime decl */ DefId ) ,
44
44
LateBoundAnon ( ty:: DebruijnIndex , /* anon index */ u32 ) ,
45
- Free ( DefId , /* lifetime decl */ ast :: NodeId ) ,
45
+ Free ( DefId , /* lifetime decl */ DefId ) ,
46
46
}
47
47
48
48
impl Region {
49
- fn early ( index : & mut u32 , def : & hir:: LifetimeDef ) -> ( ast:: Name , Region ) {
49
+ fn early ( hir_map : & Map , index : & mut u32 , def : & hir:: LifetimeDef ) -> ( ast:: Name , Region ) {
50
50
let i = * index;
51
51
* index += 1 ;
52
- ( def. lifetime . name , Region :: EarlyBound ( i, def. lifetime . id ) )
52
+ let def_id = hir_map. local_def_id ( def. lifetime . id ) ;
53
+ ( def. lifetime . name , Region :: EarlyBound ( i, def_id) )
53
54
}
54
55
55
- fn late ( def : & hir:: LifetimeDef ) -> ( ast:: Name , Region ) {
56
+ fn late ( hir_map : & Map , def : & hir:: LifetimeDef ) -> ( ast:: Name , Region ) {
56
57
let depth = ty:: DebruijnIndex :: new ( 1 ) ;
57
- ( def. lifetime . name , Region :: LateBound ( depth, def. lifetime . id ) )
58
+ let def_id = hir_map. local_def_id ( def. lifetime . id ) ;
59
+ ( def. lifetime . name , Region :: LateBound ( depth, def_id) )
58
60
}
59
61
60
62
fn late_anon ( index : & Cell < u32 > ) -> Region {
@@ -64,7 +66,7 @@ impl Region {
64
66
Region :: LateBoundAnon ( depth, i)
65
67
}
66
68
67
- fn id ( & self ) -> Option < ast :: NodeId > {
69
+ fn id ( & self ) -> Option < DefId > {
68
70
match * self {
69
71
Region :: Static |
70
72
Region :: LateBoundAnon ( ..) => None ,
@@ -337,7 +339,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
337
339
0
338
340
} ;
339
341
let lifetimes = generics. lifetimes . iter ( ) . map ( |def| {
340
- Region :: early ( & mut index, def)
342
+ Region :: early ( self . hir_map , & mut index, def)
341
343
} ) . collect ( ) ;
342
344
let scope = Scope :: Binder {
343
345
lifetimes,
@@ -368,7 +370,9 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
368
370
match ty. node {
369
371
hir:: TyBareFn ( ref c) => {
370
372
let scope = Scope :: Binder {
371
- lifetimes : c. lifetimes . iter ( ) . map ( Region :: late) . collect ( ) ,
373
+ lifetimes : c. lifetimes . iter ( ) . map ( |def| {
374
+ Region :: late ( self . hir_map , def)
375
+ } ) . collect ( ) ,
372
376
s : self . scope
373
377
} ;
374
378
self . with ( scope, |old_scope, this| {
@@ -467,7 +471,9 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
467
471
if !bound_lifetimes. is_empty ( ) {
468
472
self . trait_ref_hack = true ;
469
473
let scope = Scope :: Binder {
470
- lifetimes : bound_lifetimes. iter ( ) . map ( Region :: late) . collect ( ) ,
474
+ lifetimes : bound_lifetimes. iter ( ) . map ( |def| {
475
+ Region :: late ( self . hir_map , def)
476
+ } ) . collect ( ) ,
471
477
s : self . scope
472
478
} ;
473
479
let result = self . with ( scope, |old_scope, this| {
@@ -512,7 +518,9 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
512
518
"nested quantification of lifetimes" ) ;
513
519
}
514
520
let scope = Scope :: Binder {
515
- lifetimes : trait_ref. bound_lifetimes . iter ( ) . map ( Region :: late) . collect ( ) ,
521
+ lifetimes : trait_ref. bound_lifetimes . iter ( ) . map ( |def| {
522
+ Region :: late ( self . hir_map , def)
523
+ } ) . collect ( ) ,
516
524
s : self . scope
517
525
} ;
518
526
self . with ( scope, |old_scope, this| {
@@ -647,10 +655,13 @@ fn extract_labels(ctxt: &mut LifetimeContext, body: &hir::Body) {
647
655
Scope :: Binder { ref lifetimes, s } => {
648
656
// FIXME (#24278): non-hygienic comparison
649
657
if let Some ( def) = lifetimes. get ( & label) {
658
+ let node_id = hir_map. as_local_node_id ( def. id ( ) . unwrap ( ) )
659
+ . unwrap ( ) ;
660
+
650
661
signal_shadowing_problem (
651
662
sess,
652
663
label,
653
- original_lifetime ( hir_map. span ( def . id ( ) . unwrap ( ) ) ) ,
664
+ original_lifetime ( hir_map. span ( node_id ) ) ,
654
665
shadower_label ( label_span) ) ;
655
666
return ;
656
667
}
@@ -749,7 +760,8 @@ fn object_lifetime_defaults_for_item(hir_map: &Map, generics: &hir::Generics)
749
760
generics. lifetimes . iter ( ) . enumerate ( ) . find ( |& ( _, def) | {
750
761
def. lifetime . name == name
751
762
} ) . map_or ( Set1 :: Many , |( i, def) | {
752
- Set1 :: One ( Region :: EarlyBound ( i as u32 , def. lifetime . id ) )
763
+ let def_id = hir_map. local_def_id ( def. lifetime . id ) ;
764
+ Set1 :: One ( Region :: EarlyBound ( i as u32 , def_id) )
753
765
} )
754
766
}
755
767
}
@@ -835,9 +847,9 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
835
847
836
848
let lifetimes = generics. lifetimes . iter ( ) . map ( |def| {
837
849
if self . map . late_bound . contains ( & def. lifetime . id ) {
838
- Region :: late ( def)
850
+ Region :: late ( self . hir_map , def)
839
851
} else {
840
- Region :: early ( & mut index, def)
852
+ Region :: early ( self . hir_map , & mut index, def)
841
853
}
842
854
} ) . collect ( ) ;
843
855
@@ -1483,10 +1495,14 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
1483
1495
1484
1496
Scope :: Binder { ref lifetimes, s } => {
1485
1497
if let Some ( & def) = lifetimes. get ( & lifetime. name ) {
1498
+ let node_id = self . hir_map
1499
+ . as_local_node_id ( def. id ( ) . unwrap ( ) )
1500
+ . unwrap ( ) ;
1501
+
1486
1502
signal_shadowing_problem (
1487
1503
self . sess ,
1488
1504
lifetime. name ,
1489
- original_lifetime ( self . hir_map . span ( def . id ( ) . unwrap ( ) ) ) ,
1505
+ original_lifetime ( self . hir_map . span ( node_id ) ) ,
1490
1506
shadower_lifetime ( & lifetime) ) ;
1491
1507
return ;
1492
1508
}
0 commit comments