@@ -39,22 +39,24 @@ use hir::intravisit::{self, Visitor, NestedVisitorMap};
3939#[ derive( Clone , Copy , PartialEq , Eq , Hash , RustcEncodable , RustcDecodable , Debug ) ]
4040pub enum Region {
4141 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 ) ,
4444 LateBoundAnon ( ty:: DebruijnIndex , /* anon index */ u32 ) ,
45- Free ( DefId , /* lifetime decl */ ast :: NodeId ) ,
45+ Free ( DefId , /* lifetime decl */ DefId ) ,
4646}
4747
4848impl 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 ) {
5050 let i = * index;
5151 * 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) )
5354 }
5455
55- fn late ( def : & hir:: LifetimeDef ) -> ( ast:: Name , Region ) {
56+ fn late ( hir_map : & Map , def : & hir:: LifetimeDef ) -> ( ast:: Name , Region ) {
5657 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) )
5860 }
5961
6062 fn late_anon ( index : & Cell < u32 > ) -> Region {
@@ -64,7 +66,7 @@ impl Region {
6466 Region :: LateBoundAnon ( depth, i)
6567 }
6668
67- fn id ( & self ) -> Option < ast :: NodeId > {
69+ fn id ( & self ) -> Option < DefId > {
6870 match * self {
6971 Region :: Static |
7072 Region :: LateBoundAnon ( ..) => None ,
@@ -337,7 +339,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
337339 0
338340 } ;
339341 let lifetimes = generics. lifetimes . iter ( ) . map ( |def| {
340- Region :: early ( & mut index, def)
342+ Region :: early ( self . hir_map , & mut index, def)
341343 } ) . collect ( ) ;
342344 let scope = Scope :: Binder {
343345 lifetimes,
@@ -368,7 +370,9 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
368370 match ty. node {
369371 hir:: TyBareFn ( ref c) => {
370372 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 ( ) ,
372376 s : self . scope
373377 } ;
374378 self . with ( scope, |old_scope, this| {
@@ -467,7 +471,9 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
467471 if !bound_lifetimes. is_empty ( ) {
468472 self . trait_ref_hack = true ;
469473 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 ( ) ,
471477 s : self . scope
472478 } ;
473479 let result = self . with ( scope, |old_scope, this| {
@@ -512,7 +518,9 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
512518 "nested quantification of lifetimes" ) ;
513519 }
514520 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 ( ) ,
516524 s : self . scope
517525 } ;
518526 self . with ( scope, |old_scope, this| {
@@ -647,10 +655,13 @@ fn extract_labels(ctxt: &mut LifetimeContext, body: &hir::Body) {
647655 Scope :: Binder { ref lifetimes, s } => {
648656 // FIXME (#24278): non-hygienic comparison
649657 if let Some ( def) = lifetimes. get ( & label) {
658+ let node_id = hir_map. as_local_node_id ( def. id ( ) . unwrap ( ) )
659+ . unwrap ( ) ;
660+
650661 signal_shadowing_problem (
651662 sess,
652663 label,
653- original_lifetime ( hir_map. span ( def . id ( ) . unwrap ( ) ) ) ,
664+ original_lifetime ( hir_map. span ( node_id ) ) ,
654665 shadower_label ( label_span) ) ;
655666 return ;
656667 }
@@ -749,7 +760,8 @@ fn object_lifetime_defaults_for_item(hir_map: &Map, generics: &hir::Generics)
749760 generics. lifetimes . iter ( ) . enumerate ( ) . find ( |& ( _, def) | {
750761 def. lifetime . name == name
751762 } ) . 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) )
753765 } )
754766 }
755767 }
@@ -835,9 +847,9 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
835847
836848 let lifetimes = generics. lifetimes . iter ( ) . map ( |def| {
837849 if self . map . late_bound . contains ( & def. lifetime . id ) {
838- Region :: late ( def)
850+ Region :: late ( self . hir_map , def)
839851 } else {
840- Region :: early ( & mut index, def)
852+ Region :: early ( self . hir_map , & mut index, def)
841853 }
842854 } ) . collect ( ) ;
843855
@@ -1483,10 +1495,14 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
14831495
14841496 Scope :: Binder { ref lifetimes, s } => {
14851497 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+
14861502 signal_shadowing_problem (
14871503 self . sess ,
14881504 lifetime. name ,
1489- original_lifetime ( self . hir_map . span ( def . id ( ) . unwrap ( ) ) ) ,
1505+ original_lifetime ( self . hir_map . span ( node_id ) ) ,
14901506 shadower_lifetime ( & lifetime) ) ;
14911507 return ;
14921508 }
0 commit comments