@@ -3027,12 +3027,7 @@ impl<'a> LoweringContext<'a> {
3027
3027
hir:: VisibilityKind :: Inherited => hir:: VisibilityKind :: Inherited ,
3028
3028
hir:: VisibilityKind :: Restricted { ref path, id : _, hir_id : _ } => {
3029
3029
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) ;
3036
3031
hir:: VisibilityKind :: Restricted {
3037
3032
path,
3038
3033
id : id. node_id ,
@@ -3117,8 +3112,9 @@ impl<'a> LoweringContext<'a> {
3117
3112
hir:: VisibilityKind :: Inherited => hir:: VisibilityKind :: Inherited ,
3118
3113
hir:: VisibilityKind :: Restricted { ref path, id : _, hir_id : _ } => {
3119
3114
let id = this. next_id ( ) ;
3115
+ let path = this. renumber_segment_ids ( path) ;
3120
3116
hir:: VisibilityKind :: Restricted {
3121
- path : path. clone ( ) ,
3117
+ path : path,
3122
3118
id : id. node_id ,
3123
3119
hir_id : id. hir_id ,
3124
3120
}
@@ -3152,6 +3148,20 @@ impl<'a> LoweringContext<'a> {
3152
3148
}
3153
3149
}
3154
3150
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
+
3155
3165
fn lower_trait_item ( & mut self , i : & TraitItem ) -> hir:: TraitItem {
3156
3166
let LoweredNodeId { node_id, hir_id } = self . lower_node_id ( i. id ) ;
3157
3167
let trait_item_def_id = self . resolver . definitions ( ) . local_def_id ( node_id) ;
0 commit comments