Skip to content

overflow evaluating the requirement with impls those seem to be right #74789

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
WaffleLapkin opened this issue Jul 26, 2020 · 4 comments
Closed
Labels
A-associated-items Area: Associated items (types, constants & functions) A-coherence Area: Coherence C-bug Category: This is a bug. S-has-bisection Status: a bisection has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue.

Comments

@WaffleLapkin
Copy link
Member

I tried this code:

#![recursion_limit="5"] // without it the error is the same, but much bigger
struct Nil;
struct Cons<H, T>(H, T);

pub trait Map<F> {
    type Output;
}

impl<FH, FM, FT, H, M, T, R> Map<Cons<FH, Cons<FM, FT>>> for Cons<H, Cons<M, T>>
where
    FH: FnOnce(H) -> R,
    Cons<M, T>: Map<Cons<FM, FT>>,
{
    type Output = Cons<R, <Cons<M, T> as Map<Cons<FM, FT>>>::Output>;
}

impl<F, H, T, R> Map<F> for Cons<H, T>
where
    F: FnMut(H) -> R,
    T: Map<F>,
{
    type Output = Cons<R, T::Output>;
}

I expected this code to compile.

Instead, the compiler fails with a huge error:

error[E0275]: overflow evaluating the requirement `Cons<_, Cons<_, _>>: Map<Cons<_, Cons<_, _>>>`
  |
  = help: consider adding a `#![recursion_limit="10"]` attribute to your crate (`playground`)
  = note: required because of the requirements on the impl of `Map<Cons<_, Cons<_, Cons<_, _>>>>` for `Cons<_, Cons<_, Cons<_, _>>>`
  = note: required because of the requirements on the impl of `Map<Cons<_, Cons<_, Cons<_, Cons<_, _>>>>>` for `Cons<_, Cons<_, Cons<_, Cons<_, _>>>>`
  = note: required because of the requirements on the impl of `Map<Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, _>>>>>>` for `Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, _>>>>>`
  = note: required because of the requirements on the impl of `Map<Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, _>>>>>>>` for `Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, _>>>>>>`
  = note: required because of the requirements on the impl of `Map<Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, _>>>>>>>>` for `Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, _>>>>>>>`

(playground)

Note that very similar code with a slightly different trait works, so I assume this is a bug (though, I may miss something)

Also, note that there is a lot of issues with E0275, however, I couldn't find one that fits my problem.

Meta

Tested on 1.45.0 and 1.47.0-nightly (2020-07-25 d6953df14657f5932270)

@WaffleLapkin WaffleLapkin added the C-bug Category: This is a bug. label Jul 26, 2020
@WaffleLapkin
Copy link
Member Author

I've created more minimal example:

#![recursion_limit="5"] // without it the error is the same, but much bigger

struct Nil;
struct Cons<H, T>(H, T);

pub trait Map<F> {}

impl<F, H, M, T> Map<F> for Cons<H, Cons<M, T>>
where
    Cons<(), T>: Map<Cons<(), ()>>,
{}

impl<F, H, T> Map<F> for Cons<H, T> {}

(playground)

I don't expect this to compile (in difference with original example), though the error should definitely be

error[E0119]: conflicting implementations of trait `Map<_>` for type `Cons<_, Cons<_, _>>`

instead of

error[E0275]: overflow evaluating the requirement `Cons<_, Cons<_, _>>: Map<Cons<_, Cons<_, _>>>`

@Enselic Enselic added A-associated-items Area: Associated items (types, constants & functions) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed needs-triage-legacy labels Aug 19, 2023
@RodBurman
Copy link

The current tool chain:

% cargo -v -V
cargo 1.84.1 (66221abde 2024-11-19)
release: 1.84.1
commit-hash: 66221abdeca2002d318fde6efff516aab091df0e
commit-date: 2024-11-19
host: aarch64-apple-darwin
libgit2: 1.8.1 (sys:0.19.0 vendored)
libcurl: 8.7.1 (sys:0.4.74+curl-8.9.0 system ssl:(SecureTransport) LibreSSL/3.3.6)
ssl: OpenSSL 1.1.1w  11 Sep 2023
os: Mac OS 15.3.1 [64-bit]

compiles the original code with just a warning:

cargo build
   Compiling overev v0.1.0 (/Users/rod/code/rust/triage/overev)
warning: struct `Nil` is never constructed
 --> src/main.rs:2:8
  |
2 | struct Nil;
  |        ^^^
  |
  = note: `#[warn(dead_code)]` on by default

warning: `overev` (bin "overev") generated 1 warning
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 3.63s

So no overflow or other error, I think this issue can be closed.

@WaffleLapkin WaffleLapkin added E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. E-needs-bisection Call for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc labels Feb 15, 2025
@WaffleLapkin
Copy link
Member Author

WaffleLapkin commented Feb 15, 2025

Indeed, the issue seems to be fixed. Still, it'd be interesting to see which PR fixed the issue, and add test(s) in case the PR which fixed this did not have similar tests already. Tagging this issue appropriately.

@WaffleLapkin WaffleLapkin added the T-types Relevant to the types team, which will review and decide on the PR/issue. label Feb 15, 2025
@moxian
Copy link
Contributor

moxian commented Mar 25, 2025

Bisects to #130654
I believe there is appropriate test coverage in that PR as well, but I might be misreading this.

@rustbot label: -E-needs-bisection +S-has-bisection +A-coherence

@rustbot rustbot added S-has-bisection Status: a bisection has been found for this issue A-coherence Area: Coherence and removed E-needs-bisection Call for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc labels Mar 25, 2025
@WaffleLapkin WaffleLapkin removed the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Apr 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-associated-items Area: Associated items (types, constants & functions) A-coherence Area: Coherence C-bug Category: This is a bug. S-has-bisection Status: a bisection has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

6 participants