@@ -636,17 +636,45 @@ impl<'tcx> EmbargoVisitor<'tcx> {
636
636
impl < ' tcx > Visitor < ' tcx > for EmbargoVisitor < ' tcx > {
637
637
fn visit_item ( & mut self , item : & ' tcx hir:: Item < ' tcx > ) {
638
638
if self . impl_trait_pass
639
- && let hir:: ItemKind :: OpaqueTy ( .. ) = item. kind
639
+ && let hir:: ItemKind :: OpaqueTy ( opaque ) = item. kind
640
640
{
641
- // FIXME: This is some serious pessimization intended to workaround deficiencies
642
- // in the reachability pass (`middle/reachable.rs`). Types are marked as link-time
643
- // reachable if they are returned via `impl Trait`, even from private functions.
644
- let pub_ev = EffectiveVisibility :: from_vis ( ty:: Visibility :: Public ) ;
645
- self . reach_through_impl_trait ( item. owner_id . def_id , pub_ev)
646
- . generics ( )
647
- . predicates ( )
648
- . ty ( ) ;
649
- return ;
641
+ let should_visit = match opaque. origin {
642
+ hir:: OpaqueTyOrigin :: FnReturn {
643
+ parent,
644
+ in_trait_or_impl : Some ( hir:: RpitContext :: Trait ) ,
645
+ }
646
+ | hir:: OpaqueTyOrigin :: AsyncFn {
647
+ parent,
648
+ in_trait_or_impl : Some ( hir:: RpitContext :: Trait ) ,
649
+ } => match self . tcx . hir_node_by_def_id ( parent) . expect_trait_item ( ) . expect_fn ( ) . 1 {
650
+ hir:: TraitFn :: Required ( _) => false ,
651
+ hir:: TraitFn :: Provided ( ..) => true ,
652
+ } ,
653
+
654
+ // Always visit RPITs in functions that have definitions,
655
+ // and all TAITs.
656
+ hir:: OpaqueTyOrigin :: FnReturn {
657
+ in_trait_or_impl : None | Some ( hir:: RpitContext :: TraitImpl ) ,
658
+ ..
659
+ }
660
+ | hir:: OpaqueTyOrigin :: AsyncFn {
661
+ in_trait_or_impl : None | Some ( hir:: RpitContext :: TraitImpl ) ,
662
+ ..
663
+ }
664
+ | hir:: OpaqueTyOrigin :: TyAlias { .. } => true ,
665
+ } ;
666
+
667
+ if should_visit {
668
+ // FIXME: This is some serious pessimization intended to workaround deficiencies
669
+ // in the reachability pass (`middle/reachable.rs`). Types are marked as link-time
670
+ // reachable if they are returned via `impl Trait`, even from private functions.
671
+ let pub_ev = EffectiveVisibility :: from_vis ( ty:: Visibility :: Public ) ;
672
+ self . reach_through_impl_trait ( item. owner_id . def_id , pub_ev)
673
+ . generics ( )
674
+ . predicates ( )
675
+ . ty ( ) ;
676
+ return ;
677
+ }
650
678
}
651
679
652
680
// Update levels of nested things and mark all items
0 commit comments