diff options
| author | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2022-11-19 01:52:49 +0300 |
|---|---|---|
| committer | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2022-11-24 00:03:51 +0300 |
| commit | 3f20f4ac42be55f309224ef365dfa2ca64359e07 (patch) | |
| tree | 92db5edce2086f35428f85d5218f38d87e8d7510 /compiler/rustc_middle | |
| parent | d121aa3b5584eb919a4aaf64dbae0ea1e8e30231 (diff) | |
effective visibility: Satisfy borrow checker to use resolver lazily from a closure
Diffstat (limited to 'compiler/rustc_middle')
| -rw-r--r-- | compiler/rustc_middle/src/middle/privacy.rs | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/compiler/rustc_middle/src/middle/privacy.rs b/compiler/rustc_middle/src/middle/privacy.rs index 3a91522d362..decd213763d 100644 --- a/compiler/rustc_middle/src/middle/privacy.rs +++ b/compiler/rustc_middle/src/middle/privacy.rs @@ -142,13 +142,13 @@ impl EffectiveVisibilities { pub fn set_public_at_level( &mut self, id: LocalDefId, - default_vis: impl FnOnce() -> Visibility, + lazy_private_vis: impl FnOnce() -> Visibility, level: Level, ) { let mut effective_vis = self .effective_vis(id) .copied() - .unwrap_or_else(|| EffectiveVisibility::from_vis(default_vis())); + .unwrap_or_else(|| EffectiveVisibility::from_vis(lazy_private_vis())); for l in Level::all_levels() { if l <= level { *effective_vis.at_level_mut(l) = Visibility::Public; @@ -206,6 +206,11 @@ impl EffectiveVisibilities { } } +pub trait IntoDefIdTree { + type Tree: DefIdTree; + fn tree(self) -> Self::Tree; +} + impl<Id: Eq + Hash> EffectiveVisibilities<Id> { pub fn iter(&self) -> impl Iterator<Item = (&Id, &EffectiveVisibility)> { self.map.iter() @@ -217,21 +222,26 @@ impl<Id: Eq + Hash> EffectiveVisibilities<Id> { // `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( + pub fn update<T: IntoDefIdTree>( &mut self, id: Id, nominal_vis: Visibility, - default_vis: Visibility, + lazy_private_vis: impl FnOnce(T) -> (Visibility, T), inherited_eff_vis: Option<EffectiveVisibility>, level: Level, - tree: impl DefIdTree, + mut into_tree: T, ) -> bool { let mut changed = false; - let mut current_effective_vis = self - .map - .get(&id) - .copied() - .unwrap_or_else(|| EffectiveVisibility::from_vis(default_vis)); + let mut current_effective_vis = match self.map.get(&id).copied() { + Some(eff_vis) => eff_vis, + None => { + let private_vis; + (private_vis, into_tree) = lazy_private_vis(into_tree); + EffectiveVisibility::from_vis(private_vis) + } + }; + let tree = into_tree.tree(); + if let Some(inherited_effective_vis) = inherited_eff_vis { let mut inherited_effective_vis_at_prev_level = *inherited_effective_vis.at_level(level); |
