Skip to content

Asynchronous closures make trait constraint inference recursive #146399

@eareimu

Description

@eareimu

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-inferenceArea: Type inferenceC-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-typesRelevant to the types team, which will review and decide on the PR/issue.needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions