Skip to content

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

Description

@aturon

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`

Activity

  1. aturon commented on Nov 16, 2016

    @aturon
    ContributorAuthor
  2. nikomatsakis commented on Nov 16, 2016

    @nikomatsakis
    Contributor

    Note that this version works: https://is.gd/MIFVFg

    (Removing the A)

  3. estebank commented on Oct 9, 2019

    @estebank
    Contributor

    #65192 suggests impl<A, T: Parent<Ty = A>> Parent for ParentWrapper<T> where <T as Parent>::Assoc: Child<A> { /* ... */}, which compiles.

  4. added
    A-associated-itemsArea: Associated items (types, constants & functions)
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Oct 10, 2019
  5. added 2 commits that reference this issue on Oct 19, 2019
  6. estebank commented on Feb 2, 2021

    @estebank
    Contributor

    This now compiles.

  7. added
    E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.
    on Feb 2, 2021
  8. added 2 commits that reference this issue on Feb 2, 2021
    5f1616d
    81c64b3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-associated-itemsArea: Associated items (types, constants & functions)A-lazy-normalizationArea: Lazy normalization (tracking issue: #60471)A-trait-systemArea: 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