@@ -3029,12 +3029,7 @@ impl<'a> LoweringContext<'a> {
3029
3029
hir:: VisibilityKind :: Inherited => hir:: VisibilityKind :: Inherited ,
3030
3030
hir:: VisibilityKind :: Restricted { ref path, id : _, hir_id : _ } => {
3031
3031
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) ;
3038
3033
hir:: VisibilityKind :: Restricted {
3039
3034
path,
3040
3035
id : id. node_id ,
@@ -3119,8 +3114,9 @@ impl<'a> LoweringContext<'a> {
3119
3114
hir:: VisibilityKind :: Inherited => hir:: VisibilityKind :: Inherited ,
3120
3115
hir:: VisibilityKind :: Restricted { ref path, id : _, hir_id : _ } => {
3121
3116
let id = this. next_id ( ) ;
3117
+ let path = this. renumber_segment_ids ( path) ;
3122
3118
hir:: VisibilityKind :: Restricted {
3123
- path : path. clone ( ) ,
3119
+ path : path,
3124
3120
id : id. node_id ,
3125
3121
hir_id : id. hir_id ,
3126
3122
}
@@ -3154,6 +3150,20 @@ impl<'a> LoweringContext<'a> {
3154
3150
}
3155
3151
}
3156
3152
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
+
3157
3167
fn lower_trait_item ( & mut self , i : & TraitItem ) -> hir:: TraitItem {
3158
3168
let LoweredNodeId { node_id, hir_id } = self . lower_node_id ( i. id ) ;
3159
3169
let trait_item_def_id = self . resolver . definitions ( ) . local_def_id ( node_id) ;
0 commit comments