Skip to content

Commit 10d10ef

Browse files
committed
Stop visiting visibility.
1 parent 64c5deb commit 10d10ef

File tree

18 files changed

+29
-95
lines changed

18 files changed

+29
-95
lines changed

compiler/rustc_ast_lowering/src/index.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -290,18 +290,6 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
290290
self.insert(lifetime.span, lifetime.hir_id, Node::Lifetime(lifetime));
291291
}
292292

293-
fn visit_vis(&mut self, visibility: &'hir Visibility<'hir>) {
294-
match visibility.node {
295-
VisibilityKind::Public | VisibilityKind::Crate(_) | VisibilityKind::Inherited => {}
296-
VisibilityKind::Restricted { hir_id, .. } => {
297-
self.insert(visibility.span, hir_id, Node::Visibility(visibility));
298-
self.with_parent(hir_id, |this| {
299-
intravisit::walk_vis(this, visibility);
300-
});
301-
}
302-
}
303-
}
304-
305293
fn visit_variant(&mut self, v: &'hir Variant<'hir>, g: &'hir Generics<'hir>, item_id: HirId) {
306294
self.insert(v.span, v.id, Node::Variant(v));
307295
self.with_parent(v.id, |this| {

compiler/rustc_hir/src/hir.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3210,7 +3210,6 @@ pub enum Node<'hir> {
32103210

32113211
Lifetime(&'hir Lifetime),
32123212
GenericParam(&'hir GenericParam<'hir>),
3213-
Visibility(&'hir Visibility<'hir>),
32143213

32153214
Crate(&'hir Mod<'hir>),
32163215

@@ -3253,7 +3252,6 @@ impl<'hir> Node<'hir> {
32533252
| Node::Binding(..)
32543253
| Node::Arm(..)
32553254
| Node::Local(..)
3256-
| Node::Visibility(..)
32573255
| Node::Crate(..)
32583256
| Node::Ty(..)
32593257
| Node::TraitRef(..)
@@ -3318,18 +3316,18 @@ impl<'hir> Node<'hir> {
33183316
match self {
33193317
Node::Item(i) => match i.kind {
33203318
ItemKind::Fn(ref sig, ref generics, _) => {
3321-
Some(FnKind::ItemFn(i.ident, generics, sig.header, &i.vis))
3319+
Some(FnKind::ItemFn(i.ident, generics, sig.header))
33223320
}
33233321
_ => None,
33243322
},
33253323
Node::TraitItem(ti) => match ti.kind {
33263324
TraitItemKind::Fn(ref sig, TraitFn::Provided(_)) => {
3327-
Some(FnKind::Method(ti.ident, sig, None))
3325+
Some(FnKind::Method(ti.ident, sig))
33283326
}
33293327
_ => None,
33303328
},
33313329
Node::ImplItem(ii) => match ii.kind {
3332-
ImplItemKind::Fn(ref sig, _) => Some(FnKind::Method(ii.ident, sig, Some(&ii.vis))),
3330+
ImplItemKind::Fn(ref sig, _) => Some(FnKind::Method(ii.ident, sig)),
33333331
_ => None,
33343332
},
33353333
Node::Expr(e) => match e.kind {

compiler/rustc_hir/src/intravisit.rs

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,10 @@ where
100100
#[derive(Copy, Clone, Debug)]
101101
pub enum FnKind<'a> {
102102
/// `#[xxx] pub async/const/extern "Abi" fn foo()`
103-
ItemFn(Ident, &'a Generics<'a>, FnHeader, &'a Visibility<'a>),
103+
ItemFn(Ident, &'a Generics<'a>, FnHeader),
104104

105105
/// `fn foo(&self)`
106-
Method(Ident, &'a FnSig<'a>, Option<&'a Visibility<'a>>),
106+
Method(Ident, &'a FnSig<'a>),
107107

108108
/// `|x, y| {}`
109109
Closure,
@@ -112,8 +112,8 @@ pub enum FnKind<'a> {
112112
impl<'a> FnKind<'a> {
113113
pub fn header(&self) -> Option<&FnHeader> {
114114
match *self {
115-
FnKind::ItemFn(_, _, ref header, _) => Some(header),
116-
FnKind::Method(_, ref sig, _) => Some(&sig.header),
115+
FnKind::ItemFn(_, _, ref header) => Some(header),
116+
FnKind::Method(_, ref sig) => Some(&sig.header),
117117
FnKind::Closure => None,
118118
}
119119
}
@@ -475,9 +475,6 @@ pub trait Visitor<'v>: Sized {
475475
walk_assoc_type_binding(self, type_binding)
476476
}
477477
fn visit_attribute(&mut self, _id: HirId, _attr: &'v Attribute) {}
478-
fn visit_vis(&mut self, vis: &'v Visibility<'v>) {
479-
walk_vis(self, vis)
480-
}
481478
fn visit_associated_item_kind(&mut self, kind: &'v AssocItemKind) {
482479
walk_associated_item_kind(self, kind);
483480
}
@@ -554,7 +551,6 @@ pub fn walk_param<'v, V: Visitor<'v>>(visitor: &mut V, param: &'v Param<'v>) {
554551
}
555552

556553
pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item<'v>) {
557-
visitor.visit_vis(&item.vis);
558554
visitor.visit_ident(item.ident);
559555
match item.kind {
560556
ItemKind::ExternCrate(orig_name) => {
@@ -572,7 +568,7 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item<'v>) {
572568
visitor.visit_nested_body(body);
573569
}
574570
ItemKind::Fn(ref sig, ref generics, body_id) => visitor.visit_fn(
575-
FnKind::ItemFn(item.ident, generics, sig.header, &item.vis),
571+
FnKind::ItemFn(item.ident, generics, sig.header),
576572
&sig.decl,
577573
body_id,
578574
item.span,
@@ -859,7 +855,6 @@ pub fn walk_pat<'v, V: Visitor<'v>>(visitor: &mut V, pattern: &'v Pat<'v>) {
859855

860856
pub fn walk_foreign_item<'v, V: Visitor<'v>>(visitor: &mut V, foreign_item: &'v ForeignItem<'v>) {
861857
visitor.visit_id(foreign_item.hir_id());
862-
visitor.visit_vis(&foreign_item.vis);
863858
visitor.visit_ident(foreign_item.ident);
864859

865860
match foreign_item.kind {
@@ -999,7 +994,7 @@ pub fn walk_trait_item<'v, V: Visitor<'v>>(visitor: &mut V, trait_item: &'v Trai
999994
}
1000995
TraitItemKind::Fn(ref sig, TraitFn::Provided(body_id)) => {
1001996
visitor.visit_fn(
1002-
FnKind::Method(trait_item.ident, sig, None),
997+
FnKind::Method(trait_item.ident, sig),
1003998
&sig.decl,
1004999
body_id,
10051000
trait_item.span,
@@ -1025,10 +1020,9 @@ pub fn walk_trait_item_ref<'v, V: Visitor<'v>>(visitor: &mut V, trait_item_ref:
10251020

10261021
pub fn walk_impl_item<'v, V: Visitor<'v>>(visitor: &mut V, impl_item: &'v ImplItem<'v>) {
10271022
// N.B., deliberately force a compilation error if/when new fields are added.
1028-
let ImplItem { def_id: _, ident, ref vis, ref generics, ref kind, span: _ } = *impl_item;
1023+
let ImplItem { def_id: _, ident, ref generics, ref kind, span: _, vis: _ } = *impl_item;
10291024

10301025
visitor.visit_ident(ident);
1031-
visitor.visit_vis(vis);
10321026
visitor.visit_generics(generics);
10331027
match *kind {
10341028
ImplItemKind::Const(ref ty, body) => {
@@ -1038,7 +1032,7 @@ pub fn walk_impl_item<'v, V: Visitor<'v>>(visitor: &mut V, impl_item: &'v ImplIt
10381032
}
10391033
ImplItemKind::Fn(ref sig, body_id) => {
10401034
visitor.visit_fn(
1041-
FnKind::Method(impl_item.ident, sig, Some(&impl_item.vis)),
1035+
FnKind::Method(impl_item.ident, sig),
10421036
&sig.decl,
10431037
body_id,
10441038
impl_item.span,
@@ -1082,7 +1076,6 @@ pub fn walk_struct_def<'v, V: Visitor<'v>>(
10821076

10831077
pub fn walk_field_def<'v, V: Visitor<'v>>(visitor: &mut V, field: &'v FieldDef<'v>) {
10841078
visitor.visit_id(field.hir_id);
1085-
visitor.visit_vis(&field.vis);
10861079
visitor.visit_ident(field.ident);
10871080
visitor.visit_ty(&field.ty);
10881081
}
@@ -1250,13 +1243,6 @@ pub fn walk_arm<'v, V: Visitor<'v>>(visitor: &mut V, arm: &'v Arm<'v>) {
12501243
visitor.visit_expr(&arm.body);
12511244
}
12521245

1253-
pub fn walk_vis<'v, V: Visitor<'v>>(visitor: &mut V, vis: &'v Visibility<'v>) {
1254-
if let VisibilityKind::Restricted { ref path, hir_id } = vis.node {
1255-
visitor.visit_id(hir_id);
1256-
visitor.visit_path(path, hir_id)
1257-
}
1258-
}
1259-
12601246
pub fn walk_associated_item_kind<'v, V: Visitor<'v>>(_: &mut V, _: &'v AssocItemKind) {
12611247
// No visitable content here: this fn exists so you can call it if
12621248
// the right thing to do, should content be added in the future,

compiler/rustc_hir_pretty/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ impl<'a> State<'a> {
9898
self.print_block(&a)
9999
}
100100
Node::Lifetime(a) => self.print_lifetime(&a),
101-
Node::Visibility(a) => self.print_visibility(&a),
102101
Node::GenericParam(_) => panic!("cannot print Node::GenericParam"),
103102
Node::Field(_) => panic!("cannot print Node::Field"),
104103
// These cases do not carry enough information in the

compiler/rustc_lint/src/nonstandard_style.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ impl<'tcx> LateLintPass<'tcx> for NonSnakeCase {
406406
}
407407
_ => (),
408408
},
409-
FnKind::ItemFn(ident, _, header, _) => {
409+
FnKind::ItemFn(ident, _, header) => {
410410
// Skip foreign-ABI #[no_mangle] functions (Issue #31924)
411411
if header.abi != Abi::Rust && cx.sess().contains_name(attrs, sym::no_mangle) {
412412
return;

compiler/rustc_middle/src/hir/map/mod.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use rustc_hir::*;
1414
use rustc_index::vec::Idx;
1515
use rustc_middle::hir::nested_filter;
1616
use rustc_span::def_id::StableCrateId;
17-
use rustc_span::source_map::Spanned;
1817
use rustc_span::symbol::{kw, sym, Ident, Symbol};
1918
use rustc_span::Span;
2019
use rustc_target::spec::abi::Abi;
@@ -304,7 +303,6 @@ impl<'hir> Map<'hir> {
304303
| Node::Param(_)
305304
| Node::Arm(_)
306305
| Node::Lifetime(_)
307-
| Node::Visibility(_)
308306
| Node::Block(_) => return None,
309307
};
310308
Some(def_kind)
@@ -1000,12 +998,7 @@ impl<'hir> Map<'hir> {
1000998
},
1001999
Node::Lifetime(lifetime) => lifetime.span,
10021000
Node::GenericParam(param) => param.span,
1003-
Node::Visibility(&Spanned {
1004-
node: VisibilityKind::Restricted { ref path, .. },
1005-
..
1006-
}) => path.span,
10071001
Node::Infer(i) => i.span,
1008-
Node::Visibility(v) => bug!("unexpected Visibility {:?}", v),
10091002
Node::Local(local) => local.span,
10101003
Node::Crate(item) => item.spans.inner_span,
10111004
};
@@ -1232,7 +1225,6 @@ fn hir_id_to_string(map: Map<'_>, id: HirId) -> String {
12321225
Some(Node::Ctor(..)) => format!("ctor {}{}", path_str(), id_str),
12331226
Some(Node::Lifetime(_)) => node_str("lifetime"),
12341227
Some(Node::GenericParam(ref param)) => format!("generic_param {:?}{}", param, id_str),
1235-
Some(Node::Visibility(ref vis)) => format!("visibility {:?}{}", vis, id_str),
12361228
Some(Node::Crate(..)) => String::from("root_crate"),
12371229
None => format!("unknown node{}", id_str),
12381230
}

compiler/rustc_privacy/src/lib.rs

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -295,28 +295,6 @@ fn min(vis1: ty::Visibility, vis2: ty::Visibility, tcx: TyCtxt<'_>) -> ty::Visib
295295
if vis1.is_at_least(vis2, tcx) { vis2 } else { vis1 }
296296
}
297297

298-
////////////////////////////////////////////////////////////////////////////////
299-
/// Visitor used to determine if pub(restricted) is used anywhere in the crate.
300-
///
301-
/// This is done so that `private_in_public` warnings can be turned into hard errors
302-
/// in crates that have been updated to use pub(restricted).
303-
////////////////////////////////////////////////////////////////////////////////
304-
struct PubRestrictedVisitor<'tcx> {
305-
tcx: TyCtxt<'tcx>,
306-
has_pub_restricted: bool,
307-
}
308-
309-
impl<'tcx> Visitor<'tcx> for PubRestrictedVisitor<'tcx> {
310-
type NestedFilter = nested_filter::All;
311-
312-
fn nested_visit_map(&mut self) -> Self::Map {
313-
self.tcx.hir()
314-
}
315-
fn visit_vis(&mut self, vis: &'tcx hir::Visibility<'tcx>) {
316-
self.has_pub_restricted = self.has_pub_restricted || vis.node.is_pub_restricted();
317-
}
318-
}
319-
320298
////////////////////////////////////////////////////////////////////////////////
321299
/// Visitor used to determine impl visibility and reachability.
322300
////////////////////////////////////////////////////////////////////////////////
@@ -2083,11 +2061,12 @@ fn check_private_in_public(tcx: TyCtxt<'_>, (): ()) {
20832061
};
20842062
tcx.hir().walk_toplevel_module(&mut visitor);
20852063

2086-
let has_pub_restricted = {
2087-
let mut pub_restricted_visitor = PubRestrictedVisitor { tcx, has_pub_restricted: false };
2088-
tcx.hir().walk_toplevel_module(&mut pub_restricted_visitor);
2089-
pub_restricted_visitor.has_pub_restricted
2090-
};
2064+
let has_pub_restricted = tcx.resolutions(()).visibilities.iter().any(|(&def_id, &v)| match v {
2065+
ty::Visibility::Public | ty::Visibility::Invisible => false,
2066+
ty::Visibility::Restricted(module) => {
2067+
module != tcx.parent_module_from_def_id(def_id).to_def_id()
2068+
}
2069+
});
20912070

20922071
let mut old_error_set_ancestry = HirIdSet::default();
20932072
for mut id in visitor.old_error_set.iter().copied() {

compiler/rustc_resolve/src/late/lifetimes.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -685,8 +685,8 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
685685
hir_id: hir::HirId,
686686
) {
687687
let name = match fk {
688-
intravisit::FnKind::ItemFn(id, _, _, _) => id.name,
689-
intravisit::FnKind::Method(id, _, _) => id.name,
688+
intravisit::FnKind::ItemFn(id, _, _) => id.name,
689+
intravisit::FnKind::Method(id, _) => id.name,
690690
intravisit::FnKind::Closure => sym::closure,
691691
};
692692
let name = name.as_str();

compiler/rustc_save_analysis/src/lib.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ use rustc_middle::{bug, span_bug};
2727
use rustc_session::config::{CrateType, Input, OutputType};
2828
use rustc_session::cstore::ExternCrate;
2929
use rustc_session::output::{filename_for_metadata, out_filename};
30-
use rustc_span::source_map::Spanned;
3130
use rustc_span::symbol::Ident;
3231
use rustc_span::*;
3332

@@ -595,11 +594,6 @@ impl<'tcx> SaveContext<'tcx> {
595594
Node::TraitRef(tr) => tr.path.res,
596595

597596
Node::Item(&hir::Item { kind: hir::ItemKind::Use(path, _), .. }) => path.res,
598-
Node::Visibility(&Spanned {
599-
node: hir::VisibilityKind::Restricted { ref path, .. },
600-
..
601-
}) => path.res,
602-
603597
Node::PathSegment(seg) => match seg.res {
604598
Some(res) if res != Res::Err => res,
605599
_ => {

compiler/rustc_typeck/src/check/generator_interior/drop_ranges/cfg_build.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,6 @@ impl<'a, 'tcx> DropRangeVisitor<'a, 'tcx> {
257257
| hir::Node::Ctor(..)
258258
| hir::Node::Lifetime(..)
259259
| hir::Node::GenericParam(..)
260-
| hir::Node::Visibility(..)
261260
| hir::Node::Crate(..)
262261
| hir::Node::Infer(..) => bug!("Unsupported branch target: {:?}", node),
263262
}

0 commit comments

Comments
 (0)