privacy: Rename "accessibility levels" to "effective visibilities"
And a couple of other naming tweaks Related to https://github.com/rust-lang/rust/issues/48054
This commit is contained in:
parent
629a414d7b
commit
34eb73c72d
53 changed files with 524 additions and 516 deletions
|
@ -11,7 +11,7 @@ use rustc_hir::def_id::{DefId, LocalDefId};
|
|||
use rustc_hir::intravisit::{self, Visitor};
|
||||
use rustc_hir::{Node, PatKind, TyKind};
|
||||
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
|
||||
use rustc_middle::middle::privacy::AccessLevel;
|
||||
use rustc_middle::middle::privacy::Level;
|
||||
use rustc_middle::ty::query::Providers;
|
||||
use rustc_middle::ty::{self, DefIdTree, TyCtxt};
|
||||
use rustc_session::lint;
|
||||
|
@ -604,13 +604,13 @@ fn check_foreign_item<'tcx>(
|
|||
fn create_and_seed_worklist<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
) -> (Vec<LocalDefId>, FxHashMap<LocalDefId, LocalDefId>) {
|
||||
let access_levels = &tcx.privacy_access_levels(());
|
||||
let effective_visibilities = &tcx.effective_visibilities(());
|
||||
// see `MarkSymbolVisitor::struct_constructors`
|
||||
let mut struct_constructors = Default::default();
|
||||
let mut worklist = access_levels
|
||||
let mut worklist = effective_visibilities
|
||||
.iter()
|
||||
.filter_map(|(&id, effective_vis)| {
|
||||
effective_vis.is_public_at_level(AccessLevel::Reachable).then_some(id)
|
||||
effective_vis.is_public_at_level(Level::Reachable).then_some(id)
|
||||
})
|
||||
// Seed entry point
|
||||
.chain(tcx.entry_fn(()).and_then(|(def_id, _)| def_id.as_local()))
|
||||
|
|
|
@ -12,7 +12,7 @@ use rustc_hir::def_id::{DefId, LocalDefId};
|
|||
use rustc_hir::intravisit::{self, Visitor};
|
||||
use rustc_hir::Node;
|
||||
use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs};
|
||||
use rustc_middle::middle::privacy::{self, AccessLevel};
|
||||
use rustc_middle::middle::privacy::{self, Level};
|
||||
use rustc_middle::ty::query::Providers;
|
||||
use rustc_middle::ty::{self, DefIdTree, TyCtxt};
|
||||
use rustc_session::config::CrateType;
|
||||
|
@ -303,7 +303,7 @@ fn check_item<'tcx>(
|
|||
tcx: TyCtxt<'tcx>,
|
||||
id: hir::ItemId,
|
||||
worklist: &mut Vec<LocalDefId>,
|
||||
access_levels: &privacy::AccessLevels,
|
||||
effective_visibilities: &privacy::EffectiveVisibilities,
|
||||
) {
|
||||
if has_custom_linkage(tcx, id.def_id.def_id) {
|
||||
worklist.push(id.def_id.def_id);
|
||||
|
@ -318,7 +318,7 @@ fn check_item<'tcx>(
|
|||
if let hir::ItemKind::Impl(hir::Impl { of_trait: Some(ref trait_ref), ref items, .. }) =
|
||||
item.kind
|
||||
{
|
||||
if !access_levels.is_reachable(item.def_id.def_id) {
|
||||
if !effective_visibilities.is_reachable(item.def_id.def_id) {
|
||||
worklist.extend(items.iter().map(|ii_ref| ii_ref.id.def_id.def_id));
|
||||
|
||||
let Res::Def(DefKind::Trait, trait_def_id) = trait_ref.path.res else {
|
||||
|
@ -354,7 +354,7 @@ fn has_custom_linkage<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> bool {
|
|||
}
|
||||
|
||||
fn reachable_set<'tcx>(tcx: TyCtxt<'tcx>, (): ()) -> FxHashSet<LocalDefId> {
|
||||
let access_levels = &tcx.privacy_access_levels(());
|
||||
let effective_visibilities = &tcx.effective_visibilities(());
|
||||
|
||||
let any_library =
|
||||
tcx.sess.crate_types().iter().any(|ty| {
|
||||
|
@ -373,10 +373,10 @@ fn reachable_set<'tcx>(tcx: TyCtxt<'tcx>, (): ()) -> FxHashSet<LocalDefId> {
|
|||
// If other crates link to us, they're going to expect to be able to
|
||||
// use the lang items, so we need to be sure to mark them as
|
||||
// exported.
|
||||
reachable_context.worklist = access_levels
|
||||
reachable_context.worklist = effective_visibilities
|
||||
.iter()
|
||||
.filter_map(|(&id, effective_vis)| {
|
||||
effective_vis.is_public_at_level(AccessLevel::ReachableFromImplTrait).then_some(id)
|
||||
effective_vis.is_public_at_level(Level::ReachableThroughImplTrait).then_some(id)
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
|
@ -399,7 +399,7 @@ fn reachable_set<'tcx>(tcx: TyCtxt<'tcx>, (): ()) -> FxHashSet<LocalDefId> {
|
|||
let crate_items = tcx.hir_crate_items(());
|
||||
|
||||
for id in crate_items.items() {
|
||||
check_item(tcx, id, &mut reachable_context.worklist, access_levels);
|
||||
check_item(tcx, id, &mut reachable_context.worklist, effective_visibilities);
|
||||
}
|
||||
|
||||
for id in crate_items.impl_items() {
|
||||
|
|
|
@ -20,7 +20,7 @@ use rustc_hir::hir_id::CRATE_HIR_ID;
|
|||
use rustc_hir::intravisit::{self, Visitor};
|
||||
use rustc_hir::{FieldDef, Item, ItemKind, TraitRef, Ty, TyKind, Variant};
|
||||
use rustc_middle::hir::nested_filter;
|
||||
use rustc_middle::middle::privacy::AccessLevels;
|
||||
use rustc_middle::middle::privacy::EffectiveVisibilities;
|
||||
use rustc_middle::middle::stability::{AllowUnstable, DeprecationEntry, Index};
|
||||
use rustc_middle::ty::{query::Providers, TyCtxt};
|
||||
use rustc_session::lint;
|
||||
|
@ -516,13 +516,16 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
|
|||
|
||||
struct MissingStabilityAnnotations<'tcx> {
|
||||
tcx: TyCtxt<'tcx>,
|
||||
access_levels: &'tcx AccessLevels,
|
||||
effective_visibilities: &'tcx EffectiveVisibilities,
|
||||
}
|
||||
|
||||
impl<'tcx> MissingStabilityAnnotations<'tcx> {
|
||||
fn check_missing_stability(&self, def_id: LocalDefId, span: Span) {
|
||||
let stab = self.tcx.stability().local_stability(def_id);
|
||||
if !self.tcx.sess.opts.test && stab.is_none() && self.access_levels.is_reachable(def_id) {
|
||||
if !self.tcx.sess.opts.test
|
||||
&& stab.is_none()
|
||||
&& self.effective_visibilities.is_reachable(def_id)
|
||||
{
|
||||
let descr = self.tcx.def_kind(def_id).descr(def_id.to_def_id());
|
||||
self.tcx.sess.emit_err(MissingStabilityAttr { span, descr });
|
||||
}
|
||||
|
@ -540,7 +543,7 @@ impl<'tcx> MissingStabilityAnnotations<'tcx> {
|
|||
.lookup_stability(def_id)
|
||||
.map_or(false, |stability| stability.level.is_stable());
|
||||
let missing_const_stability_attribute = self.tcx.lookup_const_stability(def_id).is_none();
|
||||
let is_reachable = self.access_levels.is_reachable(def_id);
|
||||
let is_reachable = self.effective_visibilities.is_reachable(def_id);
|
||||
|
||||
if is_const && is_stable && missing_const_stability_attribute && is_reachable {
|
||||
let descr = self.tcx.def_kind(def_id).descr(def_id.to_def_id());
|
||||
|
@ -919,8 +922,8 @@ pub fn check_unused_or_stable_features(tcx: TyCtxt<'_>) {
|
|||
let is_staged_api =
|
||||
tcx.sess.opts.unstable_opts.force_unstable_if_unmarked || tcx.features().staged_api;
|
||||
if is_staged_api {
|
||||
let access_levels = &tcx.privacy_access_levels(());
|
||||
let mut missing = MissingStabilityAnnotations { tcx, access_levels };
|
||||
let effective_visibilities = &tcx.effective_visibilities(());
|
||||
let mut missing = MissingStabilityAnnotations { tcx, effective_visibilities };
|
||||
missing.check_missing_stability(CRATE_DEF_ID, tcx.hir().span(CRATE_HIR_ID));
|
||||
tcx.hir().walk_toplevel_module(&mut missing);
|
||||
tcx.hir().visit_all_item_likes_in_crate(&mut missing);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue