From f1850d4c9b5f4f64ad41193bb8c846027754f0ca Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sat, 29 Oct 2022 14:58:37 +0400 Subject: [PATCH] rustc_middle: Remove unnecessary type parameter from `AccessLevels` --- compiler/rustc_middle/src/middle/privacy.rs | 48 +++++++-------------- 1 file changed, 16 insertions(+), 32 deletions(-) diff --git a/compiler/rustc_middle/src/middle/privacy.rs b/compiler/rustc_middle/src/middle/privacy.rs index 9c68c750475..ffbd6d10da6 100644 --- a/compiler/rustc_middle/src/middle/privacy.rs +++ b/compiler/rustc_middle/src/middle/privacy.rs @@ -6,8 +6,7 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_macros::HashStable; use rustc_query_system::ich::StableHashingContext; -use rustc_span::def_id::{DefId, LocalDefId}; -use std::hash::Hash; +use rustc_span::def_id::LocalDefId; /// Represents the levels of effective visibility an item can have. /// @@ -75,33 +74,33 @@ pub fn from_vis(vis: Visibility) -> EffectiveVisibility { } /// Holds a map of effective visibilities for reachable HIR nodes. -#[derive(Debug, Clone)] -pub struct EffectiveVisibilities { - map: FxHashMap, +#[derive(Default, Clone, Debug)] +pub struct EffectiveVisibilities { + map: FxHashMap, } -impl EffectiveVisibilities { - pub fn is_public_at_level(&self, id: Id, level: Level) -> bool { +impl EffectiveVisibilities { + pub fn is_public_at_level(&self, id: LocalDefId, level: Level) -> bool { self.effective_vis(id) .map_or(false, |effective_vis| effective_vis.is_public_at_level(level)) } /// See `Level::Reachable`. - pub fn is_reachable(&self, id: Id) -> bool { + pub fn is_reachable(&self, id: LocalDefId) -> bool { self.is_public_at_level(id, Level::Reachable) } /// See `Level::Reexported`. - pub fn is_exported(&self, id: Id) -> bool { + pub fn is_exported(&self, id: LocalDefId) -> bool { self.is_public_at_level(id, Level::Reexported) } /// See `Level::Direct`. - pub fn is_directly_public(&self, id: Id) -> bool { + pub fn is_directly_public(&self, id: LocalDefId) -> bool { self.is_public_at_level(id, Level::Direct) } - pub fn public_at_level(&self, id: Id) -> Option { + pub fn public_at_level(&self, id: LocalDefId) -> Option { self.effective_vis(id).and_then(|effective_vis| { for level in Level::all_levels() { if effective_vis.is_public_at_level(level) { @@ -112,24 +111,17 @@ pub fn public_at_level(&self, id: Id) -> Option { }) } - pub fn effective_vis(&self, id: Id) -> Option<&EffectiveVisibility> { + pub fn effective_vis(&self, id: LocalDefId) -> Option<&EffectiveVisibility> { self.map.get(&id) } - pub fn iter(&self) -> impl Iterator { + pub fn iter(&self) -> impl Iterator { self.map.iter() } - pub fn map_id( - &self, - f: impl Fn(Id) -> OutId, - ) -> EffectiveVisibilities { - EffectiveVisibilities { map: self.map.iter().map(|(k, v)| (f(*k), *v)).collect() } - } - pub fn set_public_at_level( &mut self, - id: Id, + id: LocalDefId, default_vis: impl FnOnce() -> Visibility, level: Level, ) { @@ -144,23 +136,21 @@ pub fn set_public_at_level( } self.map.insert(id, effective_vis); } -} -impl> EffectiveVisibilities { // `parent_id` is not necessarily a parent in source code tree, // it is the node from which the maximum effective visibility is inherited. pub fn update( &mut self, - id: Id, + id: LocalDefId, nominal_vis: Visibility, default_vis: impl FnOnce() -> Visibility, - parent_id: Id, + parent_id: LocalDefId, level: Level, tree: impl DefIdTree, ) -> bool { let mut changed = false; let mut current_effective_vis = self.effective_vis(id).copied().unwrap_or_else(|| { - if id.into().is_crate_root() { + if id.is_top_level_module() { EffectiveVisibility::from_vis(Visibility::Public) } else { EffectiveVisibility::from_vis(default_vis()) @@ -204,12 +194,6 @@ pub fn update( } } -impl Default for EffectiveVisibilities { - fn default() -> Self { - EffectiveVisibilities { map: Default::default() } - } -} - impl<'a> HashStable> for EffectiveVisibilities { fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { let EffectiveVisibilities { ref map } = *self;