Skip to content

Commit 19ba1b6

Browse files
nikomatsakispietroalbini
authored andcommitted
only reset non-restricted visibilities
1 parent 5fc113d commit 19ba1b6

File tree

2 files changed

+28
-15
lines changed

2 files changed

+28
-15
lines changed

src/librustc/hir/lowering.rs

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2750,7 +2750,7 @@ impl<'a> LoweringContext<'a> {
27502750
id: NodeId,
27512751
name: &mut Name,
27522752
attrs: &hir::HirVec<Attribute>,
2753-
vis: &hir::Visibility,
2753+
vis: &mut hir::Visibility,
27542754
i: &ItemKind,
27552755
) -> hir::ItemKind {
27562756
match *i {
@@ -2953,7 +2953,7 @@ impl<'a> LoweringContext<'a> {
29532953
tree: &UseTree,
29542954
prefix: &Path,
29552955
id: NodeId,
2956-
vis: &hir::Visibility,
2956+
vis: &mut hir::Visibility,
29572957
name: &mut Name,
29582958
attrs: &hir::HirVec<Attribute>,
29592959
) -> hir::ItemKind {
@@ -3084,7 +3084,7 @@ impl<'a> LoweringContext<'a> {
30843084
hir_id: new_hir_id,
30853085
} = self.lower_node_id(id);
30863086

3087-
let vis = vis.clone();
3087+
let mut vis = vis.clone();
30883088
let mut name = name.clone();
30893089
let mut prefix = prefix.clone();
30903090

@@ -3102,7 +3102,7 @@ impl<'a> LoweringContext<'a> {
31023102
let item = this.lower_use_tree(use_tree,
31033103
&prefix,
31043104
new_id,
3105-
&vis,
3105+
&mut vis,
31063106
&mut name,
31073107
attrs);
31083108

@@ -3137,6 +3137,27 @@ impl<'a> LoweringContext<'a> {
31373137
});
31383138
}
31393139

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+
31403161
let def = self.expect_full_def_from_use(id).next().unwrap_or(Def::Err);
31413162
let path = P(self.lower_path_extra(def, &prefix, ParamMode::Explicit, None));
31423163
hir::ItemKind::Use(path, hir::UseKind::ListStem)
@@ -3382,7 +3403,7 @@ impl<'a> LoweringContext<'a> {
33823403

33833404
pub fn lower_item(&mut self, i: &Item) -> Option<hir::Item> {
33843405
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);
33863407
let attrs = self.lower_attrs(&i.attrs);
33873408
if let ItemKind::MacroDef(ref def) = i.node {
33883409
if !def.legacy || attr::contains_name(&i.attrs, "macro_export") ||
@@ -3401,7 +3422,7 @@ impl<'a> LoweringContext<'a> {
34013422
return None;
34023423
}
34033424

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);
34053426

34063427
let LoweredNodeId { node_id, hir_id } = self.lower_node_id(i.id);
34073428

src/librustc_lint/builtin.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,15 +1136,7 @@ impl UnreachablePub {
11361136

11371137
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnreachablePub {
11381138
fn check_item(&mut self, cx: &LateContext, item: &hir::Item) {
1139-
match item.node {
1140-
hir::ItemKind::Use(_, hir::UseKind::ListStem) => {
1141-
// Hack: ignore these `use foo::{}` remnants which are just a figment
1142-
// our IR.
1143-
}
1144-
_ => {
1145-
self.perform_lint(cx, "item", item.id, &item.vis, item.span, true);
1146-
}
1147-
}
1139+
self.perform_lint(cx, "item", item.id, &item.vis, item.span, true);
11481140
}
11491141

11501142
fn check_foreign_item(&mut self, cx: &LateContext, foreign_item: &hir::ForeignItem) {

0 commit comments

Comments
 (0)