Skip to content

Commit 2a47113

Browse files
committed
Remove IntoDefIdTree
1 parent 1ab14ea commit 2a47113

File tree

2 files changed

+15
-29
lines changed

2 files changed

+15
-29
lines changed

compiler/rustc_middle/src/middle/privacy.rs

+8-17
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,6 @@ impl EffectiveVisibilities {
194194
}
195195
}
196196

197-
pub trait IntoDefIdTree {
198-
type Tree: DefIdTree;
199-
fn tree(self) -> Self::Tree;
200-
}
201-
202197
impl<Id: Eq + Hash> EffectiveVisibilities<Id> {
203198
pub fn iter(&self) -> impl Iterator<Item = (&Id, &EffectiveVisibility)> {
204199
self.map.iter()
@@ -217,25 +212,21 @@ impl<Id: Eq + Hash> EffectiveVisibilities<Id> {
217212
self.map.entry(id).or_insert_with(|| EffectiveVisibility::from_vis(lazy_private_vis()))
218213
}
219214

220-
pub fn update<T: IntoDefIdTree>(
215+
pub fn update(
221216
&mut self,
222217
id: Id,
223218
nominal_vis: Visibility,
224-
lazy_private_vis: impl FnOnce(T) -> (Visibility, T),
219+
lazy_private_vis: impl FnOnce() -> Visibility,
225220
inherited_effective_vis: EffectiveVisibility,
226221
level: Level,
227-
mut into_tree: T,
222+
tree: impl DefIdTree,
228223
) -> bool {
229224
let mut changed = false;
230-
let mut current_effective_vis = match self.map.get(&id).copied() {
231-
Some(eff_vis) => eff_vis,
232-
None => {
233-
let private_vis;
234-
(private_vis, into_tree) = lazy_private_vis(into_tree);
235-
EffectiveVisibility::from_vis(private_vis)
236-
}
237-
};
238-
let tree = into_tree.tree();
225+
let mut current_effective_vis = self
226+
.map
227+
.get(&id)
228+
.copied()
229+
.unwrap_or_else(|| EffectiveVisibility::from_vis(lazy_private_vis()));
239230

240231
let mut inherited_effective_vis_at_prev_level = *inherited_effective_vis.at_level(level);
241232
let mut calculated_effective_vis = inherited_effective_vis_at_prev_level;

compiler/rustc_resolve/src/effective_visibilities.rs

+7-12
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use rustc_ast::EnumDef;
77
use rustc_data_structures::intern::Interned;
88
use rustc_hir::def_id::LocalDefId;
99
use rustc_hir::def_id::CRATE_DEF_ID;
10+
use rustc_middle::middle::privacy::Level;
1011
use rustc_middle::middle::privacy::{EffectiveVisibilities, EffectiveVisibility};
11-
use rustc_middle::middle::privacy::{IntoDefIdTree, Level};
1212
use rustc_middle::ty::{DefIdTree, Visibility};
1313
use std::mem;
1414

@@ -67,13 +67,6 @@ impl Resolver<'_, '_> {
6767
}
6868
}
6969

70-
impl<'a, 'b, 'tcx> IntoDefIdTree for &'b mut Resolver<'a, 'tcx> {
71-
type Tree = &'b Resolver<'a, 'tcx>;
72-
fn tree(self) -> Self::Tree {
73-
self
74-
}
75-
}
76-
7770
impl<'r, 'a, 'tcx> EffectiveVisibilitiesVisitor<'r, 'a, 'tcx> {
7871
/// Fills the `Resolver::effective_visibilities` table with public & exported items
7972
/// For now, this doesn't resolve macros (FIXME) and cannot resolve Impl, as we
@@ -167,26 +160,28 @@ impl<'r, 'a, 'tcx> EffectiveVisibilitiesVisitor<'r, 'a, 'tcx> {
167160
let nominal_vis = binding.vis.expect_local();
168161
let private_vis = self.cheap_private_vis(parent_id);
169162
let inherited_eff_vis = self.effective_vis_or_private(parent_id);
163+
let tcx = self.r.tcx;
170164
self.changed |= self.import_effective_visibilities.update(
171165
binding,
172166
nominal_vis,
173-
|r| (private_vis.unwrap_or_else(|| r.private_vis_import(binding)), r),
167+
|| private_vis.unwrap_or_else(|| self.r.private_vis_import(binding)),
174168
inherited_eff_vis,
175169
parent_id.level(),
176-
&mut *self.r,
170+
tcx,
177171
);
178172
}
179173

180174
fn update_def(&mut self, def_id: LocalDefId, nominal_vis: Visibility, parent_id: ParentId<'a>) {
181175
let private_vis = self.cheap_private_vis(parent_id);
182176
let inherited_eff_vis = self.effective_vis_or_private(parent_id);
177+
let tcx = self.r.tcx;
183178
self.changed |= self.def_effective_visibilities.update(
184179
def_id,
185180
nominal_vis,
186-
|r| (private_vis.unwrap_or_else(|| r.private_vis_def(def_id)), r),
181+
|| private_vis.unwrap_or_else(|| self.r.private_vis_def(def_id)),
187182
inherited_eff_vis,
188183
parent_id.level(),
189-
&mut *self.r,
184+
tcx,
190185
);
191186
}
192187

0 commit comments

Comments
 (0)