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

Associated types of a subtrait must always be explicit even when a supertrait implementation implies the subtrait with specific associated types #40255

Closed
jimmycuadra opened this issue Mar 4, 2017 · 2 comments

Comments

@jimmycuadra
Copy link
Contributor

Imagine the following scenario:

There is a trait A that has many associated types. There are many functions in a program that take a Box<A> only with specific associated types. To avoid having to write out all this boilerplate (including importing all the associated types), I want to create an alias for A with these specific associated types. A type alias cannot work, because you can't do impl Foo for Bar where Foo is a type alias. Let's try subtraits:

trait A {
    type Assoc;
    // Pretend there are several more associated types here to make uses of `Box<A>` inconvenient.
}

trait B: A<Assoc=()> {}

fn takes_b(b: Box<B>) {}

This results in:

error[E0191]: the value of the associated type `Assoc` (from the trait `A`) must be specified
 --> src/lib.rs:8:19
  |
8 | fn takes_b(b: Box<B>) {}
  |                   ^ missing associated type `Assoc` value

This seems like it should work. Note that declaring B this way is valid, as the program compiles if takes_b is commented out.

@durka
Copy link
Contributor

durka commented Mar 4, 2017

see #24010 and #29328

@jimmycuadra
Copy link
Contributor Author

Thank you for linking those issues! I wasn't sure how to search for this issue cause I wasn't sure how to phrase the title/question. Closing this as a duplicate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants