Skip to content

Ignore coroutine witness type region args in auto trait confirmation #145194

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions compiler/rustc_trait_selection/src/traits/select/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2333,10 +2333,23 @@ impl<'tcx> SelectionContext<'_, 'tcx> {

ty::Coroutine(def_id, args) => {
let ty = self.infcx.shallow_resolve(args.as_coroutine().tupled_upvars_ty());
let tcx = self.tcx();
let witness = Ty::new_coroutine_witness(
self.tcx(),
tcx,
def_id,
self.tcx().mk_args(args.as_coroutine().parent_args()),
ty::GenericArgs::for_item(tcx, def_id, |def, _| match def.kind {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need generic args for typeck_root, not the coroutine here

gonna fix soon

// HACK: Coroutine witnesse types are lifetime erased, so they
// never reference any lifetime args from the coroutine. We erase
// the regions here since we may get into situations where a
// coroutine is recursively contained within itself, leading to
// witness types that differ by region args. This means that
// cycle detection in fulfillment will not kick in, which leads
// to unnecessary overflows in async code. See the issue:
// <https://github.com/rust-lang/rust/issues/145151>.
ty::GenericParamDefKind::Lifetime => tcx.lifetimes.re_erased.into(),
ty::GenericParamDefKind::Type { .. }
| ty::GenericParamDefKind::Const { .. } => args[def.index as usize],
}),
);
ty::Binder::dummy(AutoImplConstituents {
types: [ty].into_iter().chain(iter::once(witness)).collect(),
Expand Down
14 changes: 14 additions & 0 deletions tests/ui/async-await/recursive-async-auto-trait-overflow.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Regression test for <https://github.com/rust-lang/rust/issues/145151>.

//@ edition: 2024
//@ check-pass

async fn process<'a>() {
Box::pin(process()).await;
}

fn require_send(_: impl Send) {}

fn main() {
require_send(process());
}
Loading