@@ -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,48 +632,6 @@ impl<'tcx> EmbargoVisitor<'tcx> {
634632}
635633
636634impl < ' tcx > Visitor < ' tcx > for EmbargoVisitor < ' tcx > {
637- fn visit_opaque_ty ( & mut self , opaque : & ' tcx hir:: OpaqueTy < ' tcx > ) {
638- if self . impl_trait_pass {
639- let should_visit = match opaque. origin {
640- hir:: OpaqueTyOrigin :: FnReturn {
641- parent,
642- in_trait_or_impl : Some ( hir:: RpitContext :: Trait ) ,
643- }
644- | hir:: OpaqueTyOrigin :: AsyncFn {
645- parent,
646- in_trait_or_impl : Some ( hir:: RpitContext :: Trait ) ,
647- } => match self . tcx . hir_node_by_def_id ( parent) . expect_trait_item ( ) . expect_fn ( ) . 1 {
648- hir:: TraitFn :: Required ( _) => false ,
649- hir:: TraitFn :: Provided ( ..) => true ,
650- } ,
651-
652- // Always visit RPITs in functions that have definitions,
653- // and all TAITs.
654- hir:: OpaqueTyOrigin :: FnReturn {
655- in_trait_or_impl : None | Some ( hir:: RpitContext :: TraitImpl ) ,
656- ..
657- }
658- | hir:: OpaqueTyOrigin :: AsyncFn {
659- in_trait_or_impl : None | Some ( hir:: RpitContext :: TraitImpl ) ,
660- ..
661- }
662- | hir:: OpaqueTyOrigin :: TyAlias { .. } => true ,
663- } ;
664-
665- if should_visit {
666- // FIXME: This is some serious pessimization intended to workaround deficiencies
667- // in the reachability pass (`middle/reachable.rs`). Types are marked as link-time
668- // reachable if they are returned via `impl Trait`, even from private functions.
669- let pub_ev = EffectiveVisibility :: from_vis ( ty:: Visibility :: Public ) ;
670- self . reach_through_impl_trait ( opaque. def_id , pub_ev) . generics ( ) . predicates ( ) . ty ( ) ;
671- return ;
672- }
673- }
674-
675- // Visit nested items.
676- intravisit:: walk_opaque_ty ( self , opaque)
677- }
678-
679635 fn visit_item ( & mut self , item : & ' tcx hir:: Item < ' tcx > ) {
680636 // Update levels of nested things and mark all items
681637 // in interfaces of reachable items as reachable.
@@ -1752,19 +1708,59 @@ fn effective_visibilities(tcx: TyCtxt<'_>, (): ()) -> &EffectiveVisibilities {
17521708 tcx,
17531709 effective_visibilities : tcx. resolutions ( ( ) ) . effective_visibilities . clone ( ) ,
17541710 macro_reachable : Default :: default ( ) ,
1755- // HACK(jynelson): trying to infer the type of `impl Trait` breaks `async-std` (and
1756- // `pub async fn` in general). Since rustdoc never needs to do codegen and doesn't
1757- // care about link-time reachability, keep them unreachable (issue #75100).
1758- impl_trait_pass : !tcx. sess . opts . actually_rustdoc ,
17591711 changed : false ,
17601712 } ;
17611713
17621714 visitor. effective_visibilities . check_invariants ( tcx) ;
1763- 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 {
17641721 // Underlying types of `impl Trait`s are marked as reachable unconditionally,
17651722 // so this pass doesn't need to be a part of the fixed point iteration below.
1766- tcx. hir ( ) . visit_all_item_likes_in_crate ( & mut visitor) ;
1767- 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+ let should_visit = match opaque. origin {
1727+ hir:: OpaqueTyOrigin :: FnReturn {
1728+ parent,
1729+ in_trait_or_impl : Some ( hir:: RpitContext :: Trait ) ,
1730+ }
1731+ | hir:: OpaqueTyOrigin :: AsyncFn {
1732+ parent,
1733+ in_trait_or_impl : Some ( hir:: RpitContext :: Trait ) ,
1734+ } => match tcx. hir_node_by_def_id ( parent) . expect_trait_item ( ) . expect_fn ( ) . 1 {
1735+ hir:: TraitFn :: Required ( _) => false ,
1736+ hir:: TraitFn :: Provided ( ..) => true ,
1737+ } ,
1738+
1739+ // Always visit RPITs in functions that have definitions,
1740+ // and all TAITs.
1741+ hir:: OpaqueTyOrigin :: FnReturn {
1742+ in_trait_or_impl : None | Some ( hir:: RpitContext :: TraitImpl ) ,
1743+ ..
1744+ }
1745+ | hir:: OpaqueTyOrigin :: AsyncFn {
1746+ in_trait_or_impl : None | Some ( hir:: RpitContext :: TraitImpl ) ,
1747+ ..
1748+ }
1749+ | hir:: OpaqueTyOrigin :: TyAlias { .. } => true ,
1750+ } ;
1751+ if should_visit {
1752+ // FIXME: This is some serious pessimization intended to workaround deficiencies
1753+ // in the reachability pass (`middle/reachable.rs`). Types are marked as link-time
1754+ // reachable if they are returned via `impl Trait`, even from private functions.
1755+ let pub_ev = EffectiveVisibility :: from_vis ( ty:: Visibility :: Public ) ;
1756+ visitor
1757+ . reach_through_impl_trait ( opaque. def_id , pub_ev)
1758+ . generics ( )
1759+ . predicates ( )
1760+ . ty ( ) ;
1761+ }
1762+ }
1763+
17681764 visitor. changed = false ;
17691765 }
17701766
0 commit comments