Skip to content

Constraining one associated type doesn't normalize the bounds on others #37808

Closed

Description

The trait system seems to be missing a normalization in bounds for associated items:

trait Parent {
    type Ty;
    type Assoc: Child<Self::Ty>;
}

trait Child<T> {}

struct ChildWrapper<T>(T);
impl<A, T> Child<A> for ChildWrapper<T> where T: Child<A> {}

struct ParentWrapper<T>(T);
impl<A, T: Parent<Ty = A>> Parent for ParentWrapper<T>
{
    type Ty = A;
    type Assoc = ChildWrapper<T::Assoc>;
}

produces the error:

error[E0277]: the trait bound `<T as Parent>::Assoc: Child<A>` is not satisfied
  --> wrapper.rs:12:1
   |
12 | impl<A, T: Parent<Ty = A>> Parent for ParentWrapper<T>
   | ^ the trait `Child<A>` is not implemented for `<T as Parent>::Assoc`
   |
   = help: consider adding a `where <T as Parent>::Assoc: Child<A>` bound
   = note: required by `Parent`

error[E0277]: the trait bound `<T as Parent>::Assoc: Child<A>` is not satisfied
  --> wrapper.rs:15:5
   |
15 |     type Assoc = ChildWrapper<T::Assoc>;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Child<A>` is not implemented for `<T as Parent>::Assoc`
   |
   = help: consider adding a `where <T as Parent>::Assoc: Child<A>` bound
   = note: required by `Parent`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    A-associated-itemsArea: Associated items (types, constants & functions)A-lazy-normalizationArea: Lazy normalization (tracking issue: #60471)A-traitsArea: Trait systemC-bugCategory: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.T-compilerRelevant to the compiler 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