Add ty::Visibility::is_public()
This commit is contained in:
parent
8b09ba6a5d
commit
9a987b0466
@ -1179,7 +1179,7 @@ fn each_child_of_item(&self, id: DefIndex, mut callback: impl FnMut(Export), ses
|
||||
let ctor_res =
|
||||
Res::Def(DefKind::Ctor(CtorOf::Variant, ctor_kind), ctor_def_id);
|
||||
let mut vis = self.get_visibility(ctor_def_id.index);
|
||||
if ctor_def_id == def_id && vis == ty::Visibility::Public {
|
||||
if ctor_def_id == def_id && vis.is_public() {
|
||||
// For non-exhaustive variants lower the constructor visibility to
|
||||
// within the crate. We only need this for fictive constructors,
|
||||
// for other constructors correct visibilities
|
||||
|
@ -318,7 +318,7 @@ pub fn provide(providers: &mut Providers) {
|
||||
}
|
||||
|
||||
let mut add_child = |bfs_queue: &mut VecDeque<_>, child: &Export, parent: DefId| {
|
||||
if child.vis != ty::Visibility::Public {
|
||||
if !child.vis.is_public() {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -333,6 +333,10 @@ pub fn is_visible_locally(self) -> bool {
|
||||
Visibility::Invisible => false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_public(self) -> bool {
|
||||
matches!(self, Visibility::Public)
|
||||
}
|
||||
}
|
||||
|
||||
/// The crate variances map is computed during typeck and contains the
|
||||
|
@ -2404,7 +2404,7 @@ fn for_each_def(tcx: TyCtxt<'_>, mut collect_fn: impl for<'b> FnMut(&'b Ident, N
|
||||
// Iterate external crate defs but be mindful about visibility
|
||||
while let Some(def) = queue.pop() {
|
||||
for child in tcx.item_children(def).iter() {
|
||||
if child.vis != ty::Visibility::Public {
|
||||
if !child.vis.is_public() {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -543,7 +543,7 @@ fn update_macro_reachable_def(
|
||||
module: LocalDefId,
|
||||
) {
|
||||
let level = Some(AccessLevel::Reachable);
|
||||
if let ty::Visibility::Public = vis {
|
||||
if vis.is_public() {
|
||||
self.update(def_id, level);
|
||||
}
|
||||
match def_kind {
|
||||
@ -580,7 +580,7 @@ fn update_macro_reachable_def(
|
||||
|
||||
DefKind::Struct | DefKind::Union => {
|
||||
// While structs and unions have type privacy, their fields do not.
|
||||
if let ty::Visibility::Public = vis {
|
||||
if vis.is_public() {
|
||||
let item =
|
||||
self.tcx.hir().expect_item(self.tcx.hir().local_def_id_to_hir_id(def_id));
|
||||
if let hir::ItemKind::Struct(ref struct_def, _)
|
||||
@ -933,7 +933,7 @@ fn visit_mod(&mut self, m: &'tcx hir::Mod<'tcx>, _sp: Span, id: hir::HirId) {
|
||||
let def_id = self.tcx.hir().local_def_id(id);
|
||||
if let Some(exports) = self.tcx.module_exports(def_id) {
|
||||
for export in exports.iter() {
|
||||
if export.vis == ty::Visibility::Public {
|
||||
if export.vis.is_public() {
|
||||
if let Some(def_id) = export.res.opt_def_id() {
|
||||
if let Some(def_id) = def_id.as_local() {
|
||||
self.update(def_id, Some(AccessLevel::Exported));
|
||||
@ -1918,8 +1918,7 @@ fn check_def_id(&mut self, def_id: DefId, kind: &str, descr: &dyn fmt::Display)
|
||||
/// 1. It's contained within a public type
|
||||
/// 2. It comes from a private crate
|
||||
fn leaks_private_dep(&self, item_id: DefId) -> bool {
|
||||
let ret = self.required_visibility == ty::Visibility::Public
|
||||
&& self.tcx.is_private_dep(item_id.krate);
|
||||
let ret = self.required_visibility.is_public() && self.tcx.is_private_dep(item_id.krate);
|
||||
|
||||
tracing::debug!("leaks_private_dep(item_id={:?})={}", item_id, ret);
|
||||
ret
|
||||
|
@ -32,7 +32,6 @@
|
||||
use rustc_ast_lowering::ResolverAstLowering;
|
||||
use rustc_data_structures::fx::FxHashSet;
|
||||
use rustc_errors::pluralize;
|
||||
use rustc_middle::ty;
|
||||
use rustc_session::lint::builtin::{MACRO_USE_EXTERN_CRATE, UNUSED_IMPORTS};
|
||||
use rustc_session::lint::BuiltinLintDiagnostics;
|
||||
use rustc_span::{MultiSpan, Span, DUMMY_SP};
|
||||
@ -228,7 +227,7 @@ impl Resolver<'_> {
|
||||
for import in self.potentially_unused_imports.iter() {
|
||||
match import.kind {
|
||||
_ if import.used.get()
|
||||
|| import.vis.get() == ty::Visibility::Public
|
||||
|| import.vis.get().is_public()
|
||||
|| import.span.is_dummy() =>
|
||||
{
|
||||
if let ImportKind::MacroUse = import.kind {
|
||||
|
@ -11,7 +11,7 @@
|
||||
use rustc_hir::def_id::{DefId, CRATE_DEF_INDEX, LOCAL_CRATE};
|
||||
use rustc_hir::PrimTy;
|
||||
use rustc_middle::bug;
|
||||
use rustc_middle::ty::{self, DefIdTree};
|
||||
use rustc_middle::ty::DefIdTree;
|
||||
use rustc_session::Session;
|
||||
use rustc_span::hygiene::MacroKind;
|
||||
use rustc_span::lev_distance::find_best_match_for_name;
|
||||
@ -1308,7 +1308,7 @@ fn ctor_fields_span(&self, binding: &NameBinding<'_>) -> Option<Span> {
|
||||
);
|
||||
let def_span = self.session.source_map().guess_head_span(binding.span);
|
||||
let mut note_span = MultiSpan::from_span(def_span);
|
||||
if !first && binding.vis == ty::Visibility::Public {
|
||||
if !first && binding.vis.is_public() {
|
||||
note_span.push_span_label(def_span, "consider importing it directly".into());
|
||||
}
|
||||
err.span_note(note_span, &msg);
|
||||
|
@ -164,7 +164,7 @@ fn pub_use_of_private_extern_crate_hack(import: &Import<'_>, binding: &NameBindi
|
||||
import: Import { kind: ImportKind::ExternCrate { .. }, .. },
|
||||
..
|
||||
},
|
||||
) => import.vis.get() == ty::Visibility::Public,
|
||||
) => import.vis.get().is_public(),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
@ -35,14 +35,11 @@
|
||||
use rustc_infer::infer;
|
||||
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
|
||||
use rustc_infer::infer::InferOk;
|
||||
use rustc_middle::ty;
|
||||
use rustc_middle::ty::adjustment::{Adjust, Adjustment, AllowTwoPhase};
|
||||
use rustc_middle::ty::error::TypeError::{FieldMisMatch, Sorts};
|
||||
use rustc_middle::ty::relate::expected_found_bool;
|
||||
use rustc_middle::ty::subst::SubstsRef;
|
||||
use rustc_middle::ty::Ty;
|
||||
use rustc_middle::ty::TypeFoldable;
|
||||
use rustc_middle::ty::{AdtKind, Visibility};
|
||||
use rustc_middle::ty::{self, AdtKind, Ty, TypeFoldable};
|
||||
use rustc_session::parse::feature_err;
|
||||
use rustc_span::edition::LATEST_STABLE_EDITION;
|
||||
use rustc_span::hygiene::DesugaringKind;
|
||||
@ -1732,7 +1729,7 @@ fn suggest_field_name(
|
||||
.filter_map(|field| {
|
||||
// ignore already set fields and private fields from non-local crates
|
||||
if skip.iter().any(|&x| x == field.ident.name)
|
||||
|| (!variant.def_id.is_local() && field.vis != Visibility::Public)
|
||||
|| (!variant.def_id.is_local() && !field.vis.is_public())
|
||||
{
|
||||
None
|
||||
} else {
|
||||
|
@ -1410,7 +1410,7 @@ fn suggest_traits_to_import(
|
||||
}
|
||||
}
|
||||
// We only want to suggest public or local traits (#45781).
|
||||
item.vis == ty::Visibility::Public || info.def_id.is_local()
|
||||
item.vis.is_public() || info.def_id.is_local()
|
||||
})
|
||||
.is_some()
|
||||
})
|
||||
|
@ -435,7 +435,7 @@ fn merge_attrs(
|
||||
tcx.associated_items(did)
|
||||
.in_definition_order()
|
||||
.filter_map(|item| {
|
||||
if associated_trait.is_some() || item.vis == ty::Visibility::Public {
|
||||
if associated_trait.is_some() || item.vis.is_public() {
|
||||
Some(item.clean(cx))
|
||||
} else {
|
||||
None
|
||||
@ -515,7 +515,7 @@ fn build_module(
|
||||
// two namespaces, so the target may be listed twice. Make sure we only
|
||||
// visit each node at most once.
|
||||
for &item in cx.tcx.item_children(did).iter() {
|
||||
if item.vis == ty::Visibility::Public {
|
||||
if item.vis.is_public() {
|
||||
let res = item.res.expect_non_local();
|
||||
if let Some(def_id) = res.mod_def_id() {
|
||||
if did == def_id || !visited.insert(def_id) {
|
||||
|
@ -2,7 +2,7 @@
|
||||
use rustc_hir::def::{DefKind, Res};
|
||||
use rustc_hir::def_id::{CrateNum, DefId, CRATE_DEF_INDEX};
|
||||
use rustc_middle::middle::privacy::{AccessLevel, AccessLevels};
|
||||
use rustc_middle::ty::{TyCtxt, Visibility};
|
||||
use rustc_middle::ty::TyCtxt;
|
||||
use rustc_span::symbol::sym;
|
||||
|
||||
use crate::clean::{AttributesExt, NestedAttributesExt};
|
||||
@ -59,7 +59,7 @@ fn update(&mut self, did: DefId, level: Option<AccessLevel>) -> Option<AccessLev
|
||||
for item in self.tcx.item_children(def_id).iter() {
|
||||
if let Some(def_id) = item.res.opt_def_id() {
|
||||
if self.tcx.def_key(def_id).parent.map_or(false, |d| d == def_id.index)
|
||||
|| item.vis == Visibility::Public
|
||||
|| item.vis.is_public()
|
||||
{
|
||||
self.visit_item(item.res);
|
||||
}
|
||||
@ -70,7 +70,7 @@ fn update(&mut self, did: DefId, level: Option<AccessLevel>) -> Option<AccessLev
|
||||
fn visit_item(&mut self, res: Res<!>) {
|
||||
let def_id = res.def_id();
|
||||
let vis = self.tcx.visibility(def_id);
|
||||
let inherited_item_level = if vis == Visibility::Public { self.prev_level } else { None };
|
||||
let inherited_item_level = if vis.is_public() { self.prev_level } else { None };
|
||||
|
||||
let item_level = self.update(def_id, inherited_item_level);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user