Overflow evaluating the requirement with a where clause on associated type · Issue #87755 · rust-lang/rust (original) (raw)

I tried this code (playground):

#![feature(generic_associated_types)]

use std::fmt::Debug;

trait Foo { type Ass where Self::Ass: Debug; }

#[derive(Debug)] struct Bar;

impl Foo for Bar { type Ass = Bar; }

Note that while it doesn't use GATs, it requires feature(generic_associated_types) for the where clause on the associated type to be allowed.

I expected to see this happen: this should build without errors.

Instead, this happened:

error[E0275]: overflow evaluating the requirement `<Bar as Foo>::Ass == _`
  --> src/lib.rs:12:5
   |
12 |     type Ass = Bar;
   |     ^^^^^^^^^^^^^^^

For more information about this error, try `rustc --explain E0275`.

Error E0275 explanation uses this example:

trait Foo {}

struct Bar(T);

impl Foo for T where Bar: Foo {}

where indeed there's a recursive requirement that can't be checked in a small number of steps. Not so in my example: there's no recursion; Bar clearly implements Debug (and Foo).

@rustbot modify labels: +A-associated-items +F-generic_associated_types