diff options
| author | Niko Matsakis <niko@alum.mit.edu> | 2018-11-21 13:36:11 -0500 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2018-11-21 13:41:44 -0500 |
| commit | a0a47904d64031a7a24828d6ad368ea9da33082a (patch) | |
| tree | 63afcb87e838b9cb87c6bd75c1f71b4fd7e93926 /src | |
| parent | 40f80940035af4b44aa7846ed34abee71151d3ee (diff) | |
| download | rust-a0a47904d64031a7a24828d6ad368ea9da33082a.tar.gz rust-a0a47904d64031a7a24828d6ad368ea9da33082a.zip | |
renumber segment ids for visibilities whenever we clone them
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc/hir/lowering.rs | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index e4819d6fb1d..79d605c0035 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -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, @@ -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, } @@ -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); |
