@@ -2752,7 +2752,7 @@ impl<'a> LoweringContext<'a> {
2752
2752
id : NodeId ,
2753
2753
name : & mut Name ,
2754
2754
attrs : & hir:: HirVec < Attribute > ,
2755
- vis : & hir:: Visibility ,
2755
+ vis : & mut hir:: Visibility ,
2756
2756
i : & ItemKind ,
2757
2757
) -> hir:: ItemKind {
2758
2758
match * i {
@@ -2955,7 +2955,7 @@ impl<'a> LoweringContext<'a> {
2955
2955
tree : & UseTree ,
2956
2956
prefix : & Path ,
2957
2957
id : NodeId ,
2958
- vis : & hir:: Visibility ,
2958
+ vis : & mut hir:: Visibility ,
2959
2959
name : & mut Name ,
2960
2960
attrs : & hir:: HirVec < Attribute > ,
2961
2961
) -> hir:: ItemKind {
@@ -3086,7 +3086,7 @@ impl<'a> LoweringContext<'a> {
3086
3086
hir_id : new_hir_id,
3087
3087
} = self . lower_node_id ( id) ;
3088
3088
3089
- let vis = vis. clone ( ) ;
3089
+ let mut vis = vis. clone ( ) ;
3090
3090
let mut name = name. clone ( ) ;
3091
3091
let mut prefix = prefix. clone ( ) ;
3092
3092
@@ -3104,7 +3104,7 @@ impl<'a> LoweringContext<'a> {
3104
3104
let item = this. lower_use_tree ( use_tree,
3105
3105
& prefix,
3106
3106
new_id,
3107
- & vis,
3107
+ & mut vis,
3108
3108
& mut name,
3109
3109
attrs) ;
3110
3110
@@ -3139,6 +3139,27 @@ impl<'a> LoweringContext<'a> {
3139
3139
} ) ;
3140
3140
}
3141
3141
3142
+ // Subtle and a bit hacky: we lower the privacy level
3143
+ // of the list stem to "private" most of the time, but
3144
+ // not for "restricted" paths. The key thing is that
3145
+ // we don't want it to stay as `pub` (with no caveats)
3146
+ // because that affects rustdoc and also the lints
3147
+ // about `pub` items. But we can't *always* make it
3148
+ // private -- particularly not for restricted paths --
3149
+ // because it contains node-ids that would then be
3150
+ // unused, failing the check that HirIds are "densely
3151
+ // assigned".
3152
+ match vis. node {
3153
+ hir:: VisibilityKind :: Public |
3154
+ hir:: VisibilityKind :: Crate ( _) |
3155
+ hir:: VisibilityKind :: Inherited => {
3156
+ * vis = respan ( prefix. span . shrink_to_lo ( ) , hir:: VisibilityKind :: Inherited ) ;
3157
+ }
3158
+ hir:: VisibilityKind :: Restricted { .. } => {
3159
+ // do nothing here, as described in the comment on the match
3160
+ }
3161
+ }
3162
+
3142
3163
let def = self . expect_full_def_from_use ( id) . next ( ) . unwrap_or ( Def :: Err ) ;
3143
3164
let path = P ( self . lower_path_extra ( def, & prefix, ParamMode :: Explicit , None ) ) ;
3144
3165
hir:: ItemKind :: Use ( path, hir:: UseKind :: ListStem )
@@ -3384,7 +3405,7 @@ impl<'a> LoweringContext<'a> {
3384
3405
3385
3406
pub fn lower_item ( & mut self , i : & Item ) -> Option < hir:: Item > {
3386
3407
let mut name = i. ident . name ;
3387
- let vis = self . lower_visibility ( & i. vis , None ) ;
3408
+ let mut vis = self . lower_visibility ( & i. vis , None ) ;
3388
3409
let attrs = self . lower_attrs ( & i. attrs ) ;
3389
3410
if let ItemKind :: MacroDef ( ref def) = i. node {
3390
3411
if !def. legacy || attr:: contains_name ( & i. attrs , "macro_export" ) ||
@@ -3403,7 +3424,7 @@ impl<'a> LoweringContext<'a> {
3403
3424
return None ;
3404
3425
}
3405
3426
3406
- let node = self . lower_item_kind ( i. id , & mut name, & attrs, & vis, & i. node ) ;
3427
+ let node = self . lower_item_kind ( i. id , & mut name, & attrs, & mut vis, & i. node ) ;
3407
3428
3408
3429
let LoweredNodeId { node_id, hir_id } = self . lower_node_id ( i. id ) ;
3409
3430
0 commit comments