Skip to content

Commit d94b9cc

Browse files
committed
Visit opaques for visibilities.
1 parent ac87276 commit d94b9cc

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
@@ -402,8 +402,6 @@ struct EmbargoVisitor<'tcx> {
402402
/// n::p::f()
403403
/// }
404404
macro_reachable: FxHashSet<(LocalModDefId, LocalModDefId)>,
405-
/// Preliminary pass for marking all underlying types of `impl Trait`s as reachable.
406-
impl_trait_pass: bool,
407405
/// Has something changed in the level map?
408406
changed: bool,
409407
}
@@ -634,20 +632,6 @@ impl<'tcx> EmbargoVisitor<'tcx> {
634632
}
635633

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

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

0 commit comments

Comments
 (0)