Skip to content

Asynchronous closures make trait constraint inference recursive #146399

Open

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

Activity

  1. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Sep 10, 2025
  2. GrigorenkoPV commented on Sep 10, 2025

    @GrigorenkoPV
    Contributor

    The error used to be

    error[E0308]: mismatched types
     --> src/lib.rs:8:21
      |
    8 |         errors.push(a);
      |                ---- ^ cyclic type of infinite size
      |                |
      |                arguments to this method are incorrect
      |
    

    before #119989

  3. added
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Sep 10, 2025
  4. added
    T-typesRelevant to the types team, which will review and decide on the PR/issue.
    on Sep 11, 2025
  5. removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Dec 30, 2025
  6. chenyukang commented on Aug 25, 2026

    @chenyukang
    Member

    here seems better? output from PR #161705

    error[E0308]: mismatched types
       --> /tmp/now.rs:8:21
        |
      2 |     let mut errors = Vec::new();
        |                      ---------- here the type of `errors` is inferred to be `Vec<(&str, ())>`
    ...
      8 |         errors.push(a);
        |                ---- ^ expected `(&str, ())`, found `()`
        |                |
        |                arguments to this method are incorrect
        |
        = note:  expected tuple `(&str, ())`
                found unit type `()`
    note: method defined here
       --> library/alloc/src/vec/mod.rs:995:12
        |
    995 |     pub fn push(&mut self, value: T) {
        |            ^^^^
    
    error: aborting due to 1 previous error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions