Skip to content

Commit

Permalink
call it hir::VisibilityKind instead of hir::Visibility_:*
Browse files Browse the repository at this point in the history
It was pointed out in review that the glob-exported
underscore-suffixed convention for `Spanned` HIR nodes is no longer
preferred: see February 2016's #31487 for AST's migration away from
this style towards properly namespaced NodeKind enums.

This concerns #51968.
  • Loading branch information
zackmdavis committed Jul 1, 2018
1 parent c2d44b2 commit 43a0a65
Show file tree
Hide file tree
Showing 15 changed files with 74 additions and 71 deletions.
2 changes: 1 addition & 1 deletion src/librustc/hir/intravisit.rs
Expand Up @@ -1104,7 +1104,7 @@ pub fn walk_arm<'v, V: Visitor<'v>>(visitor: &mut V, arm: &'v Arm) {
}

pub fn walk_vis<'v, V: Visitor<'v>>(visitor: &mut V, vis: &'v Visibility) {
if let VisibilityRestricted { ref path, id } = vis.node {
if let VisibilityKind::Restricted { ref path, id } = vis.node {
visitor.visit_id(id);
visitor.visit_path(path, id)
}
Expand Down
32 changes: 16 additions & 16 deletions src/librustc/hir/lowering.rs
Expand Up @@ -1285,7 +1285,7 @@ impl<'a> LoweringContext<'a> {
name: keywords::Invalid.name(),
attrs: Default::default(),
node: exist_ty_item_kind,
vis: respan(span.shrink_to_lo(), hir::VisibilityInherited),
vis: respan(span.shrink_to_lo(), hir::VisibilityKind::Inherited),
span: exist_ty_span,
};

Expand Down Expand Up @@ -2771,11 +2771,11 @@ impl<'a> LoweringContext<'a> {
let path = this.lower_path_extra(def, &path, None, ParamMode::Explicit);
let item = hir::ItemUse(P(path), hir::UseKind::Single);
let vis_kind = match vis.node {
hir::VisibilityPublic => hir::VisibilityPublic,
hir::VisibilityCrate(sugar) => hir::VisibilityCrate(sugar),
hir::VisibilityInherited => hir::VisibilityInherited,
hir::VisibilityRestricted { ref path, id: _ } => {
hir::VisibilityRestricted {
hir::VisibilityKind::Public => hir::VisibilityKind::Public,
hir::VisibilityKind::Crate(sugar) => hir::VisibilityKind::Crate(sugar),
hir::VisibilityKind::Inherited => hir::VisibilityKind::Inherited,
hir::VisibilityKind::Restricted { ref path, id: _ } => {
hir::VisibilityKind::Restricted {
path: path.clone(),
// We are allocating a new NodeId here
id: this.next_id().node_id,
Expand Down Expand Up @@ -2844,11 +2844,11 @@ impl<'a> LoweringContext<'a> {

self.with_hir_id_owner(new_id, |this| {
let vis_kind = match vis.node {
hir::VisibilityPublic => hir::VisibilityPublic,
hir::VisibilityCrate(sugar) => hir::VisibilityCrate(sugar),
hir::VisibilityInherited => hir::VisibilityInherited,
hir::VisibilityRestricted { ref path, id: _ } => {
hir::VisibilityRestricted {
hir::VisibilityKind::Public => hir::VisibilityKind::Public,
hir::VisibilityKind::Crate(sugar) => hir::VisibilityKind::Crate(sugar),
hir::VisibilityKind::Inherited => hir::VisibilityKind::Inherited,
hir::VisibilityKind::Restricted { ref path, id: _ } => {
hir::VisibilityKind::Restricted {
path: path.clone(),
// We are allocating a new NodeId here
id: this.next_id().node_id,
Expand Down Expand Up @@ -2876,7 +2876,7 @@ impl<'a> LoweringContext<'a> {
// the stability of `use a::{};`, to avoid it showing up as
// a re-export by accident when `pub`, e.g. in documentation.
let path = P(self.lower_path(id, &prefix, ParamMode::Explicit));
*vis = respan(prefix.span.shrink_to_lo(), hir::VisibilityInherited);
*vis = respan(prefix.span.shrink_to_lo(), hir::VisibilityKind::Inherited);
hir::ItemUse(path, hir::UseKind::ListStem)
}
}
Expand Down Expand Up @@ -4277,17 +4277,17 @@ impl<'a> LoweringContext<'a> {
explicit_owner: Option<NodeId>,
) -> hir::Visibility {
let node = match v.node {
VisibilityKind::Public => hir::VisibilityPublic,
VisibilityKind::Crate(sugar) => hir::VisibilityCrate(sugar),
VisibilityKind::Restricted { ref path, id } => hir::VisibilityRestricted {
VisibilityKind::Public => hir::VisibilityKind::Public,
VisibilityKind::Crate(sugar) => hir::VisibilityKind::Crate(sugar),
VisibilityKind::Restricted { ref path, id } => hir::VisibilityKind::Restricted {
path: P(self.lower_path(id, path, ParamMode::Explicit)),
id: if let Some(owner) = explicit_owner {
self.lower_node_id_with_owner(id, owner).node_id
} else {
self.lower_node_id(id).node_id
},
},
VisibilityKind::Inherited => hir::VisibilityInherited,
VisibilityKind::Inherited => hir::VisibilityKind::Inherited,
};
respan(v.span, node)
}
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/hir/map/collector.rs
Expand Up @@ -459,10 +459,10 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {

fn visit_vis(&mut self, visibility: &'hir Visibility) {
match visibility.node {
VisibilityPublic |
VisibilityCrate(_) |
VisibilityInherited => {}
VisibilityRestricted { id, .. } => {
VisibilityKind::Public |
VisibilityKind::Crate(_) |
VisibilityKind::Inherited => {}
VisibilityKind::Restricted { id, .. } => {
self.insert(id, NodeVisibility(visibility));
self.with_parent(id, |this| {
intravisit::walk_vis(this, visibility);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/hir/map/mod.rs
Expand Up @@ -1050,7 +1050,7 @@ impl<'hir> Map<'hir> {
Some(EntryLifetime(_, _, lifetime)) => lifetime.span,
Some(EntryGenericParam(_, _, param)) => param.span,
Some(EntryVisibility(_, _, &Spanned {
node: VisibilityRestricted { ref path, .. }, ..
node: VisibilityKind::Restricted { ref path, .. }, ..
})) => path.span,
Some(EntryVisibility(_, _, v)) => bug!("unexpected Visibility {:?}", v),
Some(EntryLocal(_, _, local)) => local.span,
Expand Down
25 changes: 12 additions & 13 deletions src/librustc/hir/mod.rs
Expand Up @@ -24,7 +24,6 @@ pub use self::Stmt_::*;
pub use self::Ty_::*;
pub use self::UnOp::*;
pub use self::UnsafeSource::*;
pub use self::Visibility_::*;

use hir::def::Def;
use hir::def_id::{DefId, DefIndex, LocalDefId, CRATE_DEF_INDEX};
Expand Down Expand Up @@ -1929,30 +1928,30 @@ pub struct PolyTraitRef {
pub span: Span,
}

pub type Visibility = Spanned<Visibility_>;
pub type Visibility = Spanned<VisibilityKind>;

#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
pub enum Visibility_ {
VisibilityPublic,
VisibilityCrate(CrateSugar),
VisibilityRestricted { path: P<Path>, id: NodeId },
VisibilityInherited,
pub enum VisibilityKind {
Public,
Crate(CrateSugar),
Restricted { path: P<Path>, id: NodeId },
Inherited,
}

impl Visibility_ {
impl VisibilityKind {
pub fn is_pub(&self) -> bool {
match *self {
VisibilityPublic => true,
VisibilityKind::Public => true,
_ => false
}
}

pub fn is_pub_restricted(&self) -> bool {
match *self {
VisibilityPublic |
VisibilityInherited => false,
VisibilityCrate(..) |
VisibilityRestricted { .. } => true,
VisibilityKind::Public |
VisibilityKind::Inherited => false,
VisibilityKind::Crate(..) |
VisibilityKind::Restricted { .. } => true,
}
}
}
Expand Down
22 changes: 13 additions & 9 deletions src/librustc/hir/print.rs
Expand Up @@ -840,10 +840,10 @@ impl<'a> State<'a> {

pub fn print_visibility(&mut self, vis: &hir::Visibility) -> io::Result<()> {
match vis.node {
hir::VisibilityPublic => self.word_nbsp("pub")?,
hir::VisibilityCrate(ast::CrateSugar::JustCrate) => self.word_nbsp("crate")?,
hir::VisibilityCrate(ast::CrateSugar::PubCrate) => self.word_nbsp("pub(crate)")?,
hir::VisibilityRestricted { ref path, .. } => {
hir::VisibilityKind::Public => self.word_nbsp("pub")?,
hir::VisibilityKind::Crate(ast::CrateSugar::JustCrate) => self.word_nbsp("crate")?,
hir::VisibilityKind::Crate(ast::CrateSugar::PubCrate) => self.word_nbsp("pub(crate)")?,
hir::VisibilityKind::Restricted { ref path, .. } => {
self.s.word("pub(")?;
if path.segments.len() == 1 &&
path.segments[0].ident.name == keywords::Super.name() {
Expand All @@ -856,7 +856,7 @@ impl<'a> State<'a> {
}
self.word_nbsp(")")?;
}
hir::VisibilityInherited => ()
hir::VisibilityKind::Inherited => ()
}

Ok(())
Expand Down Expand Up @@ -952,16 +952,19 @@ impl<'a> State<'a> {
self.print_outer_attributes(&ti.attrs)?;
match ti.node {
hir::TraitItemKind::Const(ref ty, default) => {
let vis = Spanned { span: syntax_pos::DUMMY_SP, node: hir::VisibilityInherited };
let vis = Spanned { span: syntax_pos::DUMMY_SP,
node: hir::VisibilityKind::Inherited };
self.print_associated_const(ti.ident, &ty, default, &vis)?;
}
hir::TraitItemKind::Method(ref sig, hir::TraitMethod::Required(ref arg_names)) => {
let vis = Spanned { span: syntax_pos::DUMMY_SP, node: hir::VisibilityInherited };
let vis = Spanned { span: syntax_pos::DUMMY_SP,
node: hir::VisibilityKind::Inherited };
self.print_method_sig(ti.ident, sig, &ti.generics, &vis, arg_names, None)?;
self.s.word(";")?;
}
hir::TraitItemKind::Method(ref sig, hir::TraitMethod::Provided(body)) => {
let vis = Spanned { span: syntax_pos::DUMMY_SP, node: hir::VisibilityInherited };
let vis = Spanned { span: syntax_pos::DUMMY_SP,
node: hir::VisibilityKind::Inherited };
self.head("")?;
self.print_method_sig(ti.ident, sig, &ti.generics, &vis, &[], Some(body))?;
self.nbsp()?;
Expand Down Expand Up @@ -2267,7 +2270,8 @@ impl<'a> State<'a> {
},
name,
&generics,
&Spanned { span: syntax_pos::DUMMY_SP, node: hir::VisibilityInherited },
&Spanned { span: syntax_pos::DUMMY_SP,
node: hir::VisibilityKind::Inherited },
arg_names,
None)?;
self.end()
Expand Down
12 changes: 6 additions & 6 deletions src/librustc/ich/impls_hir.rs
Expand Up @@ -710,20 +710,20 @@ impl_stable_hash_for!(enum ::syntax::ast::CrateSugar {
PubCrate,
});

impl<'a> HashStable<StableHashingContext<'a>> for hir::Visibility_ {
impl<'a> HashStable<StableHashingContext<'a>> for hir::VisibilityKind {
fn hash_stable<W: StableHasherResult>(&self,
hcx: &mut StableHashingContext<'a>,
hasher: &mut StableHasher<W>) {
mem::discriminant(self).hash_stable(hcx, hasher);
match *self {
hir::VisibilityPublic |
hir::VisibilityInherited => {
hir::VisibilityKind::Public |
hir::VisibilityKind::Inherited => {
// No fields to hash.
}
hir::VisibilityCrate(sugar) => {
hir::VisibilityKind::Crate(sugar) => {
sugar.hash_stable(hcx, hasher);
}
hir::VisibilityRestricted { ref path, id } => {
hir::VisibilityKind::Restricted { ref path, id } => {
hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
id.hash_stable(hcx, hasher);
});
Expand All @@ -733,7 +733,7 @@ impl<'a> HashStable<StableHashingContext<'a>> for hir::Visibility_ {
}
}

impl_stable_hash_for_spanned!(hir::Visibility_);
impl_stable_hash_for_spanned!(hir::VisibilityKind);

impl<'a> HashStable<StableHashingContext<'a>> for hir::Defaultness {
fn hash_stable<W: StableHasherResult>(&self,
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/ty/mod.rs
Expand Up @@ -269,15 +269,15 @@ impl<'a, 'gcx, 'tcx> DefIdTree for TyCtxt<'a, 'gcx, 'tcx> {
impl Visibility {
pub fn from_hir(visibility: &hir::Visibility, id: NodeId, tcx: TyCtxt) -> Self {
match visibility.node {
hir::VisibilityPublic => Visibility::Public,
hir::VisibilityCrate(_) => Visibility::Restricted(DefId::local(CRATE_DEF_INDEX)),
hir::VisibilityRestricted { ref path, .. } => match path.def {
hir::VisibilityKind::Public => Visibility::Public,
hir::VisibilityKind::Crate(_) => Visibility::Restricted(DefId::local(CRATE_DEF_INDEX)),
hir::VisibilityKind::Restricted { ref path, .. } => match path.def {
// If there is no resolution, `resolve` will have already reported an error, so
// assume that the visibility is public to avoid reporting more privacy errors.
Def::Err => Visibility::Public,
def => Visibility::Restricted(def.def_id()),
},
hir::VisibilityInherited => {
hir::VisibilityKind::Inherited => {
Visibility::Restricted(tcx.hir.get_module_parent(id))
}
}
Expand Down
14 changes: 7 additions & 7 deletions src/librustc_lint/builtin.rs
Expand Up @@ -397,7 +397,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
hir::ItemUnion(..) => "a union",
hir::ItemTrait(.., ref trait_item_refs) => {
// Issue #11592, traits are always considered exported, even when private.
if it.vis.node == hir::VisibilityInherited {
if it.vis.node == hir::VisibilityKind::Inherited {
self.private_traits.insert(it.id);
for trait_item_ref in trait_item_refs {
self.private_traits.insert(trait_item_ref.id.node_id);
Expand All @@ -414,7 +414,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
if let Some(node_id) = cx.tcx.hir.as_local_node_id(real_trait) {
match cx.tcx.hir.find(node_id) {
Some(hir_map::NodeItem(item)) => {
if item.vis.node == hir::VisibilityInherited {
if item.vis.node == hir::VisibilityKind::Inherited {
for impl_item_ref in impl_item_refs {
self.private_traits.insert(impl_item_ref.id.node_id);
}
Expand Down Expand Up @@ -1179,15 +1179,15 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InvalidNoMangleItems {
fn check_item(&mut self, cx: &LateContext, it: &hir::Item) {
let suggest_export = |vis: &hir::Visibility, err: &mut DiagnosticBuilder| {
let suggestion = match vis.node {
hir::VisibilityInherited => {
hir::VisibilityKind::Inherited => {
// inherited visibility is empty span at item start; need an extra space
Some("pub ".to_owned())
},
hir::VisibilityRestricted { .. } |
hir::VisibilityCrate(_) => {
hir::VisibilityKind::Restricted { .. } |
hir::VisibilityKind::Crate(_) => {
Some("pub".to_owned())
},
hir::VisibilityPublic => {
hir::VisibilityKind::Public => {
err.help("try exporting the item with a `pub use` statement");
None
}
Expand Down Expand Up @@ -1399,7 +1399,7 @@ impl UnreachablePub {
vis: &hir::Visibility, span: Span, exportable: bool) {
let mut applicability = Applicability::MachineApplicable;
match vis.node {
hir::VisibilityPublic if !cx.access_levels.is_reachable(id) => {
hir::VisibilityKind::Public if !cx.access_levels.is_reachable(id) => {
if span.ctxt().outer().expn_info().is_some() {
applicability = Applicability::MaybeIncorrect;
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_metadata/encoder.rs
Expand Up @@ -320,7 +320,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
fn encode_info_for_items(&mut self) -> Index {
let krate = self.tcx.hir.krate();
let mut index = IndexBuilder::new(self);
let vis = Spanned { span: syntax_pos::DUMMY_SP, node: hir::VisibilityPublic };
let vis = Spanned { span: syntax_pos::DUMMY_SP, node: hir::VisibilityKind::Public };
index.record(DefId::local(CRATE_DEF_INDEX),
IsolatedEncoder::encode_info_for_mod,
FromId(CRATE_NODE_ID, (&krate.module, &krate.attrs, &vis)));
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_privacy/lib.rs
Expand Up @@ -1469,8 +1469,8 @@ impl<'a, 'tcx: 'a> TypeVisitor<'tcx> for SearchInterfaceForPrivateItemsVisitor<'
}
if !vis.is_at_least(self.required_visibility, self.tcx) {
let vis_adj = match hir_vis.node {
hir::VisibilityCrate(_) => "crate-visible",
hir::VisibilityRestricted { .. } => "restricted",
hir::VisibilityKind::Crate(_) => "crate-visible",
hir::VisibilityKind::Restricted { .. } => "restricted",
_ => "private"
};

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_save_analysis/lib.rs
Expand Up @@ -633,7 +633,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
..
}) |
Node::NodeVisibility(&Spanned {
node: hir::VisibilityRestricted { ref path, .. }, .. }) => path.def,
node: hir::VisibilityKind::Restricted { ref path, .. }, .. }) => path.def,

Node::NodeExpr(&hir::Expr {
node: hir::ExprStruct(ref qpath, ..),
Expand Down
8 changes: 4 additions & 4 deletions src/librustdoc/clean/mod.rs
Expand Up @@ -3226,10 +3226,10 @@ pub enum Visibility {
impl Clean<Option<Visibility>> for hir::Visibility {
fn clean(&self, cx: &DocContext) -> Option<Visibility> {
Some(match self.node {
hir::VisibilityPublic => Visibility::Public,
hir::VisibilityInherited => Visibility::Inherited,
hir::VisibilityCrate(_) => Visibility::Crate,
hir::VisibilityRestricted { ref path, .. } => {
hir::VisibilityKind::Public => Visibility::Public,
hir::VisibilityKind::Inherited => Visibility::Inherited,
hir::VisibilityKind::Crate(_) => Visibility::Crate,
hir::VisibilityKind::Restricted { ref path, .. } => {
let path = path.clean(cx);
let did = register_def(cx, path.def);
Visibility::Restricted(did, path)
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/doctree.rs
Expand Up @@ -54,7 +54,7 @@ impl Module {
Module {
name : name,
id: ast::CRATE_NODE_ID,
vis: Spanned { span: syntax_pos::DUMMY_SP, node: hir::VisibilityInherited },
vis: Spanned { span: syntax_pos::DUMMY_SP, node: hir::VisibilityKind::Inherited },
stab: None,
depr: None,
where_outer: syntax_pos::DUMMY_SP,
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/visit_ast.rs
Expand Up @@ -96,7 +96,7 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> {
self.module = self.visit_mod_contents(krate.span,
krate.attrs.clone(),
Spanned { span: syntax_pos::DUMMY_SP,
node: hir::VisibilityPublic },
node: hir::VisibilityKind::Public },
ast::CRATE_NODE_ID,
&krate.module,
None);
Expand Down

0 comments on commit 43a0a65

Please sign in to comment.