@@ -38,22 +38,24 @@ use hir::intravisit::{self, Visitor, NestedVisitorMap};
38
38
#[ derive( Clone , Copy , PartialEq , Eq , Hash , RustcEncodable , RustcDecodable , Debug ) ]
39
39
pub enum Region {
40
40
Static ,
41
- EarlyBound ( /* index */ u32 , /* lifetime decl */ ast :: NodeId ) ,
42
- LateBound ( ty:: DebruijnIndex , /* lifetime decl */ ast :: NodeId ) ,
41
+ EarlyBound ( /* index */ u32 , /* lifetime decl */ DefId ) ,
42
+ LateBound ( ty:: DebruijnIndex , /* lifetime decl */ DefId ) ,
43
43
LateBoundAnon ( ty:: DebruijnIndex , /* anon index */ u32 ) ,
44
- Free ( DefId , /* lifetime decl */ ast :: NodeId ) ,
44
+ Free ( DefId , /* lifetime decl */ DefId ) ,
45
45
}
46
46
47
47
impl Region {
48
- fn early ( index : & mut u32 , def : & hir:: LifetimeDef ) -> ( ast:: Name , Region ) {
48
+ fn early ( hir_map : & Map , index : & mut u32 , def : & hir:: LifetimeDef ) -> ( ast:: Name , Region ) {
49
49
let i = * index;
50
50
* index += 1 ;
51
- ( def. lifetime . name , Region :: EarlyBound ( i, def. lifetime . id ) )
51
+ let def_id = hir_map. local_def_id ( def. lifetime . id ) ;
52
+ ( def. lifetime . name , Region :: EarlyBound ( i, def_id) )
52
53
}
53
54
54
- fn late ( def : & hir:: LifetimeDef ) -> ( ast:: Name , Region ) {
55
+ fn late ( hir_map : & Map , def : & hir:: LifetimeDef ) -> ( ast:: Name , Region ) {
55
56
let depth = ty:: DebruijnIndex :: new ( 1 ) ;
56
- ( def. lifetime . name , Region :: LateBound ( depth, def. lifetime . id ) )
57
+ let def_id = hir_map. local_def_id ( def. lifetime . id ) ;
58
+ ( def. lifetime . name , Region :: LateBound ( depth, def_id) )
57
59
}
58
60
59
61
fn late_anon ( index : & Cell < u32 > ) -> Region {
@@ -63,7 +65,7 @@ impl Region {
63
65
Region :: LateBoundAnon ( depth, i)
64
66
}
65
67
66
- fn id ( & self ) -> Option < ast :: NodeId > {
68
+ fn id ( & self ) -> Option < DefId > {
67
69
match * self {
68
70
Region :: Static |
69
71
Region :: LateBoundAnon ( ..) => None ,
@@ -333,7 +335,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
333
335
0
334
336
} ;
335
337
let lifetimes = generics. lifetimes . iter ( ) . map ( |def| {
336
- Region :: early ( & mut index, def)
338
+ Region :: early ( self . hir_map , & mut index, def)
337
339
} ) . collect ( ) ;
338
340
let scope = Scope :: Binder {
339
341
lifetimes,
@@ -364,7 +366,9 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
364
366
match ty. node {
365
367
hir:: TyBareFn ( ref c) => {
366
368
let scope = Scope :: Binder {
367
- lifetimes : c. lifetimes . iter ( ) . map ( Region :: late) . collect ( ) ,
369
+ lifetimes : c. lifetimes . iter ( ) . map ( |def| {
370
+ Region :: late ( self . hir_map , def)
371
+ } ) . collect ( ) ,
368
372
s : self . scope
369
373
} ;
370
374
self . with ( scope, |old_scope, this| {
@@ -463,7 +467,9 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
463
467
if !bound_lifetimes. is_empty ( ) {
464
468
self . trait_ref_hack = true ;
465
469
let scope = Scope :: Binder {
466
- lifetimes : bound_lifetimes. iter ( ) . map ( Region :: late) . collect ( ) ,
470
+ lifetimes : bound_lifetimes. iter ( ) . map ( |def| {
471
+ Region :: late ( self . hir_map , def)
472
+ } ) . collect ( ) ,
467
473
s : self . scope
468
474
} ;
469
475
let result = self . with ( scope, |old_scope, this| {
@@ -508,7 +514,9 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
508
514
"nested quantification of lifetimes" ) ;
509
515
}
510
516
let scope = Scope :: Binder {
511
- lifetimes : trait_ref. bound_lifetimes . iter ( ) . map ( Region :: late) . collect ( ) ,
517
+ lifetimes : trait_ref. bound_lifetimes . iter ( ) . map ( |def| {
518
+ Region :: late ( self . hir_map , def)
519
+ } ) . collect ( ) ,
512
520
s : self . scope
513
521
} ;
514
522
self . with ( scope, |old_scope, this| {
@@ -643,10 +651,13 @@ fn extract_labels(ctxt: &mut LifetimeContext, body: &hir::Body) {
643
651
Scope :: Binder { ref lifetimes, s } => {
644
652
// FIXME (#24278): non-hygienic comparison
645
653
if let Some ( def) = lifetimes. get ( & label) {
654
+ let node_id = hir_map. as_local_node_id ( def. id ( ) . unwrap ( ) )
655
+ . unwrap ( ) ;
656
+
646
657
signal_shadowing_problem (
647
658
sess,
648
659
label,
649
- original_lifetime ( hir_map. span ( def . id ( ) . unwrap ( ) ) ) ,
660
+ original_lifetime ( hir_map. span ( node_id ) ) ,
650
661
shadower_label ( label_span) ) ;
651
662
return ;
652
663
}
@@ -745,7 +756,8 @@ fn object_lifetime_defaults_for_item(hir_map: &Map, generics: &hir::Generics)
745
756
generics. lifetimes . iter ( ) . enumerate ( ) . find ( |& ( _, def) | {
746
757
def. lifetime . name == name
747
758
} ) . map_or ( Set1 :: Many , |( i, def) | {
748
- Set1 :: One ( Region :: EarlyBound ( i as u32 , def. lifetime . id ) )
759
+ let def_id = hir_map. local_def_id ( def. lifetime . id ) ;
760
+ Set1 :: One ( Region :: EarlyBound ( i as u32 , def_id) )
749
761
} )
750
762
}
751
763
}
@@ -830,9 +842,9 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
830
842
831
843
let lifetimes = generics. lifetimes . iter ( ) . map ( |def| {
832
844
if self . map . late_bound . contains ( & def. lifetime . id ) {
833
- Region :: late ( def)
845
+ Region :: late ( self . hir_map , def)
834
846
} else {
835
- Region :: early ( & mut index, def)
847
+ Region :: early ( self . hir_map , & mut index, def)
836
848
}
837
849
} ) . collect ( ) ;
838
850
@@ -1478,10 +1490,14 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
1478
1490
1479
1491
Scope :: Binder { ref lifetimes, s } => {
1480
1492
if let Some ( & def) = lifetimes. get ( & lifetime. name ) {
1493
+ let node_id = self . hir_map
1494
+ . as_local_node_id ( def. id ( ) . unwrap ( ) )
1495
+ . unwrap ( ) ;
1496
+
1481
1497
signal_shadowing_problem (
1482
1498
self . sess ,
1483
1499
lifetime. name ,
1484
- original_lifetime ( self . hir_map . span ( def . id ( ) . unwrap ( ) ) ) ,
1500
+ original_lifetime ( self . hir_map . span ( node_id ) ) ,
1485
1501
shadower_lifetime ( & lifetime) ) ;
1486
1502
return ;
1487
1503
}
0 commit comments