`cargo check` works fine, but `cargo build` gives "overflow evaluating the requirement "
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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