Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
aturon opened this issue Nov 16, 2016 · 4 comments · Fixed by #81671
Closed

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

aturon opened this issue Nov 16, 2016 · 4 comments · Fixed by #81671
Labels
A-associated-items Area: Associated items (types, constants & functions) A-lazy-normalization Area: Lazy normalization (tracking issue: #60471) A-trait-system Area: Trait system C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@aturon
Copy link
Member

aturon commented Nov 16, 2016

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`
@aturon aturon added the A-trait-system Area: Trait system label Nov 16, 2016
@aturon
Copy link
Member Author

aturon commented Nov 16, 2016

cc @nikomatsakis

@nikomatsakis
Copy link
Contributor

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

(Removing the A)

@estebank
Copy link
Contributor

estebank commented Oct 9, 2019

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

@jonas-schievink jonas-schievink added A-associated-items Area: Associated items (types, constants & functions) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 10, 2019
Centril added a commit to Centril/rust that referenced this issue Oct 19, 2019
…asper

Use structured suggestion for restricting bounds

When a trait bound is not met and restricting a type parameter would
make the restriction hold, use a structured suggestion pointing at an
appropriate place (type param in param list or `where` clause).

Account for opaque parameters where instead of suggesting extending
the `where` clause, we suggest appending the new restriction:
`fn foo(impl Trait + UnmetTrait)`. Fix rust-lang#64565, fix rust-lang#41817, fix rust-lang#24354,
cc rust-lang#26026, cc rust-lang#37808, cc rust-lang#24159, fix rust-lang#37138, fix rust-lang#24354, cc rust-lang#20671.
Centril added a commit to Centril/rust that referenced this issue Oct 19, 2019
…asper

Use structured suggestion for restricting bounds

When a trait bound is not met and restricting a type parameter would
make the restriction hold, use a structured suggestion pointing at an
appropriate place (type param in param list or `where` clause).

Account for opaque parameters where instead of suggesting extending
the `where` clause, we suggest appending the new restriction:
`fn foo(impl Trait + UnmetTrait)`. Fix rust-lang#64565, fix rust-lang#41817, fix rust-lang#24354,
cc rust-lang#26026, cc rust-lang#37808, cc rust-lang#24159, fix rust-lang#37138, fix rust-lang#24354, cc rust-lang#20671.
@estebank estebank added the F-associated_type_bounds `#![feature(associated_type_bounds)]` label Nov 5, 2019
@matthewjasper matthewjasper added the A-lazy-normalization Area: Lazy normalization (tracking issue: #60471) label Jul 11, 2020
@estebank
Copy link
Contributor

estebank commented Feb 2, 2021

This now compiles.

@estebank estebank added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Feb 2, 2021
@jackh726 jackh726 removed the F-associated_type_bounds `#![feature(associated_type_bounds)]` label Feb 2, 2021
jackh726 added a commit to jackh726/rust that referenced this issue Feb 2, 2021
@bors bors closed this as completed in 81c64b3 Feb 3, 2021
@fmease fmease added A-trait-system Area: Trait system and removed A-trait-system Area: Trait system labels Dec 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-associated-items Area: Associated items (types, constants & functions) A-lazy-normalization Area: Lazy normalization (tracking issue: #60471) A-trait-system Area: Trait system C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants