Skip to content

Failure to assume GAT normalization holds when proving GAT bounds in impl #117606

Open
@compiler-errors

Description

@compiler-errors
#![feature(associated_type_defaults)]

trait Foo {
    type Bar<T>: Baz<Self> = i32;
    // We should be able to prove that `i32: Baz<Self>` because of
    // the impl below, which requires that `Self::Bar<()>: Eq<i32>`
    // which is true, because we assume `for<T> Self::Bar<T> = i32`.
}

trait Baz<T: ?Sized> {}
impl<T: Foo + ?Sized> Baz<T> for i32 where T::Bar<()>: Eq<i32> {}
trait Eq<T> {}
impl<T> Eq<T> for T {}

fn main() {}

This code should pass, but it doesn't after #117542.

Instead, it fails with:

error[E0277]: the trait bound `<Self as Foo>::Bar<()>: Eq<i32>` is not satisfied
  --> $DIR/assume-gat-normalization-for-nested-goals.rs:6:30
   |
LL |     type Bar<T>: Baz<Self> = i32;
   |                              ^^^ the trait `Eq<i32>` is not implemented for `<Self as Foo>::Bar<()>`
   |
note: required for `i32` to implement `Baz<Self>`
  --> $DIR/assume-gat-normalization-for-nested-goals.rs:13:23
   |
LL | impl<T: Foo + ?Sized> Baz<T> for i32 where T::Bar<()>: Eq<i32> {}
   |                       ^^^^^^     ^^^                   ------- unsatisfied trait bound introduced here
note: required by a bound in `Foo::Bar`
  --> $DIR/assume-gat-normalization-for-nested-goals.rs:6:18
   |
LL |     type Bar<T>: Baz<Self> = i32;
   |                  ^^^^^^^^^ required by this bound in `Foo::Bar`
help: consider further restricting the associated type
   |
LL | trait Foo where <Self as Foo>::Bar<()>: Eq<i32> {
   |           +++++++++++++++++++++++++++++++++++++

error: aborting due to previous error

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-GATsArea: Generic associated types (GATs)F-associated_type_defaults`#![feature(associated_type_defaults)]`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