Skip to content

overflow evaluating the requirement of ... #47393

Closed
@Andlon

Description

@Andlon

I ran into some problems when attempting to get a blanket implementation for a trait of mine given certain requirements. I managed to reduce my code to the minimal example below.

trait Constraint {
    type Strategy;
}

impl Constraint for () {
    type Strategy = ();
}

struct Foo<T>(T);

impl<A> Constraint for Foo<A>
where
    A: Constraint,
{
    type Strategy = Foo<Option<A::Strategy>>;
}

impl<T> Constraint for Option<T>
where
    T: Constraint,
{
    type Strategy = Option<T::Strategy>;
}

trait DataStructure {
    type Constraint: Constraint;
}

impl<C> DataStructure for C
where
    C: Constraint<Strategy = C>,
{
    type Constraint = ();
}

impl<A> DataStructure for Foo<A>
where
    A: DataStructure,
{
    type Constraint = A::Constraint;
}

fn main() {}

I don't know too much about Rust internals, and I'm not really sure if this should be allowed, but I had perhaps expected that no actual recursion could occur in this case. What I get is the following compiler error:

error[E0275]: overflow evaluating the requirement `<std::option::Option<_> as Constraint>::Strategy`
  |
  = help: consider adding a `#![recursion_limit="128"]` attribute to your crate

error: aborting due to previous error

Rust compiler information:

rustc 1.23.0 (766bd11c8 2018-01-01)
binary: rustc
commit-hash: 766bd11c8a3c019ca53febdcd77b2215379dd67d
commit-date: 2018-01-01
host: x86_64-unknown-linux-gnu
release: 1.23.0
LLVM version: 4.0

Here's a playground link which demonstrates the issue: https://play.rust-lang.org/?gist=6d0b7b03aec50245d24de119f57dcafa&version=stable

I'm sorry if this has reported before. I searched and found many similar problems, but I simply don't have enough knowledge about the Rust internals to determine if it's the same problem or not.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions