rust-lang / rust-lang/rust

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

Open
#139,658 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-impl-trait A-type-system 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:

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).

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

Use the minimized example in src/lib.rs to reproduce the difference between cargo check and cargo build with the reported rustc versions. Compare the resulting behavior and diagnostics, then add coverage showing that the example no longer overflows during cargo build while preserving the expected cargo check result.

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
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.