diff --git a/src/librustc/middle/resolve_lifetime.rs b/src/librustc/middle/resolve_lifetime.rs index a8e98e53db394..1e801d665fb99 100644 --- a/src/librustc/middle/resolve_lifetime.rs +++ b/src/librustc/middle/resolve_lifetime.rs @@ -38,22 +38,24 @@ use hir::intravisit::{self, Visitor, NestedVisitorMap}; #[derive(Clone, Copy, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, Debug)] pub enum Region { Static, - EarlyBound(/* index */ u32, /* lifetime decl */ ast::NodeId), - LateBound(ty::DebruijnIndex, /* lifetime decl */ ast::NodeId), + EarlyBound(/* index */ u32, /* lifetime decl */ DefId), + LateBound(ty::DebruijnIndex, /* lifetime decl */ DefId), LateBoundAnon(ty::DebruijnIndex, /* anon index */ u32), - Free(DefId, /* lifetime decl */ ast::NodeId), + Free(DefId, /* lifetime decl */ DefId), } impl Region { - fn early(index: &mut u32, def: &hir::LifetimeDef) -> (ast::Name, Region) { + fn early(hir_map: &Map, index: &mut u32, def: &hir::LifetimeDef) -> (ast::Name, Region) { let i = *index; *index += 1; - (def.lifetime.name, Region::EarlyBound(i, def.lifetime.id)) + let def_id = hir_map.local_def_id(def.lifetime.id); + (def.lifetime.name, Region::EarlyBound(i, def_id)) } - fn late(def: &hir::LifetimeDef) -> (ast::Name, Region) { + fn late(hir_map: &Map, def: &hir::LifetimeDef) -> (ast::Name, Region) { let depth = ty::DebruijnIndex::new(1); - (def.lifetime.name, Region::LateBound(depth, def.lifetime.id)) + let def_id = hir_map.local_def_id(def.lifetime.id); + (def.lifetime.name, Region::LateBound(depth, def_id)) } fn late_anon(index: &Cell) -> Region { @@ -63,7 +65,7 @@ impl Region { Region::LateBoundAnon(depth, i) } - fn id(&self) -> Option { + fn id(&self) -> Option { match *self { Region::Static | Region::LateBoundAnon(..) => None, @@ -333,7 +335,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> { 0 }; let lifetimes = generics.lifetimes.iter().map(|def| { - Region::early(&mut index, def) + Region::early(self.hir_map, &mut index, def) }).collect(); let scope = Scope::Binder { lifetimes, @@ -364,7 +366,9 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> { match ty.node { hir::TyBareFn(ref c) => { let scope = Scope::Binder { - lifetimes: c.lifetimes.iter().map(Region::late).collect(), + lifetimes: c.lifetimes.iter().map(|def| { + Region::late(self.hir_map, def) + }).collect(), s: self.scope }; self.with(scope, |old_scope, this| { @@ -463,7 +467,9 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> { if !bound_lifetimes.is_empty() { self.trait_ref_hack = true; let scope = Scope::Binder { - lifetimes: bound_lifetimes.iter().map(Region::late).collect(), + lifetimes: bound_lifetimes.iter().map(|def| { + Region::late(self.hir_map, def) + }).collect(), s: self.scope }; let result = self.with(scope, |old_scope, this| { @@ -508,7 +514,9 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> { "nested quantification of lifetimes"); } let scope = Scope::Binder { - lifetimes: trait_ref.bound_lifetimes.iter().map(Region::late).collect(), + lifetimes: trait_ref.bound_lifetimes.iter().map(|def| { + Region::late(self.hir_map, def) + }).collect(), s: self.scope }; self.with(scope, |old_scope, this| { @@ -643,10 +651,13 @@ fn extract_labels(ctxt: &mut LifetimeContext, body: &hir::Body) { Scope::Binder { ref lifetimes, s } => { // FIXME (#24278): non-hygienic comparison if let Some(def) = lifetimes.get(&label) { + let node_id = hir_map.as_local_node_id(def.id().unwrap()) + .unwrap(); + signal_shadowing_problem( sess, label, - original_lifetime(hir_map.span(def.id().unwrap())), + original_lifetime(hir_map.span(node_id)), shadower_label(label_span)); return; } @@ -745,7 +756,8 @@ fn object_lifetime_defaults_for_item(hir_map: &Map, generics: &hir::Generics) generics.lifetimes.iter().enumerate().find(|&(_, def)| { def.lifetime.name == name }).map_or(Set1::Many, |(i, def)| { - Set1::One(Region::EarlyBound(i as u32, def.lifetime.id)) + let def_id = hir_map.local_def_id(def.lifetime.id); + Set1::One(Region::EarlyBound(i as u32, def_id)) }) } } @@ -830,9 +842,9 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { let lifetimes = generics.lifetimes.iter().map(|def| { if self.map.late_bound.contains(&def.lifetime.id) { - Region::late(def) + Region::late(self.hir_map, def) } else { - Region::early(&mut index, def) + Region::early(self.hir_map, &mut index, def) } }).collect(); @@ -1478,10 +1490,14 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { Scope::Binder { ref lifetimes, s } => { if let Some(&def) = lifetimes.get(&lifetime.name) { + let node_id = self.hir_map + .as_local_node_id(def.id().unwrap()) + .unwrap(); + signal_shadowing_problem( self.sess, lifetime.name, - original_lifetime(self.hir_map.span(def.id().unwrap())), + original_lifetime(self.hir_map.span(node_id)), shadower_lifetime(&lifetime)); return; } diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index ee1e6bd950fa1..cda0e4f7ebd0f 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -96,15 +96,19 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o { -> ty::Region<'tcx> { let tcx = self.tcx(); + let lifetime_name = |def_id| { + tcx.hir.name(tcx.hir.as_local_node_id(def_id).unwrap()) + }; + let r = match tcx.named_region_map.defs.get(&lifetime.id) { Some(&rl::Region::Static) => { tcx.types.re_static } Some(&rl::Region::LateBound(debruijn, id)) => { - let name = tcx.hir.name(id); + let name = lifetime_name(id); tcx.mk_region(ty::ReLateBound(debruijn, - ty::BrNamed(tcx.hir.local_def_id(id), name))) + ty::BrNamed(id, name))) } Some(&rl::Region::LateBoundAnon(debruijn, index)) => { @@ -112,19 +116,19 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o { } Some(&rl::Region::EarlyBound(index, id)) => { - let name = tcx.hir.name(id); + let name = lifetime_name(id); tcx.mk_region(ty::ReEarlyBound(ty::EarlyBoundRegion { - def_id: tcx.hir.local_def_id(id), + def_id: id, index, name, })) } Some(&rl::Region::Free(scope, id)) => { - let name = tcx.hir.name(id); + let name = lifetime_name(id); tcx.mk_region(ty::ReFree(ty::FreeRegion { scope, - bound_region: ty::BrNamed(tcx.hir.local_def_id(id), name) + bound_region: ty::BrNamed(id, name) })) // (*) -- not late-bound, won't change diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index aab44ddce0e6a..4f5ccd57aec56 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1807,7 +1807,8 @@ impl Clean for hir::Ty { for (i, lt_param) in generics.lifetimes.iter().enumerate() { if let Some(lt) = provided_params.lifetimes.get(i).cloned() { if !lt.is_elided() { - lt_substs.insert(lt_param.lifetime.id, lt.clean(cx)); + let lt_def_id = cx.tcx.hir.local_def_id(lt_param.lifetime.id); + lt_substs.insert(lt_def_id, lt.clean(cx)); } } } diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index 58de0e1caecdb..3033e904f2583 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -25,7 +25,7 @@ use rustc_trans::back::link; use rustc_resolve as resolve; use rustc_metadata::cstore::CStore; -use syntax::{ast, codemap}; +use syntax::codemap; use syntax::feature_gate::UnstableFeatures; use syntax::fold::Folder; use errors; @@ -66,7 +66,7 @@ pub struct DocContext<'a, 'tcx: 'a> { /// Table type parameter definition -> substituted type pub ty_substs: RefCell>, /// Table node id of lifetime parameter definition -> substituted lifetime - pub lt_substs: RefCell>, + pub lt_substs: RefCell>, } impl<'a, 'tcx> DocContext<'a, 'tcx> { @@ -78,7 +78,7 @@ impl<'a, 'tcx> DocContext<'a, 'tcx> { /// the substitutions for a type alias' RHS. pub fn enter_alias(&self, ty_substs: FxHashMap, - lt_substs: FxHashMap, + lt_substs: FxHashMap, f: F) -> R where F: FnOnce() -> R { let (old_tys, old_lts) =