Skip to content

Commit a0a4790

Browse files
committed
renumber segment ids for visibilities whenever we clone them
1 parent 40f8094 commit a0a4790

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

src/librustc/hir/lowering.rs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3029,12 +3029,7 @@ impl<'a> LoweringContext<'a> {
30293029
hir::VisibilityKind::Inherited => hir::VisibilityKind::Inherited,
30303030
hir::VisibilityKind::Restricted { ref path, id: _, hir_id: _ } => {
30313031
let id = this.next_id();
3032-
let mut path = path.clone();
3033-
for seg in path.segments.iter_mut() {
3034-
if seg.id.is_some() {
3035-
seg.id = Some(this.next_id().node_id);
3036-
}
3037-
}
3032+
let path = this.renumber_segment_ids(path);
30383033
hir::VisibilityKind::Restricted {
30393034
path,
30403035
id: id.node_id,
@@ -3119,8 +3114,9 @@ impl<'a> LoweringContext<'a> {
31193114
hir::VisibilityKind::Inherited => hir::VisibilityKind::Inherited,
31203115
hir::VisibilityKind::Restricted { ref path, id: _, hir_id: _ } => {
31213116
let id = this.next_id();
3117+
let path = this.renumber_segment_ids(path);
31223118
hir::VisibilityKind::Restricted {
3123-
path: path.clone(),
3119+
path: path,
31243120
id: id.node_id,
31253121
hir_id: id.hir_id,
31263122
}
@@ -3154,6 +3150,20 @@ impl<'a> LoweringContext<'a> {
31543150
}
31553151
}
31563152

3153+
/// Paths like the visibility path in `pub(super) use foo::{bar, baz}` are repeated
3154+
/// many times in the HIR tree; for each occurrence, we need to assign distinct
3155+
/// node-ids. (See e.g. #56128.)
3156+
fn renumber_segment_ids(&mut self, path: &P<hir::Path>) -> P<hir::Path> {
3157+
debug!("renumber_segment_ids(path = {:?})", path);
3158+
let mut path = path.clone();
3159+
for seg in path.segments.iter_mut() {
3160+
if seg.id.is_some() {
3161+
seg.id = Some(self.next_id().node_id);
3162+
}
3163+
}
3164+
path
3165+
}
3166+
31573167
fn lower_trait_item(&mut self, i: &TraitItem) -> hir::TraitItem {
31583168
let LoweredNodeId { node_id, hir_id } = self.lower_node_id(i.id);
31593169
let trait_item_def_id = self.resolver.definitions().local_def_id(node_id);

0 commit comments

Comments
 (0)