rust-lang / rust-lang/rust

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

Open
#117,606 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-GATs F-associated_type_defaults T-types
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

#![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`.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the example in the mentioned test, $DIR/assume-gat-normalization-for-nested-goals.rs, and compare its behavior before and after #117542. Trace the GAT normalization and nested-goal handling involved in the reported E0277; done means the example compiles without requiring the suggested additional bound.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.