Drop vis in ImplItem.
This commit is contained in:
parent
2827007d32
commit
a6e3124d2c
@ -1016,8 +1016,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||
def_id: hir_id.expect_owner(),
|
||||
ident: self.lower_ident(i.ident),
|
||||
generics,
|
||||
vis: self.lower_visibility(&i.vis),
|
||||
kind,
|
||||
vis_span: self.lower_span(i.vis.span),
|
||||
span: self.lower_span(i.span),
|
||||
};
|
||||
self.arena.alloc(item)
|
||||
|
@ -2140,10 +2140,10 @@ impl ImplItemId {
|
||||
pub struct ImplItem<'hir> {
|
||||
pub ident: Ident,
|
||||
pub def_id: LocalDefId,
|
||||
pub vis: Visibility<'hir>,
|
||||
pub generics: Generics<'hir>,
|
||||
pub kind: ImplItemKind<'hir>,
|
||||
pub span: Span,
|
||||
pub vis_span: Span,
|
||||
}
|
||||
|
||||
impl ImplItem<'_> {
|
||||
@ -3350,6 +3350,6 @@ mod size_asserts {
|
||||
|
||||
rustc_data_structures::static_assert_size!(super::Item<'static>, 184);
|
||||
rustc_data_structures::static_assert_size!(super::TraitItem<'static>, 128);
|
||||
rustc_data_structures::static_assert_size!(super::ImplItem<'static>, 144);
|
||||
rustc_data_structures::static_assert_size!(super::ImplItem<'static>, 120);
|
||||
rustc_data_structures::static_assert_size!(super::ForeignItem<'static>, 112);
|
||||
}
|
||||
|
@ -1020,7 +1020,7 @@ pub fn walk_trait_item_ref<'v, V: Visitor<'v>>(visitor: &mut V, trait_item_ref:
|
||||
|
||||
pub fn walk_impl_item<'v, V: Visitor<'v>>(visitor: &mut V, impl_item: &'v ImplItem<'v>) {
|
||||
// N.B., deliberately force a compilation error if/when new fields are added.
|
||||
let ImplItem { def_id: _, ident, ref generics, ref kind, span: _, vis: _ } = *impl_item;
|
||||
let ImplItem { def_id: _, ident, ref generics, ref kind, span: _, vis_span: _ } = *impl_item;
|
||||
|
||||
visitor.visit_ident(ident);
|
||||
visitor.visit_generics(generics);
|
||||
|
@ -1439,7 +1439,7 @@ impl<'tcx> LateLintPass<'tcx> for UnreachablePub {
|
||||
|
||||
fn check_impl_item(&mut self, cx: &LateContext<'_>, impl_item: &hir::ImplItem<'_>) {
|
||||
if cx.tcx.visibility(impl_item.def_id).is_public() {
|
||||
self.perform_lint(cx, "item", impl_item.def_id, impl_item.vis.span, false);
|
||||
self.perform_lint(cx, "item", impl_item.def_id, impl_item.vis_span, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1363,8 +1363,8 @@ impl<'a, 'tcx> ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
fn item_is_public(&self, def_id: LocalDefId, vis: &hir::Visibility<'_>) -> bool {
|
||||
self.access_levels.is_reachable(def_id) || vis.node.is_pub()
|
||||
fn item_is_public(&self, def_id: LocalDefId) -> bool {
|
||||
self.access_levels.is_reachable(def_id) || self.tcx.visibility(def_id).is_public()
|
||||
}
|
||||
}
|
||||
|
||||
@ -1499,8 +1499,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> {
|
||||
let impl_item = self.tcx.hir().impl_item(impl_item_ref.id);
|
||||
match impl_item.kind {
|
||||
hir::ImplItemKind::Const(..) | hir::ImplItemKind::Fn(..)
|
||||
if self
|
||||
.item_is_public(impl_item.def_id, &impl_item.vis) =>
|
||||
if self.item_is_public(impl_item.def_id) =>
|
||||
{
|
||||
intravisit::walk_impl_item(self, impl_item)
|
||||
}
|
||||
@ -1571,7 +1570,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> {
|
||||
hir::ItemKind::TyAlias(..) => return,
|
||||
|
||||
// Not at all public, so we don't care.
|
||||
_ if !self.item_is_public(item.def_id, &item.vis) => {
|
||||
_ if !self.item_is_public(item.def_id) => {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,6 @@ use rustc_middle::hir::nested_filter;
|
||||
use rustc_middle::span_bug;
|
||||
use rustc_middle::ty::{self, DefIdTree, TyCtxt};
|
||||
use rustc_session::config::Input;
|
||||
use rustc_span::source_map::respan;
|
||||
use rustc_span::symbol::Ident;
|
||||
use rustc_span::*;
|
||||
|
||||
@ -65,12 +64,6 @@ macro_rules! access_from {
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! access_from_vis {
|
||||
($save_ctxt:expr, $vis:expr, $id:expr) => {
|
||||
Access { public: $vis.node.is_pub(), reachable: $save_ctxt.access_levels.is_reachable($id) }
|
||||
};
|
||||
}
|
||||
|
||||
pub struct DumpVisitor<'tcx> {
|
||||
pub save_ctxt: SaveContext<'tcx>,
|
||||
tcx: TyCtxt<'tcx>,
|
||||
@ -257,7 +250,6 @@ impl<'tcx> DumpVisitor<'tcx> {
|
||||
def_id: LocalDefId,
|
||||
ident: Ident,
|
||||
generics: &'tcx hir::Generics<'tcx>,
|
||||
vis: &hir::Visibility<'tcx>,
|
||||
span: Span,
|
||||
) {
|
||||
debug!("process_method: {:?}:{}", def_id, ident);
|
||||
@ -275,7 +267,7 @@ impl<'tcx> DumpVisitor<'tcx> {
|
||||
fn_to_string(sig.decl, sig.header, Some(ident.name), generics, &[], None);
|
||||
method_data.sig = sig::method_signature(hir_id, ident, generics, sig, &v.save_ctxt);
|
||||
|
||||
v.dumper.dump_def(&access_from_vis!(v.save_ctxt, vis, def_id), method_data);
|
||||
v.dumper.dump_def(&access_from!(v.save_ctxt, def_id), method_data);
|
||||
}
|
||||
|
||||
// walk arg and return types
|
||||
@ -407,7 +399,6 @@ impl<'tcx> DumpVisitor<'tcx> {
|
||||
typ: &'tcx hir::Ty<'tcx>,
|
||||
expr: Option<&'tcx hir::Expr<'tcx>>,
|
||||
parent_id: DefId,
|
||||
vis: &hir::Visibility<'tcx>,
|
||||
attrs: &'tcx [ast::Attribute],
|
||||
) {
|
||||
let qualname = format!("::{}", self.tcx.def_path_str(def_id.to_def_id()));
|
||||
@ -418,7 +409,7 @@ impl<'tcx> DumpVisitor<'tcx> {
|
||||
let span = self.span_from_span(ident.span);
|
||||
|
||||
self.dumper.dump_def(
|
||||
&access_from_vis!(self.save_ctxt, vis, def_id),
|
||||
&access_from!(self.save_ctxt, def_id),
|
||||
Def {
|
||||
kind: DefKind::Const,
|
||||
id: id_from_hir_id(hir_id, &self.save_ctxt),
|
||||
@ -983,11 +974,9 @@ impl<'tcx> DumpVisitor<'tcx> {
|
||||
|
||||
fn process_trait_item(&mut self, trait_item: &'tcx hir::TraitItem<'tcx>, trait_id: DefId) {
|
||||
self.process_macro_use(trait_item.span);
|
||||
let vis_span = trait_item.span.shrink_to_lo();
|
||||
match trait_item.kind {
|
||||
hir::TraitItemKind::Const(ref ty, body) => {
|
||||
let body = body.map(|b| &self.tcx.hir().body(b).value);
|
||||
let respan = respan(vis_span, hir::VisibilityKind::Public);
|
||||
let attrs = self.tcx.hir().attrs(trait_item.hir_id());
|
||||
self.process_assoc_const(
|
||||
trait_item.def_id,
|
||||
@ -995,21 +984,18 @@ impl<'tcx> DumpVisitor<'tcx> {
|
||||
&ty,
|
||||
body,
|
||||
trait_id,
|
||||
&respan,
|
||||
attrs,
|
||||
);
|
||||
}
|
||||
hir::TraitItemKind::Fn(ref sig, ref trait_fn) => {
|
||||
let body =
|
||||
if let hir::TraitFn::Provided(body) = trait_fn { Some(*body) } else { None };
|
||||
let respan = respan(vis_span, hir::VisibilityKind::Public);
|
||||
self.process_method(
|
||||
sig,
|
||||
body,
|
||||
trait_item.def_id,
|
||||
trait_item.ident,
|
||||
&trait_item.generics,
|
||||
&respan,
|
||||
trait_item.span,
|
||||
);
|
||||
}
|
||||
@ -1068,7 +1054,6 @@ impl<'tcx> DumpVisitor<'tcx> {
|
||||
&ty,
|
||||
Some(&body.value),
|
||||
impl_id,
|
||||
&impl_item.vis,
|
||||
attrs,
|
||||
);
|
||||
}
|
||||
@ -1079,7 +1064,6 @@ impl<'tcx> DumpVisitor<'tcx> {
|
||||
impl_item.def_id,
|
||||
impl_item.ident,
|
||||
&impl_item.generics,
|
||||
&impl_item.vis,
|
||||
impl_item.span,
|
||||
);
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ use clippy_utils::get_attr;
|
||||
use rustc_ast::ast::{Attribute, InlineAsmTemplatePiece};
|
||||
use rustc_hir as hir;
|
||||
use rustc_lint::{LateContext, LateLintPass, LintContext};
|
||||
use rustc_middle::ty;
|
||||
use rustc_session::Session;
|
||||
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
||||
|
||||
@ -45,14 +46,10 @@ impl<'tcx> LateLintPass<'tcx> for DeepCodeInspector {
|
||||
return;
|
||||
}
|
||||
println!("impl item `{}`", item.ident.name);
|
||||
match item.vis.node {
|
||||
hir::VisibilityKind::Public => println!("public"),
|
||||
hir::VisibilityKind::Crate(_) => println!("visible crate wide"),
|
||||
hir::VisibilityKind::Restricted { path, .. } => println!(
|
||||
"visible in module `{}`",
|
||||
rustc_hir_pretty::to_string(rustc_hir_pretty::NO_ANN, |s| s.print_path(path, false))
|
||||
),
|
||||
hir::VisibilityKind::Inherited => println!("visibility inherited from outer item"),
|
||||
match cx.tcx.visibility(item.def_id) {
|
||||
ty::Visibility::Public => println!("public"),
|
||||
ty::Visibility::Restricted(def_id) => println!("visible in module `{}`", cx.tcx.def_path_str(def_id)),
|
||||
ty::Visibility::Invisible => println!("invisible"),
|
||||
}
|
||||
match item.kind {
|
||||
hir::ImplItemKind::Const(_, body_id) => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user