Use () for privacy.

This commit is contained in:
Camille GILLOT 2021-05-11 13:49:00 +02:00
parent 2c71ad4bb3
commit 9849327384
10 changed files with 19 additions and 26 deletions

View File

@ -902,11 +902,11 @@ fn analysis(tcx: TyCtxt<'_>, cnum: CrateNum) -> Result<()> {
sess.time("misc_checking_3", || {
parallel!(
{
tcx.ensure().privacy_access_levels(LOCAL_CRATE);
tcx.ensure().privacy_access_levels(());
parallel!(
{
tcx.ensure().check_private_in_public(LOCAL_CRATE);
tcx.ensure().check_private_in_public(());
},
{
sess.time("death_checking", || rustc_passes::dead::check_crate(tcx));

View File

@ -18,7 +18,7 @@
use rustc_ast as ast;
use rustc_data_structures::sync::{join, par_iter, ParallelIterator};
use rustc_hir as hir;
use rustc_hir::def_id::{LocalDefId, LOCAL_CRATE};
use rustc_hir::def_id::LocalDefId;
use rustc_hir::intravisit as hir_visit;
use rustc_hir::intravisit::Visitor;
use rustc_middle::hir::map::Map;
@ -375,7 +375,7 @@ fn late_lint_mod_pass<'tcx, T: LateLintPass<'tcx>>(
module_def_id: LocalDefId,
pass: T,
) {
let access_levels = &tcx.privacy_access_levels(LOCAL_CRATE);
let access_levels = &tcx.privacy_access_levels(());
let context = LateContext {
tcx,
@ -423,7 +423,7 @@ pub fn late_lint_mod<'tcx, T: LateLintPass<'tcx>>(
}
fn late_lint_pass_crate<'tcx, T: LateLintPass<'tcx>>(tcx: TyCtxt<'tcx>, pass: T) {
let access_levels = &tcx.privacy_access_levels(LOCAL_CRATE);
let access_levels = &tcx.privacy_access_levels(());
let krate = tcx.hir().krate();

View File

@ -842,11 +842,11 @@
}
/// Performs part of the privacy check and computes "access levels".
query privacy_access_levels(_: CrateNum) -> &'tcx AccessLevels {
query privacy_access_levels(_: ()) -> &'tcx AccessLevels {
eval_always
desc { "privacy access levels" }
}
query check_private_in_public(_: CrateNum) -> () {
query check_private_in_public(_: ()) -> () {
eval_always
desc { "checking for private elements in public interfaces" }
}

View File

@ -5,7 +5,7 @@
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_hir as hir;
use rustc_hir::def::{CtorOf, DefKind, Res};
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
use rustc_hir::def_id::DefId;
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
use rustc_hir::itemlikevisit::ItemLikeVisitor;
use rustc_hir::{Node, PatKind, TyKind};
@ -708,7 +708,7 @@ fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem<'tcx>) {
}
pub fn check_crate(tcx: TyCtxt<'_>) {
let access_levels = &tcx.privacy_access_levels(LOCAL_CRATE);
let access_levels = &tcx.privacy_access_levels(());
let krate = tcx.hir().krate();
let live_symbols = find_live(tcx, access_levels, krate);
let mut visitor = DeadVisitor { tcx, live_symbols };

View File

@ -8,7 +8,6 @@
use rustc_data_structures::fx::FxHashSet;
use rustc_hir as hir;
use rustc_hir::def::{DefKind, Res};
use rustc_hir::def_id::LOCAL_CRATE;
use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
use rustc_hir::itemlikevisit::ItemLikeVisitor;
@ -387,7 +386,7 @@ fn visit_foreign_item(&mut self, _foreign_item: &hir::ForeignItem<'_>) {
}
fn reachable_set<'tcx>(tcx: TyCtxt<'tcx>, (): ()) -> FxHashSet<LocalDefId> {
let access_levels = &tcx.privacy_access_levels(LOCAL_CRATE);
let access_levels = &tcx.privacy_access_levels(());
let any_library =
tcx.sess.crate_types().iter().any(|ty| {

View File

@ -880,7 +880,7 @@ fn visit_ty(&mut self, t: &'tcx Ty<'tcx>) {
/// were expected to be library features), and the list of features used from
/// libraries, identify activated features that don't exist and error about them.
pub fn check_unused_or_stable_features(tcx: TyCtxt<'_>) {
let access_levels = &tcx.privacy_access_levels(LOCAL_CRATE);
let access_levels = &tcx.privacy_access_levels(());
if tcx.stability().staged_api[&LOCAL_CRATE] {
let krate = tcx.hir().krate();

View File

@ -12,7 +12,7 @@
use rustc_errors::struct_span_err;
use rustc_hir as hir;
use rustc_hir::def::{DefKind, Res};
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, CRATE_DEF_INDEX, LOCAL_CRATE};
use rustc_hir::def_id::{DefId, LocalDefId, CRATE_DEF_INDEX, LOCAL_CRATE};
use rustc_hir::intravisit::{self, DeepVisitor, NestedVisitorMap, Visitor};
use rustc_hir::{AssocItemKind, HirIdSet, Node, PatKind};
use rustc_middle::bug;
@ -2092,9 +2092,7 @@ fn check_mod_privacy(tcx: TyCtxt<'_>, module_def_id: LocalDefId) {
intravisit::walk_mod(&mut visitor, module, hir_id);
}
fn privacy_access_levels(tcx: TyCtxt<'_>, krate: CrateNum) -> &AccessLevels {
assert_eq!(krate, LOCAL_CRATE);
fn privacy_access_levels(tcx: TyCtxt<'_>, (): ()) -> &AccessLevels {
// Build up a set of all exported items in the AST. This is a set of all
// items which are reachable from external crates based on visibility.
let mut visitor = EmbargoVisitor {
@ -2117,10 +2115,8 @@ fn privacy_access_levels(tcx: TyCtxt<'_>, krate: CrateNum) -> &AccessLevels {
tcx.arena.alloc(visitor.access_levels)
}
fn check_private_in_public(tcx: TyCtxt<'_>, krate: CrateNum) {
assert_eq!(krate, LOCAL_CRATE);
let access_levels = tcx.privacy_access_levels(LOCAL_CRATE);
fn check_private_in_public(tcx: TyCtxt<'_>, (): ()) {
let access_levels = tcx.privacy_access_levels(());
let krate = tcx.hir().krate();

View File

@ -1000,7 +1000,7 @@ pub fn process_crate<'l, 'tcx, H: SaveHandler>(
// Privacy checking requires and is done after type checking; use a
// fallback in case the access levels couldn't have been correctly computed.
let access_levels = match tcx.sess.compile_status() {
Ok(..) => tcx.privacy_access_levels(LOCAL_CRATE),
Ok(..) => tcx.privacy_access_levels(()),
Err(..) => tcx.arena.alloc(AccessLevels::default()),
};

View File

@ -348,7 +348,7 @@ impl<'tcx> DocContext<'tcx> {
});
rustc_passes::stability::check_unused_or_stable_features(tcx);
let access_levels = tcx.privacy_access_levels(LOCAL_CRATE);
let access_levels = tcx.privacy_access_levels(());
// Convert from a HirId set to a DefId set since we don't always have easy access
// to the map from defid -> hirid
let access_levels = AccessLevels {

View File

@ -1213,13 +1213,11 @@ fn resolve_link(
item.def_id.expect_real().as_local().map(|src_id| (src_id, dst_id))
})
{
use rustc_hir::def_id::LOCAL_CRATE;
let hir_src = self.cx.tcx.hir().local_def_id_to_hir_id(src_id);
let hir_dst = self.cx.tcx.hir().local_def_id_to_hir_id(dst_id);
if self.cx.tcx.privacy_access_levels(LOCAL_CRATE).is_exported(hir_src)
&& !self.cx.tcx.privacy_access_levels(LOCAL_CRATE).is_exported(hir_dst)
if self.cx.tcx.privacy_access_levels(()).is_exported(hir_src)
&& !self.cx.tcx.privacy_access_levels(()).is_exported(hir_dst)
{
privacy_error(self.cx, &diag_info, &path_str);
}