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

E0207 when type parameter's associated type is used in Self. #64155

Open
alex-ozdemir opened this issue Sep 4, 2019 · 3 comments
Open

E0207 when type parameter's associated type is used in Self. #64155

alex-ozdemir opened this issue Sep 4, 2019 · 3 comments
Labels
A-associated-items Area: Associated items (types, constants & functions) A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@alex-ozdemir
Copy link
Contributor

Not sure if this needs to be an error or not.

Per rustc --explain E0207, impl type parameter are acceptable if they appear in the Self type of the impl. Emphasis mine:

Any type parameter or lifetime parameter of an impl must meet at least one of
the following criteria:

  • it appears in the implementing type of the impl, e.g. impl<T> Foo<T>
  • for a trait impl, it appears in the implemented trait, e.g.
    impl<T> SomeTrait<T> for Foo
  • it is bound as an associated type, e.g. impl<T, U> SomeTrait for T where T: AnotherTrait<AssocType=U>

Rustc currently generates an error even if an associated type of the parameter appears in the Self type: playground link:

trait Field {}

trait Vector {
    type MyField: Field;
}

struct BaseFieldPrinter<F: Field>;

impl<V: Vector> BaseFieldPrinter<V::MyField> {
}

It seems like this doesn't need to be an error, but perhaps I'm missing something?

@alex-ozdemir alex-ozdemir changed the title E0207 when type parameter's associated type is used in a bound. E0207 when type parameter's associated type is used in Self. Sep 4, 2019
@estebank
Copy link
Contributor

estebank commented Sep 4, 2019

I think this will need to be written as impl<V: Vector, T> BaseFieldPrinter<T> where T: V::MyField {} once associated type bounds lands.

@estebank estebank added A-associated-items Area: Associated items (types, constants & functions) A-diagnostics Area: Messages for errors, warnings, and lints F-associated_type_bounds `#![feature(associated_type_bounds)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue. labels Sep 4, 2019
@Centril
Copy link
Contributor

Centril commented Sep 5, 2019

It seems like this doesn't need to be an error, but perhaps I'm missing something?

Seems like "appears" needs to be clarified. In your snippet it appears in a projection which in turn appears in the implementing type but that's not the same thing.

I think this will need to be written as impl<V: Vector, T> BaseFieldPrinter<T> where T: V::MyField {} once associated type bounds lands.

T: V::MyField would be bounding T by an associated trait. This is entirely unrelated to associated_type_bounds (Trait<Assoc: Bound>) which are just a short-hand.

@Centril Centril removed F-associated_type_bounds `#![feature(associated_type_bounds)]` T-lang Relevant to the language team, which will review and decide on the PR/issue. labels Sep 5, 2019
@estebank
Copy link
Contributor

Current output:

error[E0207]: the type parameter `V` is not constrained by the impl trait, self type, or predicates
 --> src/lib.rs:9:6
  |
9 | impl<V: Vector> BaseFieldPrinter<V::MyField> {
  |      ^ unconstrained type parameter

@crlf0710 crlf0710 added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Jun 11, 2020
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-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants