Skip to content

Commit 3a37c2f

Browse files
committed
Auto merge of rust-lang#111371 - compiler-errors:revert-110907, r=petrochenkov
Revert "Populate effective visibilities in `rustc_privacy`" This reverts commit cff85f2, cc rust-lang#110907. It needs to be fixed, but there are too many issues being reported that I wanted to put up a revert until a proper fix can be committed. Fixes a ton of issues where private but still reachable impls were missing during codegen: Fixes rust-lang#111320 Fixes rust-lang#111321 Fixes rust-lang#111334 Fixes rust-lang#111357 Fixes rust-lang#111368 Fixes rust-lang#111373 Fixes rust-lang#111377 Fixes rust-lang#111386 Fixes rust-lang#111387 `@bors` p=1 r? `@petrochenkov`
2 parents f7b831a + 5fcf2e6 commit 3a37c2f

File tree

6 files changed

+178
-181
lines changed

6 files changed

+178
-181
lines changed

compiler/rustc_middle/src/middle/privacy.rs

+26-19
Original file line numberDiff line numberDiff line change
@@ -64,26 +64,14 @@ impl EffectiveVisibility {
6464
self.at_level(level).is_public()
6565
}
6666

67-
pub const fn from_vis(vis: Visibility) -> EffectiveVisibility {
67+
pub fn from_vis(vis: Visibility) -> EffectiveVisibility {
6868
EffectiveVisibility {
6969
direct: vis,
7070
reexported: vis,
7171
reachable: vis,
7272
reachable_through_impl_trait: vis,
7373
}
7474
}
75-
76-
#[must_use]
77-
pub fn min(mut self, lhs: EffectiveVisibility, tcx: TyCtxt<'_>) -> Self {
78-
for l in Level::all_levels() {
79-
let rhs_vis = self.at_level_mut(l);
80-
let lhs_vis = *lhs.at_level(l);
81-
if rhs_vis.is_at_least(lhs_vis, tcx) {
82-
*rhs_vis = lhs_vis;
83-
};
84-
}
85-
self
86-
}
8775
}
8876

8977
/// Holds a map of effective visibilities for reachable HIR nodes.
@@ -149,6 +137,24 @@ impl EffectiveVisibilities {
149137
};
150138
}
151139

140+
pub fn set_public_at_level(
141+
&mut self,
142+
id: LocalDefId,
143+
lazy_private_vis: impl FnOnce() -> Visibility,
144+
level: Level,
145+
) {
146+
let mut effective_vis = self
147+
.effective_vis(id)
148+
.copied()
149+
.unwrap_or_else(|| EffectiveVisibility::from_vis(lazy_private_vis()));
150+
for l in Level::all_levels() {
151+
if l <= level {
152+
*effective_vis.at_level_mut(l) = Visibility::Public;
153+
}
154+
}
155+
self.map.insert(id, effective_vis);
156+
}
157+
152158
pub fn check_invariants(&self, tcx: TyCtxt<'_>, early: bool) {
153159
if !cfg!(debug_assertions) {
154160
return;
@@ -213,7 +219,7 @@ impl<Id: Eq + Hash> EffectiveVisibilities<Id> {
213219
pub fn update(
214220
&mut self,
215221
id: Id,
216-
nominal_vis: Option<Visibility>,
222+
nominal_vis: Visibility,
217223
lazy_private_vis: impl FnOnce() -> Visibility,
218224
inherited_effective_vis: EffectiveVisibility,
219225
level: Level,
@@ -237,11 +243,12 @@ impl<Id: Eq + Hash> EffectiveVisibilities<Id> {
237243
if !(inherited_effective_vis_at_prev_level == inherited_effective_vis_at_level
238244
&& level != l)
239245
{
240-
calculated_effective_vis = if let Some(nominal_vis) = nominal_vis && !nominal_vis.is_at_least(inherited_effective_vis_at_level, tcx) {
241-
nominal_vis
242-
} else {
243-
inherited_effective_vis_at_level
244-
}
246+
calculated_effective_vis =
247+
if nominal_vis.is_at_least(inherited_effective_vis_at_level, tcx) {
248+
inherited_effective_vis_at_level
249+
} else {
250+
nominal_vis
251+
};
245252
}
246253
// effective visibility can't be decreased at next update call for the
247254
// same id

0 commit comments

Comments
 (0)