Skip to content

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

Closed
@WaffleLapkin

Description

@WaffleLapkin

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-associated-itemsArea: Associated items (types, constants & functions)A-coherenceArea: CoherenceC-bugCategory: This is a bug.S-has-bisectionStatus: a bisection has been found for this issueT-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