@@ -2752,7 +2752,7 @@ impl<'a> LoweringContext<'a> {
27522752 id : NodeId ,
27532753 name : & mut Name ,
27542754 attrs : & hir:: HirVec < Attribute > ,
2755- vis : & hir:: Visibility ,
2755+ vis : & mut hir:: Visibility ,
27562756 i : & ItemKind ,
27572757 ) -> hir:: ItemKind {
27582758 match * i {
@@ -2955,7 +2955,7 @@ impl<'a> LoweringContext<'a> {
29552955 tree : & UseTree ,
29562956 prefix : & Path ,
29572957 id : NodeId ,
2958- vis : & hir:: Visibility ,
2958+ vis : & mut hir:: Visibility ,
29592959 name : & mut Name ,
29602960 attrs : & hir:: HirVec < Attribute > ,
29612961 ) -> hir:: ItemKind {
@@ -3086,7 +3086,7 @@ impl<'a> LoweringContext<'a> {
30863086 hir_id : new_hir_id,
30873087 } = self . lower_node_id ( id) ;
30883088
3089- let vis = vis. clone ( ) ;
3089+ let mut vis = vis. clone ( ) ;
30903090 let mut name = name. clone ( ) ;
30913091 let mut prefix = prefix. clone ( ) ;
30923092
@@ -3104,7 +3104,7 @@ impl<'a> LoweringContext<'a> {
31043104 let item = this. lower_use_tree ( use_tree,
31053105 & prefix,
31063106 new_id,
3107- & vis,
3107+ & mut vis,
31083108 & mut name,
31093109 attrs) ;
31103110
@@ -3139,6 +3139,27 @@ impl<'a> LoweringContext<'a> {
31393139 } ) ;
31403140 }
31413141
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+
31423163 let def = self . expect_full_def_from_use ( id) . next ( ) . unwrap_or ( Def :: Err ) ;
31433164 let path = P ( self . lower_path_extra ( def, & prefix, ParamMode :: Explicit , None ) ) ;
31443165 hir:: ItemKind :: Use ( path, hir:: UseKind :: ListStem )
@@ -3384,7 +3405,7 @@ impl<'a> LoweringContext<'a> {
33843405
33853406 pub fn lower_item ( & mut self , i : & Item ) -> Option < hir:: Item > {
33863407 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 ) ;
33883409 let attrs = self . lower_attrs ( & i. attrs ) ;
33893410 if let ItemKind :: MacroDef ( ref def) = i. node {
33903411 if !def. legacy || attr:: contains_name ( & i. attrs , "macro_export" ) ||
@@ -3403,7 +3424,7 @@ impl<'a> LoweringContext<'a> {
34033424 return None ;
34043425 }
34053426
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 ) ;
34073428
34083429 let LoweredNodeId { node_id, hir_id } = self . lower_node_id ( i. id ) ;
34093430
0 commit comments