Skip to content

Commit 5a4b6dc

Browse files
committed
Visit opaques for visibilities.
1 parent 4835f90 commit 5a4b6dc

File tree

1 file changed

+22
-23
lines changed
  • compiler/rustc_privacy/src

1 file changed

+22
-23
lines changed

compiler/rustc_privacy/src/lib.rs

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -401,8 +401,6 @@ struct EmbargoVisitor<'tcx> {
401401
/// n::p::f()
402402
/// }
403403
macro_reachable: FxHashSet<(LocalModDefId, LocalModDefId)>,
404-
/// Preliminary pass for marking all underlying types of `impl Trait`s as reachable.
405-
impl_trait_pass: bool,
406404
/// Has something changed in the level map?
407405
changed: bool,
408406
}
@@ -632,20 +630,6 @@ impl<'tcx> EmbargoVisitor<'tcx> {
632630
}
633631

634632
impl<'tcx> Visitor<'tcx> for EmbargoVisitor<'tcx> {
635-
fn visit_opaque_ty(&mut self, opaque: &'tcx rustc_hir::OpaqueTy<'tcx>) -> Self::Result {
636-
if self.impl_trait_pass && !opaque.in_trait {
637-
// FIXME: This is some serious pessimization intended to workaround deficiencies
638-
// in the reachability pass (`middle/reachable.rs`). Types are marked as link-time
639-
// reachable if they are returned via `impl Trait`, even from private functions.
640-
let pub_ev = EffectiveVisibility::from_vis(ty::Visibility::Public);
641-
self.reach_through_impl_trait(opaque.def_id, pub_ev).generics().predicates().ty();
642-
return;
643-
}
644-
645-
// Visit nested items.
646-
intravisit::walk_opaque_ty(self, opaque)
647-
}
648-
649633
fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) {
650634
// Update levels of nested things and mark all items
651635
// in interfaces of reachable items as reachable.
@@ -1722,19 +1706,34 @@ fn effective_visibilities(tcx: TyCtxt<'_>, (): ()) -> &EffectiveVisibilities {
17221706
tcx,
17231707
effective_visibilities: tcx.resolutions(()).effective_visibilities.clone(),
17241708
macro_reachable: Default::default(),
1725-
// HACK(jynelson): trying to infer the type of `impl Trait` breaks `async-std` (and
1726-
// `pub async fn` in general). Since rustdoc never needs to do codegen and doesn't
1727-
// care about link-time reachability, keep them unreachable (issue #75100).
1728-
impl_trait_pass: !tcx.sess.opts.actually_rustdoc,
17291709
changed: false,
17301710
};
17311711

17321712
visitor.effective_visibilities.check_invariants(tcx);
1733-
if visitor.impl_trait_pass {
1713+
1714+
// HACK(jynelson): trying to infer the type of `impl Trait` breaks `async-std` (and
1715+
// `pub async fn` in general). Since rustdoc never needs to do codegen and doesn't
1716+
// care about link-time reachability, keep them unreachable (issue #75100).
1717+
let impl_trait_pass = !tcx.sess.opts.actually_rustdoc;
1718+
if impl_trait_pass {
17341719
// Underlying types of `impl Trait`s are marked as reachable unconditionally,
17351720
// so this pass doesn't need to be a part of the fixed point iteration below.
1736-
tcx.hir().visit_all_item_likes_in_crate(&mut visitor);
1737-
visitor.impl_trait_pass = false;
1721+
let krate = tcx.hir_crate_items(());
1722+
for id in krate.opaques() {
1723+
let opaque = tcx.hir_node_by_def_id(id).expect_opaque_ty();
1724+
if !opaque.in_trait {
1725+
// FIXME: This is some serious pessimization intended to workaround deficiencies
1726+
// in the reachability pass (`middle/reachable.rs`). Types are marked as link-time
1727+
// reachable if they are returned via `impl Trait`, even from private functions.
1728+
let pub_ev = EffectiveVisibility::from_vis(ty::Visibility::Public);
1729+
visitor
1730+
.reach_through_impl_trait(opaque.def_id, pub_ev)
1731+
.generics()
1732+
.predicates()
1733+
.ty();
1734+
}
1735+
}
1736+
17381737
visitor.changed = false;
17391738
}
17401739

0 commit comments

Comments
 (0)