Skip to content

Commit 6e8573c

Browse files
Visit in embargo visitor if trait method has body
1 parent 7cd466a commit 6e8573c

File tree

1 file changed

+38
-10
lines changed
  • compiler/rustc_privacy/src

1 file changed

+38
-10
lines changed

Diff for: compiler/rustc_privacy/src/lib.rs

+38-10
Original file line numberDiff line numberDiff line change
@@ -636,17 +636,45 @@ impl<'tcx> EmbargoVisitor<'tcx> {
636636
impl<'tcx> Visitor<'tcx> for EmbargoVisitor<'tcx> {
637637
fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) {
638638
if self.impl_trait_pass
639-
&& let hir::ItemKind::OpaqueTy(..) = item.kind
639+
&& let hir::ItemKind::OpaqueTy(opaque) = item.kind
640640
{
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+
}
650678
}
651679

652680
// Update levels of nested things and mark all items

0 commit comments

Comments
 (0)