@@ -38,22 +38,24 @@ use hir::intravisit::{self, Visitor, NestedVisitorMap};
3838#[ derive( Clone , Copy , PartialEq , Eq , Hash , RustcEncodable , RustcDecodable , Debug ) ]
3939pub enum Region {
4040 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 ) ,
4343 LateBoundAnon ( ty:: DebruijnIndex , /* anon index */ u32 ) ,
44- Free ( DefId , /* lifetime decl */ ast :: NodeId ) ,
44+ Free ( DefId , /* lifetime decl */ DefId ) ,
4545}
4646
4747impl 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 ) {
4949 let i = * index;
5050 * 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) )
5253 }
5354
54- fn late ( def : & hir:: LifetimeDef ) -> ( ast:: Name , Region ) {
55+ fn late ( hir_map : & Map , def : & hir:: LifetimeDef ) -> ( ast:: Name , Region ) {
5556 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) )
5759 }
5860
5961 fn late_anon ( index : & Cell < u32 > ) -> Region {
@@ -63,7 +65,7 @@ impl Region {
6365 Region :: LateBoundAnon ( depth, i)
6466 }
6567
66- fn id ( & self ) -> Option < ast :: NodeId > {
68+ fn id ( & self ) -> Option < DefId > {
6769 match * self {
6870 Region :: Static |
6971 Region :: LateBoundAnon ( ..) => None ,
@@ -333,7 +335,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
333335 0
334336 } ;
335337 let lifetimes = generics. lifetimes . iter ( ) . map ( |def| {
336- Region :: early ( & mut index, def)
338+ Region :: early ( self . hir_map , & mut index, def)
337339 } ) . collect ( ) ;
338340 let scope = Scope :: Binder {
339341 lifetimes,
@@ -364,7 +366,9 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
364366 match ty. node {
365367 hir:: TyBareFn ( ref c) => {
366368 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 ( ) ,
368372 s : self . scope
369373 } ;
370374 self . with ( scope, |old_scope, this| {
@@ -463,7 +467,9 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
463467 if !bound_lifetimes. is_empty ( ) {
464468 self . trait_ref_hack = true ;
465469 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 ( ) ,
467473 s : self . scope
468474 } ;
469475 let result = self . with ( scope, |old_scope, this| {
@@ -508,7 +514,9 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
508514 "nested quantification of lifetimes" ) ;
509515 }
510516 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 ( ) ,
512520 s : self . scope
513521 } ;
514522 self . with ( scope, |old_scope, this| {
@@ -643,10 +651,13 @@ fn extract_labels(ctxt: &mut LifetimeContext, body: &hir::Body) {
643651 Scope :: Binder { ref lifetimes, s } => {
644652 // FIXME (#24278): non-hygienic comparison
645653 if let Some ( def) = lifetimes. get ( & label) {
654+ let node_id = hir_map. as_local_node_id ( def. id ( ) . unwrap ( ) )
655+ . unwrap ( ) ;
656+
646657 signal_shadowing_problem (
647658 sess,
648659 label,
649- original_lifetime ( hir_map. span ( def . id ( ) . unwrap ( ) ) ) ,
660+ original_lifetime ( hir_map. span ( node_id ) ) ,
650661 shadower_label ( label_span) ) ;
651662 return ;
652663 }
@@ -745,7 +756,8 @@ fn object_lifetime_defaults_for_item(hir_map: &Map, generics: &hir::Generics)
745756 generics. lifetimes . iter ( ) . enumerate ( ) . find ( |& ( _, def) | {
746757 def. lifetime . name == name
747758 } ) . 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) )
749761 } )
750762 }
751763 }
@@ -830,9 +842,9 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
830842
831843 let lifetimes = generics. lifetimes . iter ( ) . map ( |def| {
832844 if self . map . late_bound . contains ( & def. lifetime . id ) {
833- Region :: late ( def)
845+ Region :: late ( self . hir_map , def)
834846 } else {
835- Region :: early ( & mut index, def)
847+ Region :: early ( self . hir_map , & mut index, def)
836848 }
837849 } ) . collect ( ) ;
838850
@@ -1481,10 +1493,14 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
14811493
14821494 Scope :: Binder { ref lifetimes, s } => {
14831495 if let Some ( & def) = lifetimes. get ( & lifetime. name ) {
1496+ let node_id = self . hir_map
1497+ . as_local_node_id ( def. id ( ) . unwrap ( ) )
1498+ . unwrap ( ) ;
1499+
14841500 signal_shadowing_problem (
14851501 self . sess ,
14861502 lifetime. name ,
1487- original_lifetime ( self . hir_map . span ( def . id ( ) . unwrap ( ) ) ) ,
1503+ original_lifetime ( self . hir_map . span ( node_id ) ) ,
14881504 shadower_lifetime ( & lifetime) ) ;
14891505 return ;
14901506 }
0 commit comments