Skip to content

cargo check works fine, but cargo build gives "overflow evaluating the requirement " #139658

Open
@theemathas

Description

@theemathas

I tried this code:

trait Trait {
    type Output;
}

impl<O, F: Fn() -> O> Trait for F {
    type Output = O;
}

struct Wrap<P>(P);

impl<P: Trait> Trait for Wrap<P> {
    type Output = P::Output;
}

fn wrap<P: Trait>(x: P) -> impl Trait {
    Wrap(x)
}

fn consume<P: Trait>(_: P) -> P::Output {
    unimplemented!()
}

pub fn recurse() -> impl Sized {
    consume(wrap(recurse))
}

I think that the code should compile fine. However:

  • When compiling with cargo check, it compiles fine.
  • When compiling with cargo build, I get the following error:
error[E0275]: overflow evaluating the requirement `fn() -> impl Sized {recurse}: Trait`
   |
   = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`foo`)
note: required for `Wrap<fn() -> impl Sized {recurse}>` to implement `Trait`
  --> src/lib.rs:11:16
   |
11 | impl<P: Trait> Trait for Wrap<P> {
   |         -----  ^^^^^     ^^^^^^^
   |         |
   |         unsatisfied trait bound introduced here

For more information about this error, try `rustc --explain E0275`.

Minimized from real code written by fearless_process on the rust community discord.

Very similar to #139659, which instead ICEs.

Meta

rustc --version --verbose:

rustc 1.86.0 (05f9846f8 2025-03-31)
binary: rustc
commit-hash: 05f9846f893b09a1be1fc8560e33fc3c815cfecb
commit-date: 2025-03-31
host: aarch64-apple-darwin
release: 1.86.0
LLVM version: 19.1.7

The issue also reproduces on rustc 1.88.0-nightly (0fe8f3454 2025-04-10).

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-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