//! A pass that checks to make sure private fields and methods aren't used
//! outside their scopes. This pass will also generate a set of exported items
//! which are available for use externally when compiled as a library.
-use crate::ty::{DefIdTree, TyCtxt, Visibility};
+use crate::ty::{TyCtxt, Visibility};
use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use rustc_macros::HashStable;
use rustc_query_system::ich::StableHashingContext;
-use rustc_span::def_id::LocalDefId;
+use rustc_span::def_id::{LocalDefId, CRATE_DEF_ID};
use std::hash::Hash;
/// Represents the levels of effective visibility an item can have.
})
}
+ pub fn update_root(&mut self) {
+ self.map.insert(CRATE_DEF_ID, EffectiveVisibility::from_vis(Visibility::Public));
+ }
+
// FIXME: Share code with `fn update`.
pub fn update_eff_vis(
&mut self,
def_id: LocalDefId,
eff_vis: &EffectiveVisibility,
- tree: impl DefIdTree,
+ tcx: TyCtxt<'_>,
) {
use std::collections::hash_map::Entry;
match self.map.entry(def_id) {
let vis_at_level = eff_vis.at_level(l);
let old_vis_at_level = old_eff_vis.at_level_mut(l);
if vis_at_level != old_vis_at_level
- && vis_at_level.is_at_least(*old_vis_at_level, tree)
+ && vis_at_level.is_at_least(*old_vis_at_level, tcx)
{
*old_vis_at_level = *vis_at_level
}
lazy_private_vis: impl FnOnce() -> Visibility,
inherited_effective_vis: EffectiveVisibility,
level: Level,
- tree: impl DefIdTree,
+ tcx: TyCtxt<'_>,
) -> bool {
let mut changed = false;
let mut current_effective_vis = self
&& level != l)
{
calculated_effective_vis =
- if nominal_vis.is_at_least(inherited_effective_vis_at_level, tree) {
+ if nominal_vis.is_at_least(inherited_effective_vis_at_level, tcx) {
inherited_effective_vis_at_level
} else {
nominal_vis
// effective visibility can't be decreased at next update call for the
// same id
if *current_effective_vis_at_level != calculated_effective_vis
- && calculated_effective_vis.is_at_least(*current_effective_vis_at_level, tree)
+ && calculated_effective_vis.is_at_least(*current_effective_vis_at_level, tcx)
{
changed = true;
*current_effective_vis_at_level = calculated_effective_vis;