only reset non-restricted visibilities
This commit is contained in:
parent
ebf3c8d8e9
commit
b83150e6ac
2 changed files with 28 additions and 15 deletions
|
@ -2752,7 +2752,7 @@ impl<'a> LoweringContext<'a> {
|
||||||
id: NodeId,
|
id: NodeId,
|
||||||
name: &mut Name,
|
name: &mut Name,
|
||||||
attrs: &hir::HirVec<Attribute>,
|
attrs: &hir::HirVec<Attribute>,
|
||||||
vis: &hir::Visibility,
|
vis: &mut hir::Visibility,
|
||||||
i: &ItemKind,
|
i: &ItemKind,
|
||||||
) -> hir::ItemKind {
|
) -> hir::ItemKind {
|
||||||
match *i {
|
match *i {
|
||||||
|
@ -2955,7 +2955,7 @@ impl<'a> LoweringContext<'a> {
|
||||||
tree: &UseTree,
|
tree: &UseTree,
|
||||||
prefix: &Path,
|
prefix: &Path,
|
||||||
id: NodeId,
|
id: NodeId,
|
||||||
vis: &hir::Visibility,
|
vis: &mut hir::Visibility,
|
||||||
name: &mut Name,
|
name: &mut Name,
|
||||||
attrs: &hir::HirVec<Attribute>,
|
attrs: &hir::HirVec<Attribute>,
|
||||||
) -> hir::ItemKind {
|
) -> hir::ItemKind {
|
||||||
|
@ -3086,7 +3086,7 @@ impl<'a> LoweringContext<'a> {
|
||||||
hir_id: new_hir_id,
|
hir_id: new_hir_id,
|
||||||
} = self.lower_node_id(id);
|
} = self.lower_node_id(id);
|
||||||
|
|
||||||
let vis = vis.clone();
|
let mut vis = vis.clone();
|
||||||
let mut name = name.clone();
|
let mut name = name.clone();
|
||||||
let mut prefix = prefix.clone();
|
let mut prefix = prefix.clone();
|
||||||
|
|
||||||
|
@ -3104,7 +3104,7 @@ impl<'a> LoweringContext<'a> {
|
||||||
let item = this.lower_use_tree(use_tree,
|
let item = this.lower_use_tree(use_tree,
|
||||||
&prefix,
|
&prefix,
|
||||||
new_id,
|
new_id,
|
||||||
&vis,
|
&mut vis,
|
||||||
&mut name,
|
&mut name,
|
||||||
attrs);
|
attrs);
|
||||||
|
|
||||||
|
@ -3139,6 +3139,27 @@ impl<'a> LoweringContext<'a> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Subtle and a bit hacky: we lower the privacy level
|
||||||
|
// of the list stem to "private" most of the time, but
|
||||||
|
// not for "restricted" paths. The key thing is that
|
||||||
|
// we don't want it to stay as `pub` (with no caveats)
|
||||||
|
// because that affects rustdoc and also the lints
|
||||||
|
// about `pub` items. But we can't *always* make it
|
||||||
|
// private -- particularly not for restricted paths --
|
||||||
|
// because it contains node-ids that would then be
|
||||||
|
// unused, failing the check that HirIds are "densely
|
||||||
|
// assigned".
|
||||||
|
match vis.node {
|
||||||
|
hir::VisibilityKind::Public |
|
||||||
|
hir::VisibilityKind::Crate(_) |
|
||||||
|
hir::VisibilityKind::Inherited => {
|
||||||
|
*vis = respan(prefix.span.shrink_to_lo(), hir::VisibilityKind::Inherited);
|
||||||
|
}
|
||||||
|
hir::VisibilityKind::Restricted { .. } => {
|
||||||
|
// do nothing here, as described in the comment on the match
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let def = self.expect_full_def_from_use(id).next().unwrap_or(Def::Err);
|
let def = self.expect_full_def_from_use(id).next().unwrap_or(Def::Err);
|
||||||
let path = P(self.lower_path_extra(def, &prefix, ParamMode::Explicit, None));
|
let path = P(self.lower_path_extra(def, &prefix, ParamMode::Explicit, None));
|
||||||
hir::ItemKind::Use(path, hir::UseKind::ListStem)
|
hir::ItemKind::Use(path, hir::UseKind::ListStem)
|
||||||
|
@ -3384,7 +3405,7 @@ impl<'a> LoweringContext<'a> {
|
||||||
|
|
||||||
pub fn lower_item(&mut self, i: &Item) -> Option<hir::Item> {
|
pub fn lower_item(&mut self, i: &Item) -> Option<hir::Item> {
|
||||||
let mut name = i.ident.name;
|
let mut name = i.ident.name;
|
||||||
let vis = self.lower_visibility(&i.vis, None);
|
let mut vis = self.lower_visibility(&i.vis, None);
|
||||||
let attrs = self.lower_attrs(&i.attrs);
|
let attrs = self.lower_attrs(&i.attrs);
|
||||||
if let ItemKind::MacroDef(ref def) = i.node {
|
if let ItemKind::MacroDef(ref def) = i.node {
|
||||||
if !def.legacy || attr::contains_name(&i.attrs, "macro_export") ||
|
if !def.legacy || attr::contains_name(&i.attrs, "macro_export") ||
|
||||||
|
@ -3403,7 +3424,7 @@ impl<'a> LoweringContext<'a> {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
let node = self.lower_item_kind(i.id, &mut name, &attrs, &vis, &i.node);
|
let node = self.lower_item_kind(i.id, &mut name, &attrs, &mut vis, &i.node);
|
||||||
|
|
||||||
let LoweredNodeId { node_id, hir_id } = self.lower_node_id(i.id);
|
let LoweredNodeId { node_id, hir_id } = self.lower_node_id(i.id);
|
||||||
|
|
||||||
|
|
|
@ -1136,15 +1136,7 @@ impl UnreachablePub {
|
||||||
|
|
||||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnreachablePub {
|
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnreachablePub {
|
||||||
fn check_item(&mut self, cx: &LateContext, item: &hir::Item) {
|
fn check_item(&mut self, cx: &LateContext, item: &hir::Item) {
|
||||||
match item.node {
|
self.perform_lint(cx, "item", item.id, &item.vis, item.span, true);
|
||||||
hir::ItemKind::Use(_, hir::UseKind::ListStem) => {
|
|
||||||
// Hack: ignore these `use foo::{}` remnants which are just a figment
|
|
||||||
// our IR.
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
self.perform_lint(cx, "item", item.id, &item.vis, item.span, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_foreign_item(&mut self, cx: &LateContext, foreign_item: &hir::ForeignItem) {
|
fn check_foreign_item(&mut self, cx: &LateContext, foreign_item: &hir::ForeignItem) {
|
||||||
|
|
Loading…
Reference in a new issue