@@ -3027,12 +3027,7 @@ impl<'a> LoweringContext<'a> {
30273027 hir:: VisibilityKind :: Inherited => hir:: VisibilityKind :: Inherited ,
30283028 hir:: VisibilityKind :: Restricted { ref path, id : _, hir_id : _ } => {
30293029 let id = this. next_id ( ) ;
3030- let mut path = path. clone ( ) ;
3031- for seg in path. segments . iter_mut ( ) {
3032- if seg. id . is_some ( ) {
3033- seg. id = Some ( this. next_id ( ) . node_id ) ;
3034- }
3035- }
3030+ let path = this. renumber_segment_ids ( path) ;
30363031 hir:: VisibilityKind :: Restricted {
30373032 path,
30383033 id : id. node_id ,
@@ -3117,8 +3112,9 @@ impl<'a> LoweringContext<'a> {
31173112 hir:: VisibilityKind :: Inherited => hir:: VisibilityKind :: Inherited ,
31183113 hir:: VisibilityKind :: Restricted { ref path, id : _, hir_id : _ } => {
31193114 let id = this. next_id ( ) ;
3115+ let path = this. renumber_segment_ids ( path) ;
31203116 hir:: VisibilityKind :: Restricted {
3121- path : path. clone ( ) ,
3117+ path : path,
31223118 id : id. node_id ,
31233119 hir_id : id. hir_id ,
31243120 }
@@ -3152,6 +3148,20 @@ impl<'a> LoweringContext<'a> {
31523148 }
31533149 }
31543150
3151+ /// Paths like the visibility path in `pub(super) use foo::{bar, baz}` are repeated
3152+ /// many times in the HIR tree; for each occurrence, we need to assign distinct
3153+ /// node-ids. (See e.g. #56128.)
3154+ fn renumber_segment_ids ( & mut self , path : & P < hir:: Path > ) -> P < hir:: Path > {
3155+ debug ! ( "renumber_segment_ids(path = {:?})" , path) ;
3156+ let mut path = path. clone ( ) ;
3157+ for seg in path. segments . iter_mut ( ) {
3158+ if seg. id . is_some ( ) {
3159+ seg. id = Some ( self . next_id ( ) . node_id ) ;
3160+ }
3161+ }
3162+ path
3163+ }
3164+
31553165 fn lower_trait_item ( & mut self , i : & TraitItem ) -> hir:: TraitItem {
31563166 let LoweredNodeId { node_id, hir_id } = self . lower_node_id ( i. id ) ;
31573167 let trait_item_def_id = self . resolver . definitions ( ) . local_def_id ( node_id) ;
0 commit comments