Visit in embargo visitor if trait method has body

This commit is contained in:
Michael Goulet 2024-10-02 23:00:08 -04:00
parent 7cd466a036
commit 6e8573c520

View File

@ -636,8 +636,35 @@ impl<'tcx> EmbargoVisitor<'tcx> {
impl<'tcx> Visitor<'tcx> for EmbargoVisitor<'tcx> { impl<'tcx> Visitor<'tcx> for EmbargoVisitor<'tcx> {
fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) { fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) {
if self.impl_trait_pass if self.impl_trait_pass
&& let hir::ItemKind::OpaqueTy(..) = item.kind && let hir::ItemKind::OpaqueTy(opaque) = item.kind
{ {
let should_visit = match opaque.origin {
hir::OpaqueTyOrigin::FnReturn {
parent,
in_trait_or_impl: Some(hir::RpitContext::Trait),
}
| hir::OpaqueTyOrigin::AsyncFn {
parent,
in_trait_or_impl: Some(hir::RpitContext::Trait),
} => match self.tcx.hir_node_by_def_id(parent).expect_trait_item().expect_fn().1 {
hir::TraitFn::Required(_) => false,
hir::TraitFn::Provided(..) => true,
},
// Always visit RPITs in functions that have definitions,
// and all TAITs.
hir::OpaqueTyOrigin::FnReturn {
in_trait_or_impl: None | Some(hir::RpitContext::TraitImpl),
..
}
| hir::OpaqueTyOrigin::AsyncFn {
in_trait_or_impl: None | Some(hir::RpitContext::TraitImpl),
..
}
| hir::OpaqueTyOrigin::TyAlias { .. } => true,
};
if should_visit {
// FIXME: This is some serious pessimization intended to workaround deficiencies // FIXME: This is some serious pessimization intended to workaround deficiencies
// in the reachability pass (`middle/reachable.rs`). Types are marked as link-time // in the reachability pass (`middle/reachable.rs`). Types are marked as link-time
// reachable if they are returned via `impl Trait`, even from private functions. // reachable if they are returned via `impl Trait`, even from private functions.
@ -648,6 +675,7 @@ impl<'tcx> Visitor<'tcx> for EmbargoVisitor<'tcx> {
.ty(); .ty();
return; return;
} }
}
// Update levels of nested things and mark all items // Update levels of nested things and mark all items
// in interfaces of reachable items as reachable. // in interfaces of reachable items as reachable.