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