rust-lang / rust-lang/rust

Asynchronous closures make trait constraint inference recursive

Open
#146,399 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-inference C-bug T-compiler T-types
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

I tried this code:

async fn foo() -> Vec<(&'static str, ())> {
    let mut errors = Vec::new();
    let op = async || Ok(());
    if let Err(a) = async { op().await }.await {
        errors.push(("test", a));
    }
    if let Err(a) = async { op().await }.await {
        errors.push(a);
    }
    errors
}

The code could probably be simplified further?

I expected to see this happen: ...type mismatch...

Instead, this happened:

error[E0275]: overflow evaluating the requirement `(&str, _): std::marker::Sized`
   --> genmeta-ssh3/src/config.rs:127:22
    |
127 |     let mut errors = Vec::new();
    |                      ^^^
    |
    = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`genmeta_ssh3`)
    = note: required because it appears within the type `(&str, (&str, _))`
    = note: required because it appears within the type `(&str, (&str, (&str, _)))`
    = note: required because it appears within the type `(&str, (&str, (&str, (&str, _))))`
    = note: required because it appears within the type `(&str, (&str, (&str, (&str, (&str, _)))))`
...... continue recursion
Meta

rustc --version --verbose:

rustc 1.91.0-nightly (7ad23f43a 2025-09-09)
binary: rustc
commit-hash: 7ad23f43a225546c095123de52cc07d8719f8e2b
commit-date: 2025-09-09
host: aarch64-apple-darwin
release: 1.91.0-nightly
LLVM version: 21.1.0
Backtrace

none

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by compiling the async-closure reproducer with the reported rustc 1.91.0-nightly version, using genmeta-ssh3/src/config.rs:127 as the observed failure location. Trace the trait-constraint inference involved in the nested async calls and verify that the example produces the expected type mismatch instead of recursively overflowing with E0275.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.