Skip to content

Commit

Permalink
renumber segment ids for visibilities whenever we clone them
Browse files Browse the repository at this point in the history
  • Loading branch information
nikomatsakis committed Nov 21, 2018
1 parent 40f8094 commit a0a4790
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/librustc/hir/lowering.rs
Expand Up @@ -3029,12 +3029,7 @@ impl<'a> LoweringContext<'a> {
hir::VisibilityKind::Inherited => hir::VisibilityKind::Inherited,
hir::VisibilityKind::Restricted { ref path, id: _, hir_id: _ } => {
let id = this.next_id();
let mut path = path.clone();
for seg in path.segments.iter_mut() {
if seg.id.is_some() {
seg.id = Some(this.next_id().node_id);
}
}
let path = this.renumber_segment_ids(path);
hir::VisibilityKind::Restricted {
path,
id: id.node_id,
Expand Down Expand Up @@ -3119,8 +3114,9 @@ impl<'a> LoweringContext<'a> {
hir::VisibilityKind::Inherited => hir::VisibilityKind::Inherited,
hir::VisibilityKind::Restricted { ref path, id: _, hir_id: _ } => {
let id = this.next_id();
let path = this.renumber_segment_ids(path);
hir::VisibilityKind::Restricted {
path: path.clone(),
path: path,
id: id.node_id,
hir_id: id.hir_id,
}
Expand Down Expand Up @@ -3154,6 +3150,20 @@ impl<'a> LoweringContext<'a> {
}
}

/// Paths like the visibility path in `pub(super) use foo::{bar, baz}` are repeated
/// many times in the HIR tree; for each occurrence, we need to assign distinct
/// node-ids. (See e.g. #56128.)
fn renumber_segment_ids(&mut self, path: &P<hir::Path>) -> P<hir::Path> {
debug!("renumber_segment_ids(path = {:?})", path);
let mut path = path.clone();
for seg in path.segments.iter_mut() {
if seg.id.is_some() {
seg.id = Some(self.next_id().node_id);
}
}
path
}

fn lower_trait_item(&mut self, i: &TraitItem) -> hir::TraitItem {
let LoweredNodeId { node_id, hir_id } = self.lower_node_id(i.id);
let trait_item_def_id = self.resolver.definitions().local_def_id(node_id);
Expand Down

0 comments on commit a0a4790

Please sign in to comment.