Skip to content

Commit 43a0a65

Browse files
committed
call it hir::VisibilityKind instead of hir::Visibility_:*
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.
1 parent c2d44b2 commit 43a0a65

File tree

15 files changed

+74
-71
lines changed

15 files changed

+74
-71
lines changed

src/librustc/hir/intravisit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1104,7 +1104,7 @@ pub fn walk_arm<'v, V: Visitor<'v>>(visitor: &mut V, arm: &'v Arm) {
11041104
}
11051105

11061106
pub fn walk_vis<'v, V: Visitor<'v>>(visitor: &mut V, vis: &'v Visibility) {
1107-
if let VisibilityRestricted { ref path, id } = vis.node {
1107+
if let VisibilityKind::Restricted { ref path, id } = vis.node {
11081108
visitor.visit_id(id);
11091109
visitor.visit_path(path, id)
11101110
}

src/librustc/hir/lowering.rs

+16-16
Original file line numberDiff line numberDiff line change
@@ -1285,7 +1285,7 @@ impl<'a> LoweringContext<'a> {
12851285
name: keywords::Invalid.name(),
12861286
attrs: Default::default(),
12871287
node: exist_ty_item_kind,
1288-
vis: respan(span.shrink_to_lo(), hir::VisibilityInherited),
1288+
vis: respan(span.shrink_to_lo(), hir::VisibilityKind::Inherited),
12891289
span: exist_ty_span,
12901290
};
12911291

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

28452845
self.with_hir_id_owner(new_id, |this| {
28462846
let vis_kind = match vis.node {
2847-
hir::VisibilityPublic => hir::VisibilityPublic,
2848-
hir::VisibilityCrate(sugar) => hir::VisibilityCrate(sugar),
2849-
hir::VisibilityInherited => hir::VisibilityInherited,
2850-
hir::VisibilityRestricted { ref path, id: _ } => {
2851-
hir::VisibilityRestricted {
2847+
hir::VisibilityKind::Public => hir::VisibilityKind::Public,
2848+
hir::VisibilityKind::Crate(sugar) => hir::VisibilityKind::Crate(sugar),
2849+
hir::VisibilityKind::Inherited => hir::VisibilityKind::Inherited,
2850+
hir::VisibilityKind::Restricted { ref path, id: _ } => {
2851+
hir::VisibilityKind::Restricted {
28522852
path: path.clone(),
28532853
// We are allocating a new NodeId here
28542854
id: this.next_id().node_id,
@@ -2876,7 +2876,7 @@ impl<'a> LoweringContext<'a> {
28762876
// the stability of `use a::{};`, to avoid it showing up as
28772877
// a re-export by accident when `pub`, e.g. in documentation.
28782878
let path = P(self.lower_path(id, &prefix, ParamMode::Explicit));
2879-
*vis = respan(prefix.span.shrink_to_lo(), hir::VisibilityInherited);
2879+
*vis = respan(prefix.span.shrink_to_lo(), hir::VisibilityKind::Inherited);
28802880
hir::ItemUse(path, hir::UseKind::ListStem)
28812881
}
28822882
}
@@ -4277,17 +4277,17 @@ impl<'a> LoweringContext<'a> {
42774277
explicit_owner: Option<NodeId>,
42784278
) -> hir::Visibility {
42794279
let node = match v.node {
4280-
VisibilityKind::Public => hir::VisibilityPublic,
4281-
VisibilityKind::Crate(sugar) => hir::VisibilityCrate(sugar),
4282-
VisibilityKind::Restricted { ref path, id } => hir::VisibilityRestricted {
4280+
VisibilityKind::Public => hir::VisibilityKind::Public,
4281+
VisibilityKind::Crate(sugar) => hir::VisibilityKind::Crate(sugar),
4282+
VisibilityKind::Restricted { ref path, id } => hir::VisibilityKind::Restricted {
42834283
path: P(self.lower_path(id, path, ParamMode::Explicit)),
42844284
id: if let Some(owner) = explicit_owner {
42854285
self.lower_node_id_with_owner(id, owner).node_id
42864286
} else {
42874287
self.lower_node_id(id).node_id
42884288
},
42894289
},
4290-
VisibilityKind::Inherited => hir::VisibilityInherited,
4290+
VisibilityKind::Inherited => hir::VisibilityKind::Inherited,
42914291
};
42924292
respan(v.span, node)
42934293
}

src/librustc/hir/map/collector.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -459,10 +459,10 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
459459

460460
fn visit_vis(&mut self, visibility: &'hir Visibility) {
461461
match visibility.node {
462-
VisibilityPublic |
463-
VisibilityCrate(_) |
464-
VisibilityInherited => {}
465-
VisibilityRestricted { id, .. } => {
462+
VisibilityKind::Public |
463+
VisibilityKind::Crate(_) |
464+
VisibilityKind::Inherited => {}
465+
VisibilityKind::Restricted { id, .. } => {
466466
self.insert(id, NodeVisibility(visibility));
467467
self.with_parent(id, |this| {
468468
intravisit::walk_vis(this, visibility);

src/librustc/hir/map/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1050,7 +1050,7 @@ impl<'hir> Map<'hir> {
10501050
Some(EntryLifetime(_, _, lifetime)) => lifetime.span,
10511051
Some(EntryGenericParam(_, _, param)) => param.span,
10521052
Some(EntryVisibility(_, _, &Spanned {
1053-
node: VisibilityRestricted { ref path, .. }, ..
1053+
node: VisibilityKind::Restricted { ref path, .. }, ..
10541054
})) => path.span,
10551055
Some(EntryVisibility(_, _, v)) => bug!("unexpected Visibility {:?}", v),
10561056
Some(EntryLocal(_, _, local)) => local.span,

src/librustc/hir/mod.rs

+12-13
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ pub use self::Stmt_::*;
2424
pub use self::Ty_::*;
2525
pub use self::UnOp::*;
2626
pub use self::UnsafeSource::*;
27-
pub use self::Visibility_::*;
2827

2928
use hir::def::Def;
3029
use hir::def_id::{DefId, DefIndex, LocalDefId, CRATE_DEF_INDEX};
@@ -1929,30 +1928,30 @@ pub struct PolyTraitRef {
19291928
pub span: Span,
19301929
}
19311930

1932-
pub type Visibility = Spanned<Visibility_>;
1931+
pub type Visibility = Spanned<VisibilityKind>;
19331932

19341933
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
1935-
pub enum Visibility_ {
1936-
VisibilityPublic,
1937-
VisibilityCrate(CrateSugar),
1938-
VisibilityRestricted { path: P<Path>, id: NodeId },
1939-
VisibilityInherited,
1934+
pub enum VisibilityKind {
1935+
Public,
1936+
Crate(CrateSugar),
1937+
Restricted { path: P<Path>, id: NodeId },
1938+
Inherited,
19401939
}
19411940

1942-
impl Visibility_ {
1941+
impl VisibilityKind {
19431942
pub fn is_pub(&self) -> bool {
19441943
match *self {
1945-
VisibilityPublic => true,
1944+
VisibilityKind::Public => true,
19461945
_ => false
19471946
}
19481947
}
19491948

19501949
pub fn is_pub_restricted(&self) -> bool {
19511950
match *self {
1952-
VisibilityPublic |
1953-
VisibilityInherited => false,
1954-
VisibilityCrate(..) |
1955-
VisibilityRestricted { .. } => true,
1951+
VisibilityKind::Public |
1952+
VisibilityKind::Inherited => false,
1953+
VisibilityKind::Crate(..) |
1954+
VisibilityKind::Restricted { .. } => true,
19561955
}
19571956
}
19581957
}

src/librustc/hir/print.rs

+13-9
Original file line numberDiff line numberDiff line change
@@ -840,10 +840,10 @@ impl<'a> State<'a> {
840840

841841
pub fn print_visibility(&mut self, vis: &hir::Visibility) -> io::Result<()> {
842842
match vis.node {
843-
hir::VisibilityPublic => self.word_nbsp("pub")?,
844-
hir::VisibilityCrate(ast::CrateSugar::JustCrate) => self.word_nbsp("crate")?,
845-
hir::VisibilityCrate(ast::CrateSugar::PubCrate) => self.word_nbsp("pub(crate)")?,
846-
hir::VisibilityRestricted { ref path, .. } => {
843+
hir::VisibilityKind::Public => self.word_nbsp("pub")?,
844+
hir::VisibilityKind::Crate(ast::CrateSugar::JustCrate) => self.word_nbsp("crate")?,
845+
hir::VisibilityKind::Crate(ast::CrateSugar::PubCrate) => self.word_nbsp("pub(crate)")?,
846+
hir::VisibilityKind::Restricted { ref path, .. } => {
847847
self.s.word("pub(")?;
848848
if path.segments.len() == 1 &&
849849
path.segments[0].ident.name == keywords::Super.name() {
@@ -856,7 +856,7 @@ impl<'a> State<'a> {
856856
}
857857
self.word_nbsp(")")?;
858858
}
859-
hir::VisibilityInherited => ()
859+
hir::VisibilityKind::Inherited => ()
860860
}
861861

862862
Ok(())
@@ -952,16 +952,19 @@ impl<'a> State<'a> {
952952
self.print_outer_attributes(&ti.attrs)?;
953953
match ti.node {
954954
hir::TraitItemKind::Const(ref ty, default) => {
955-
let vis = Spanned { span: syntax_pos::DUMMY_SP, node: hir::VisibilityInherited };
955+
let vis = Spanned { span: syntax_pos::DUMMY_SP,
956+
node: hir::VisibilityKind::Inherited };
956957
self.print_associated_const(ti.ident, &ty, default, &vis)?;
957958
}
958959
hir::TraitItemKind::Method(ref sig, hir::TraitMethod::Required(ref arg_names)) => {
959-
let vis = Spanned { span: syntax_pos::DUMMY_SP, node: hir::VisibilityInherited };
960+
let vis = Spanned { span: syntax_pos::DUMMY_SP,
961+
node: hir::VisibilityKind::Inherited };
960962
self.print_method_sig(ti.ident, sig, &ti.generics, &vis, arg_names, None)?;
961963
self.s.word(";")?;
962964
}
963965
hir::TraitItemKind::Method(ref sig, hir::TraitMethod::Provided(body)) => {
964-
let vis = Spanned { span: syntax_pos::DUMMY_SP, node: hir::VisibilityInherited };
966+
let vis = Spanned { span: syntax_pos::DUMMY_SP,
967+
node: hir::VisibilityKind::Inherited };
965968
self.head("")?;
966969
self.print_method_sig(ti.ident, sig, &ti.generics, &vis, &[], Some(body))?;
967970
self.nbsp()?;
@@ -2267,7 +2270,8 @@ impl<'a> State<'a> {
22672270
},
22682271
name,
22692272
&generics,
2270-
&Spanned { span: syntax_pos::DUMMY_SP, node: hir::VisibilityInherited },
2273+
&Spanned { span: syntax_pos::DUMMY_SP,
2274+
node: hir::VisibilityKind::Inherited },
22712275
arg_names,
22722276
None)?;
22732277
self.end()

src/librustc/ich/impls_hir.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -710,20 +710,20 @@ impl_stable_hash_for!(enum ::syntax::ast::CrateSugar {
710710
PubCrate,
711711
});
712712

713-
impl<'a> HashStable<StableHashingContext<'a>> for hir::Visibility_ {
713+
impl<'a> HashStable<StableHashingContext<'a>> for hir::VisibilityKind {
714714
fn hash_stable<W: StableHasherResult>(&self,
715715
hcx: &mut StableHashingContext<'a>,
716716
hasher: &mut StableHasher<W>) {
717717
mem::discriminant(self).hash_stable(hcx, hasher);
718718
match *self {
719-
hir::VisibilityPublic |
720-
hir::VisibilityInherited => {
719+
hir::VisibilityKind::Public |
720+
hir::VisibilityKind::Inherited => {
721721
// No fields to hash.
722722
}
723-
hir::VisibilityCrate(sugar) => {
723+
hir::VisibilityKind::Crate(sugar) => {
724724
sugar.hash_stable(hcx, hasher);
725725
}
726-
hir::VisibilityRestricted { ref path, id } => {
726+
hir::VisibilityKind::Restricted { ref path, id } => {
727727
hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
728728
id.hash_stable(hcx, hasher);
729729
});
@@ -733,7 +733,7 @@ impl<'a> HashStable<StableHashingContext<'a>> for hir::Visibility_ {
733733
}
734734
}
735735

736-
impl_stable_hash_for_spanned!(hir::Visibility_);
736+
impl_stable_hash_for_spanned!(hir::VisibilityKind);
737737

738738
impl<'a> HashStable<StableHashingContext<'a>> for hir::Defaultness {
739739
fn hash_stable<W: StableHasherResult>(&self,

src/librustc/ty/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -269,15 +269,15 @@ impl<'a, 'gcx, 'tcx> DefIdTree for TyCtxt<'a, 'gcx, 'tcx> {
269269
impl Visibility {
270270
pub fn from_hir(visibility: &hir::Visibility, id: NodeId, tcx: TyCtxt) -> Self {
271271
match visibility.node {
272-
hir::VisibilityPublic => Visibility::Public,
273-
hir::VisibilityCrate(_) => Visibility::Restricted(DefId::local(CRATE_DEF_INDEX)),
274-
hir::VisibilityRestricted { ref path, .. } => match path.def {
272+
hir::VisibilityKind::Public => Visibility::Public,
273+
hir::VisibilityKind::Crate(_) => Visibility::Restricted(DefId::local(CRATE_DEF_INDEX)),
274+
hir::VisibilityKind::Restricted { ref path, .. } => match path.def {
275275
// If there is no resolution, `resolve` will have already reported an error, so
276276
// assume that the visibility is public to avoid reporting more privacy errors.
277277
Def::Err => Visibility::Public,
278278
def => Visibility::Restricted(def.def_id()),
279279
},
280-
hir::VisibilityInherited => {
280+
hir::VisibilityKind::Inherited => {
281281
Visibility::Restricted(tcx.hir.get_module_parent(id))
282282
}
283283
}

src/librustc_lint/builtin.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
397397
hir::ItemUnion(..) => "a union",
398398
hir::ItemTrait(.., ref trait_item_refs) => {
399399
// Issue #11592, traits are always considered exported, even when private.
400-
if it.vis.node == hir::VisibilityInherited {
400+
if it.vis.node == hir::VisibilityKind::Inherited {
401401
self.private_traits.insert(it.id);
402402
for trait_item_ref in trait_item_refs {
403403
self.private_traits.insert(trait_item_ref.id.node_id);
@@ -414,7 +414,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
414414
if let Some(node_id) = cx.tcx.hir.as_local_node_id(real_trait) {
415415
match cx.tcx.hir.find(node_id) {
416416
Some(hir_map::NodeItem(item)) => {
417-
if item.vis.node == hir::VisibilityInherited {
417+
if item.vis.node == hir::VisibilityKind::Inherited {
418418
for impl_item_ref in impl_item_refs {
419419
self.private_traits.insert(impl_item_ref.id.node_id);
420420
}
@@ -1179,15 +1179,15 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InvalidNoMangleItems {
11791179
fn check_item(&mut self, cx: &LateContext, it: &hir::Item) {
11801180
let suggest_export = |vis: &hir::Visibility, err: &mut DiagnosticBuilder| {
11811181
let suggestion = match vis.node {
1182-
hir::VisibilityInherited => {
1182+
hir::VisibilityKind::Inherited => {
11831183
// inherited visibility is empty span at item start; need an extra space
11841184
Some("pub ".to_owned())
11851185
},
1186-
hir::VisibilityRestricted { .. } |
1187-
hir::VisibilityCrate(_) => {
1186+
hir::VisibilityKind::Restricted { .. } |
1187+
hir::VisibilityKind::Crate(_) => {
11881188
Some("pub".to_owned())
11891189
},
1190-
hir::VisibilityPublic => {
1190+
hir::VisibilityKind::Public => {
11911191
err.help("try exporting the item with a `pub use` statement");
11921192
None
11931193
}
@@ -1399,7 +1399,7 @@ impl UnreachablePub {
13991399
vis: &hir::Visibility, span: Span, exportable: bool) {
14001400
let mut applicability = Applicability::MachineApplicable;
14011401
match vis.node {
1402-
hir::VisibilityPublic if !cx.access_levels.is_reachable(id) => {
1402+
hir::VisibilityKind::Public if !cx.access_levels.is_reachable(id) => {
14031403
if span.ctxt().outer().expn_info().is_some() {
14041404
applicability = Applicability::MaybeIncorrect;
14051405
}

src/librustc_metadata/encoder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
320320
fn encode_info_for_items(&mut self) -> Index {
321321
let krate = self.tcx.hir.krate();
322322
let mut index = IndexBuilder::new(self);
323-
let vis = Spanned { span: syntax_pos::DUMMY_SP, node: hir::VisibilityPublic };
323+
let vis = Spanned { span: syntax_pos::DUMMY_SP, node: hir::VisibilityKind::Public };
324324
index.record(DefId::local(CRATE_DEF_INDEX),
325325
IsolatedEncoder::encode_info_for_mod,
326326
FromId(CRATE_NODE_ID, (&krate.module, &krate.attrs, &vis)));

src/librustc_privacy/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1469,8 +1469,8 @@ impl<'a, 'tcx: 'a> TypeVisitor<'tcx> for SearchInterfaceForPrivateItemsVisitor<'
14691469
}
14701470
if !vis.is_at_least(self.required_visibility, self.tcx) {
14711471
let vis_adj = match hir_vis.node {
1472-
hir::VisibilityCrate(_) => "crate-visible",
1473-
hir::VisibilityRestricted { .. } => "restricted",
1472+
hir::VisibilityKind::Crate(_) => "crate-visible",
1473+
hir::VisibilityKind::Restricted { .. } => "restricted",
14741474
_ => "private"
14751475
};
14761476

src/librustc_save_analysis/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
633633
..
634634
}) |
635635
Node::NodeVisibility(&Spanned {
636-
node: hir::VisibilityRestricted { ref path, .. }, .. }) => path.def,
636+
node: hir::VisibilityKind::Restricted { ref path, .. }, .. }) => path.def,
637637

638638
Node::NodeExpr(&hir::Expr {
639639
node: hir::ExprStruct(ref qpath, ..),

src/librustdoc/clean/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -3226,10 +3226,10 @@ pub enum Visibility {
32263226
impl Clean<Option<Visibility>> for hir::Visibility {
32273227
fn clean(&self, cx: &DocContext) -> Option<Visibility> {
32283228
Some(match self.node {
3229-
hir::VisibilityPublic => Visibility::Public,
3230-
hir::VisibilityInherited => Visibility::Inherited,
3231-
hir::VisibilityCrate(_) => Visibility::Crate,
3232-
hir::VisibilityRestricted { ref path, .. } => {
3229+
hir::VisibilityKind::Public => Visibility::Public,
3230+
hir::VisibilityKind::Inherited => Visibility::Inherited,
3231+
hir::VisibilityKind::Crate(_) => Visibility::Crate,
3232+
hir::VisibilityKind::Restricted { ref path, .. } => {
32333233
let path = path.clean(cx);
32343234
let did = register_def(cx, path.def);
32353235
Visibility::Restricted(did, path)

src/librustdoc/doctree.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ impl Module {
5454
Module {
5555
name : name,
5656
id: ast::CRATE_NODE_ID,
57-
vis: Spanned { span: syntax_pos::DUMMY_SP, node: hir::VisibilityInherited },
57+
vis: Spanned { span: syntax_pos::DUMMY_SP, node: hir::VisibilityKind::Inherited },
5858
stab: None,
5959
depr: None,
6060
where_outer: syntax_pos::DUMMY_SP,

src/librustdoc/visit_ast.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> {
9696
self.module = self.visit_mod_contents(krate.span,
9797
krate.attrs.clone(),
9898
Spanned { span: syntax_pos::DUMMY_SP,
99-
node: hir::VisibilityPublic },
99+
node: hir::VisibilityKind::Public },
100100
ast::CRATE_NODE_ID,
101101
&krate.module,
102102
None);

0 commit comments

Comments
 (0)