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.
15 files changed:
}
pub fn walk_vis<'v, V: Visitor<'v>>(visitor: &mut V, vis: &'v Visibility) {
}
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)
}
visitor.visit_id(id);
visitor.visit_path(path, id)
}
name: keywords::Invalid.name(),
attrs: Default::default(),
node: exist_ty_item_kind,
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),
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 {
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,
path: path.clone(),
// We are allocating a new NodeId here
id: this.next_id().node_id,
self.with_hir_id_owner(new_id, |this| {
let vis_kind = match vis.node {
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,
path: path.clone(),
// We are allocating a new NodeId here
id: this.next_id().node_id,
// 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));
// 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)
}
}
hir::ItemUse(path, hir::UseKind::ListStem)
}
}
explicit_owner: Option<NodeId>,
) -> hir::Visibility {
let node = match v.node {
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
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
self.lower_node_id(id).node_id
},
},
self.lower_node_id(id).node_id
},
},
- VisibilityKind::Inherited => hir::VisibilityInherited,
+ VisibilityKind::Inherited => hir::VisibilityKind::Inherited,
};
respan(v.span, node)
}
};
respan(v.span, node)
}
fn visit_vis(&mut self, visibility: &'hir Visibility) {
match visibility.node {
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);
self.insert(id, NodeVisibility(visibility));
self.with_parent(id, |this| {
intravisit::walk_vis(this, visibility);
Some(EntryLifetime(_, _, lifetime)) => lifetime.span,
Some(EntryGenericParam(_, _, param)) => param.span,
Some(EntryVisibility(_, _, &Spanned {
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,
})) => path.span,
Some(EntryVisibility(_, _, v)) => bug!("unexpected Visibility {:?}", v),
Some(EntryLocal(_, _, local)) => local.span,
pub use self::Ty_::*;
pub use self::UnOp::*;
pub use self::UnsafeSource::*;
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};
use hir::def::Def;
use hir::def_id::{DefId, DefIndex, LocalDefId, CRATE_DEF_INDEX};
-pub type Visibility = Spanned<Visibility_>;
+pub type Visibility = Spanned<VisibilityKind>;
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
#[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,
pub fn is_pub(&self) -> bool {
match *self {
pub fn is_pub(&self) -> bool {
match *self {
- VisibilityPublic => true,
+ VisibilityKind::Public => true,
_ => false
}
}
pub fn is_pub_restricted(&self) -> bool {
match *self {
_ => 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,
pub fn print_visibility(&mut self, vis: &hir::Visibility) -> io::Result<()> {
match vis.node {
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() {
self.s.word("pub(")?;
if path.segments.len() == 1 &&
path.segments[0].ident.name == keywords::Super.name() {
}
self.word_nbsp(")")?;
}
}
self.word_nbsp(")")?;
}
- hir::VisibilityInherited => ()
+ hir::VisibilityKind::Inherited => ()
self.print_outer_attributes(&ti.attrs)?;
match ti.node {
hir::TraitItemKind::Const(ref ty, default) => {
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)) => {
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)) => {
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()?;
self.head("")?;
self.print_method_sig(ti.ident, sig, &ti.generics, &vis, &[], Some(body))?;
self.nbsp()?;
- &Spanned { span: syntax_pos::DUMMY_SP, node: hir::VisibilityInherited },
+ &Spanned { span: syntax_pos::DUMMY_SP,
+ node: hir::VisibilityKind::Inherited },
arg_names,
None)?;
self.end()
arg_names,
None)?;
self.end()
-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 {
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 => {
- hir::VisibilityCrate(sugar) => {
+ hir::VisibilityKind::Crate(sugar) => {
sugar.hash_stable(hcx, hasher);
}
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);
});
hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
id.hash_stable(hcx, hasher);
});
-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,
impl<'a> HashStable<StableHashingContext<'a>> for hir::Defaultness {
fn hash_stable<W: StableHasherResult>(&self,
impl Visibility {
pub fn from_hir(visibility: &hir::Visibility, id: NodeId, tcx: TyCtxt) -> Self {
match visibility.node {
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()),
},
// 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))
}
}
Visibility::Restricted(tcx.hir.get_module_parent(id))
}
}
hir::ItemUnion(..) => "a union",
hir::ItemTrait(.., ref trait_item_refs) => {
// Issue #11592, traits are always considered exported, even when private.
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);
self.private_traits.insert(it.id);
for trait_item_ref in trait_item_refs {
self.private_traits.insert(trait_item_ref.id.node_id);
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 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);
}
for impl_item_ref in impl_item_refs {
self.private_traits.insert(impl_item_ref.id.node_id);
}
fn check_item(&mut self, cx: &LateContext, it: &hir::Item) {
let suggest_export = |vis: &hir::Visibility, err: &mut DiagnosticBuilder| {
let suggestion = match vis.node {
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())
},
// 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())
},
Some("pub".to_owned())
},
- hir::VisibilityPublic => {
+ hir::VisibilityKind::Public => {
err.help("try exporting the item with a `pub use` statement");
None
}
err.help("try exporting the item with a `pub use` statement");
None
}
vis: &hir::Visibility, span: Span, exportable: bool) {
let mut applicability = Applicability::MachineApplicable;
match vis.node {
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;
}
if span.ctxt().outer().expn_info().is_some() {
applicability = Applicability::MaybeIncorrect;
}
fn encode_info_for_items(&mut self) -> Index {
let krate = self.tcx.hir.krate();
let mut index = IndexBuilder::new(self);
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)));
index.record(DefId::local(CRATE_DEF_INDEX),
IsolatedEncoder::encode_info_for_mod,
FromId(CRATE_NODE_ID, (&krate.module, &krate.attrs, &vis)));
}
if !vis.is_at_least(self.required_visibility, self.tcx) {
let vis_adj = match hir_vis.node {
}
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",
..
}) |
Node::NodeVisibility(&Spanned {
..
}) |
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, ..),
Node::NodeExpr(&hir::Expr {
node: hir::ExprStruct(ref qpath, ..),
impl Clean<Option<Visibility>> for hir::Visibility {
fn clean(&self, cx: &DocContext) -> Option<Visibility> {
Some(match self.node {
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)
let path = path.clean(cx);
let did = register_def(cx, path.def);
Visibility::Restricted(did, path)
Module {
name : name,
id: ast::CRATE_NODE_ID,
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,
stab: None,
depr: None,
where_outer: syntax_pos::DUMMY_SP,
self.module = self.visit_mod_contents(krate.span,
krate.attrs.clone(),
Spanned { span: syntax_pos::DUMMY_SP,
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);
ast::CRATE_NODE_ID,
&krate.module,
None);