Skip to content

Commit 04024ba

Browse files
committed
Drop vis in Item.
1 parent 6ec33df commit 04024ba

File tree

4 files changed

+13
-13
lines changed

4 files changed

+13
-13
lines changed

clippy_lints/src/enum_variants.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ impl LateLintPass<'_> for EnumVariantNames {
260260
}
261261
// The `module_name_repetitions` lint should only trigger if the item has the module in its
262262
// name. Having the same name is accepted.
263-
if item.vis.node.is_pub() && item_camel.len() > mod_camel.len() {
263+
if cx.tcx.visibility(item.def_id).is_public() && item_camel.len() > mod_camel.len() {
264264
let matching = count_match_start(mod_camel, &item_camel);
265265
let rmatching = count_match_end(mod_camel, &item_camel);
266266
let nchars = mod_camel.chars().count();

clippy_lints/src/redundant_pub_crate.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
use clippy_utils::diagnostics::span_lint_and_then;
22
use rustc_errors::Applicability;
3-
use rustc_hir::{Item, ItemKind, VisibilityKind};
3+
use rustc_hir::{Item, ItemKind};
44
use rustc_lint::{LateContext, LateLintPass};
5+
use rustc_middle::ty;
56
use rustc_session::{declare_tool_lint, impl_lint_pass};
7+
use rustc_span::def_id::CRATE_DEF_ID;
68

79
declare_clippy_lint! {
810
/// ### What it does
@@ -41,7 +43,7 @@ impl_lint_pass!(RedundantPubCrate => [REDUNDANT_PUB_CRATE]);
4143

4244
impl<'tcx> LateLintPass<'tcx> for RedundantPubCrate {
4345
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'tcx>) {
44-
if let VisibilityKind::Crate { .. } = item.vis.node {
46+
if cx.tcx.visibility(item.def_id) == ty::Visibility::Restricted(CRATE_DEF_ID.to_def_id()) {
4547
if !cx.access_levels.is_exported(item.def_id) && self.is_exported.last() == Some(&false) {
4648
let span = item.span.with_hi(item.ident.span.hi());
4749
let descr = cx.tcx.def_kind(item.def_id).descr(item.def_id.to_def_id());
@@ -52,7 +54,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantPubCrate {
5254
&format!("pub(crate) {} inside private module", descr),
5355
|diag| {
5456
diag.span_suggestion(
55-
item.vis.span,
57+
item.vis_span,
5658
"consider using",
5759
"pub".to_string(),
5860
Applicability::MachineApplicable,

clippy_lints/src/utils/inspector.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -357,14 +357,10 @@ fn print_expr(cx: &LateContext<'_>, expr: &hir::Expr<'_>, indent: usize) {
357357
fn print_item(cx: &LateContext<'_>, item: &hir::Item<'_>) {
358358
let did = item.def_id;
359359
println!("item `{}`", item.ident.name);
360-
match item.vis.node {
361-
hir::VisibilityKind::Public => println!("public"),
362-
hir::VisibilityKind::Crate(_) => println!("visible crate wide"),
363-
hir::VisibilityKind::Restricted { path, .. } => println!(
364-
"visible in module `{}`",
365-
rustc_hir_pretty::to_string(rustc_hir_pretty::NO_ANN, |s| s.print_path(path, false))
366-
),
367-
hir::VisibilityKind::Inherited => println!("visibility inherited from outer item"),
360+
match cx.tcx.visibility(item.def_id) {
361+
ty::Visibility::Public => println!("public"),
362+
ty::Visibility::Restricted(def_id) => println!("visible in module `{}`", cx.tcx.def_path_str(def_id)),
363+
ty::Visibility::Invisible => println!("invisible"),
368364
}
369365
match item.kind {
370366
hir::ItemKind::ExternCrate(ref _renamed_from) => {

clippy_lints/src/wildcard_imports.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use rustc_hir::{
88
Item, ItemKind, PathSegment, UseKind,
99
};
1010
use rustc_lint::{LateContext, LateLintPass};
11+
use rustc_middle::ty;
1112
use rustc_session::{declare_tool_lint, impl_lint_pass};
1213
use rustc_span::symbol::kw;
1314
use rustc_span::{sym, BytePos};
@@ -115,7 +116,8 @@ impl LateLintPass<'_> for WildcardImports {
115116
if is_test_module_or_function(cx.tcx, item) {
116117
self.test_modules_deep = self.test_modules_deep.saturating_add(1);
117118
}
118-
if item.vis.node.is_pub() || item.vis.node.is_pub_restricted() {
119+
let module = cx.tcx.parent_module_from_def_id(item.def_id);
120+
if cx.tcx.visibility(item.def_id) != ty::Visibility::Restricted(module.to_def_id()) {
119121
return;
120122
}
121123
if_chain! {

0 commit comments

Comments
 (0)