Skip to content

Commit a6e3124

Browse files
committed
Drop vis in ImplItem.
1 parent 2827007 commit a6e3124

File tree

7 files changed

+16
-36
lines changed

7 files changed

+16
-36
lines changed

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1016,8 +1016,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
10161016
def_id: hir_id.expect_owner(),
10171017
ident: self.lower_ident(i.ident),
10181018
generics,
1019-
vis: self.lower_visibility(&i.vis),
10201019
kind,
1020+
vis_span: self.lower_span(i.vis.span),
10211021
span: self.lower_span(i.span),
10221022
};
10231023
self.arena.alloc(item)

compiler/rustc_hir/src/hir.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2140,10 +2140,10 @@ impl ImplItemId {
21402140
pub struct ImplItem<'hir> {
21412141
pub ident: Ident,
21422142
pub def_id: LocalDefId,
2143-
pub vis: Visibility<'hir>,
21442143
pub generics: Generics<'hir>,
21452144
pub kind: ImplItemKind<'hir>,
21462145
pub span: Span,
2146+
pub vis_span: Span,
21472147
}
21482148

21492149
impl ImplItem<'_> {
@@ -3350,6 +3350,6 @@ mod size_asserts {
33503350

33513351
rustc_data_structures::static_assert_size!(super::Item<'static>, 184);
33523352
rustc_data_structures::static_assert_size!(super::TraitItem<'static>, 128);
3353-
rustc_data_structures::static_assert_size!(super::ImplItem<'static>, 144);
3353+
rustc_data_structures::static_assert_size!(super::ImplItem<'static>, 120);
33543354
rustc_data_structures::static_assert_size!(super::ForeignItem<'static>, 112);
33553355
}

compiler/rustc_hir/src/intravisit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1020,7 +1020,7 @@ pub fn walk_trait_item_ref<'v, V: Visitor<'v>>(visitor: &mut V, trait_item_ref:
10201020

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

10251025
visitor.visit_ident(ident);
10261026
visitor.visit_generics(generics);

compiler/rustc_lint/src/builtin.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1439,7 +1439,7 @@ impl<'tcx> LateLintPass<'tcx> for UnreachablePub {
14391439

14401440
fn check_impl_item(&mut self, cx: &LateContext<'_>, impl_item: &hir::ImplItem<'_>) {
14411441
if cx.tcx.visibility(impl_item.def_id).is_public() {
1442-
self.perform_lint(cx, "item", impl_item.def_id, impl_item.vis.span, false);
1442+
self.perform_lint(cx, "item", impl_item.def_id, impl_item.vis_span, false);
14431443
}
14441444
}
14451445
}

compiler/rustc_privacy/src/lib.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1363,8 +1363,8 @@ impl<'a, 'tcx> ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> {
13631363
}
13641364
}
13651365

1366-
fn item_is_public(&self, def_id: LocalDefId, vis: &hir::Visibility<'_>) -> bool {
1367-
self.access_levels.is_reachable(def_id) || vis.node.is_pub()
1366+
fn item_is_public(&self, def_id: LocalDefId) -> bool {
1367+
self.access_levels.is_reachable(def_id) || self.tcx.visibility(def_id).is_public()
13681368
}
13691369
}
13701370

@@ -1499,8 +1499,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> {
14991499
let impl_item = self.tcx.hir().impl_item(impl_item_ref.id);
15001500
match impl_item.kind {
15011501
hir::ImplItemKind::Const(..) | hir::ImplItemKind::Fn(..)
1502-
if self
1503-
.item_is_public(impl_item.def_id, &impl_item.vis) =>
1502+
if self.item_is_public(impl_item.def_id) =>
15041503
{
15051504
intravisit::walk_impl_item(self, impl_item)
15061505
}
@@ -1571,7 +1570,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> {
15711570
hir::ItemKind::TyAlias(..) => return,
15721571

15731572
// Not at all public, so we don't care.
1574-
_ if !self.item_is_public(item.def_id, &item.vis) => {
1573+
_ if !self.item_is_public(item.def_id) => {
15751574
return;
15761575
}
15771576

compiler/rustc_save_analysis/src/dump_visitor.rs

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ use rustc_middle::hir::nested_filter;
2525
use rustc_middle::span_bug;
2626
use rustc_middle::ty::{self, DefIdTree, TyCtxt};
2727
use rustc_session::config::Input;
28-
use rustc_span::source_map::respan;
2928
use rustc_span::symbol::Ident;
3029
use rustc_span::*;
3130

@@ -65,12 +64,6 @@ macro_rules! access_from {
6564
};
6665
}
6766

68-
macro_rules! access_from_vis {
69-
($save_ctxt:expr, $vis:expr, $id:expr) => {
70-
Access { public: $vis.node.is_pub(), reachable: $save_ctxt.access_levels.is_reachable($id) }
71-
};
72-
}
73-
7467
pub struct DumpVisitor<'tcx> {
7568
pub save_ctxt: SaveContext<'tcx>,
7669
tcx: TyCtxt<'tcx>,
@@ -257,7 +250,6 @@ impl<'tcx> DumpVisitor<'tcx> {
257250
def_id: LocalDefId,
258251
ident: Ident,
259252
generics: &'tcx hir::Generics<'tcx>,
260-
vis: &hir::Visibility<'tcx>,
261253
span: Span,
262254
) {
263255
debug!("process_method: {:?}:{}", def_id, ident);
@@ -275,7 +267,7 @@ impl<'tcx> DumpVisitor<'tcx> {
275267
fn_to_string(sig.decl, sig.header, Some(ident.name), generics, &[], None);
276268
method_data.sig = sig::method_signature(hir_id, ident, generics, sig, &v.save_ctxt);
277269

278-
v.dumper.dump_def(&access_from_vis!(v.save_ctxt, vis, def_id), method_data);
270+
v.dumper.dump_def(&access_from!(v.save_ctxt, def_id), method_data);
279271
}
280272

281273
// walk arg and return types
@@ -407,7 +399,6 @@ impl<'tcx> DumpVisitor<'tcx> {
407399
typ: &'tcx hir::Ty<'tcx>,
408400
expr: Option<&'tcx hir::Expr<'tcx>>,
409401
parent_id: DefId,
410-
vis: &hir::Visibility<'tcx>,
411402
attrs: &'tcx [ast::Attribute],
412403
) {
413404
let qualname = format!("::{}", self.tcx.def_path_str(def_id.to_def_id()));
@@ -418,7 +409,7 @@ impl<'tcx> DumpVisitor<'tcx> {
418409
let span = self.span_from_span(ident.span);
419410

420411
self.dumper.dump_def(
421-
&access_from_vis!(self.save_ctxt, vis, def_id),
412+
&access_from!(self.save_ctxt, def_id),
422413
Def {
423414
kind: DefKind::Const,
424415
id: id_from_hir_id(hir_id, &self.save_ctxt),
@@ -983,33 +974,28 @@ impl<'tcx> DumpVisitor<'tcx> {
983974

984975
fn process_trait_item(&mut self, trait_item: &'tcx hir::TraitItem<'tcx>, trait_id: DefId) {
985976
self.process_macro_use(trait_item.span);
986-
let vis_span = trait_item.span.shrink_to_lo();
987977
match trait_item.kind {
988978
hir::TraitItemKind::Const(ref ty, body) => {
989979
let body = body.map(|b| &self.tcx.hir().body(b).value);
990-
let respan = respan(vis_span, hir::VisibilityKind::Public);
991980
let attrs = self.tcx.hir().attrs(trait_item.hir_id());
992981
self.process_assoc_const(
993982
trait_item.def_id,
994983
trait_item.ident,
995984
&ty,
996985
body,
997986
trait_id,
998-
&respan,
999987
attrs,
1000988
);
1001989
}
1002990
hir::TraitItemKind::Fn(ref sig, ref trait_fn) => {
1003991
let body =
1004992
if let hir::TraitFn::Provided(body) = trait_fn { Some(*body) } else { None };
1005-
let respan = respan(vis_span, hir::VisibilityKind::Public);
1006993
self.process_method(
1007994
sig,
1008995
body,
1009996
trait_item.def_id,
1010997
trait_item.ident,
1011998
&trait_item.generics,
1012-
&respan,
1013999
trait_item.span,
10141000
);
10151001
}
@@ -1068,7 +1054,6 @@ impl<'tcx> DumpVisitor<'tcx> {
10681054
&ty,
10691055
Some(&body.value),
10701056
impl_id,
1071-
&impl_item.vis,
10721057
attrs,
10731058
);
10741059
}
@@ -1079,7 +1064,6 @@ impl<'tcx> DumpVisitor<'tcx> {
10791064
impl_item.def_id,
10801065
impl_item.ident,
10811066
&impl_item.generics,
1082-
&impl_item.vis,
10831067
impl_item.span,
10841068
);
10851069
}

src/tools/clippy/clippy_lints/src/utils/inspector.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use clippy_utils::get_attr;
44
use rustc_ast::ast::{Attribute, InlineAsmTemplatePiece};
55
use rustc_hir as hir;
66
use rustc_lint::{LateContext, LateLintPass, LintContext};
7+
use rustc_middle::ty;
78
use rustc_session::Session;
89
use rustc_session::{declare_lint_pass, declare_tool_lint};
910

@@ -45,14 +46,10 @@ impl<'tcx> LateLintPass<'tcx> for DeepCodeInspector {
4546
return;
4647
}
4748
println!("impl item `{}`", item.ident.name);
48-
match item.vis.node {
49-
hir::VisibilityKind::Public => println!("public"),
50-
hir::VisibilityKind::Crate(_) => println!("visible crate wide"),
51-
hir::VisibilityKind::Restricted { path, .. } => println!(
52-
"visible in module `{}`",
53-
rustc_hir_pretty::to_string(rustc_hir_pretty::NO_ANN, |s| s.print_path(path, false))
54-
),
55-
hir::VisibilityKind::Inherited => println!("visibility inherited from outer item"),
49+
match cx.tcx.visibility(item.def_id) {
50+
ty::Visibility::Public => println!("public"),
51+
ty::Visibility::Restricted(def_id) => println!("visible in module `{}`", cx.tcx.def_path_str(def_id)),
52+
ty::Visibility::Invisible => println!("invisible"),
5653
}
5754
match item.kind {
5855
hir::ImplItemKind::Const(_, body_id) => {

0 commit comments

Comments
 (0)