Skip to content

overflow evaluating the requirement of ... #47393

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
Andlon opened this issue Jan 12, 2018 · 1 comment
Closed

overflow evaluating the requirement of ... #47393

Andlon opened this issue Jan 12, 2018 · 1 comment

Comments

@Andlon
Copy link

Andlon commented Jan 12, 2018

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.

@sgrif
Copy link
Contributor

sgrif commented Jan 19, 2018

This is a duplicate of/related to #34260

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants