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

Redundant specification of associated types with bound by inheriting trait #57218

Closed
dhardy opened this issue Dec 30, 2018 · 3 comments
Closed
Labels
A-trait-system Area: Trait system A-type-system Area: Type system C-feature-request Category: A feature request, i.e: not implemented / a PR.

Comments

@dhardy
Copy link
Contributor

dhardy commented Dec 30, 2018

Given traits:

trait A {
    type X;
}
trait C: A<X = u32> {}

the compiler does enforce that types implementing C have the required type for X, yet claims the associated type must still be specified when used (e.g. in &C).

https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=50ed977d59b2b0ab67effef5c84d810a


I would expect that it would be unnecessary (or even illegal) to specify the type of X twice hence consider this a bug. This limits API design: a trait like C cannot retroactively have a base trait with associated type like A added, and in any case requiring all users to write C<X = u32> or equivalent is undesirable.

Possibly such a change warrants an RFC, though since the extra type specification is redundant, not requiring it is not a breaking change. Making this change would however mean that an API cannot relax a constraint like X = u32 without the change being breaking (if a library uses trait C: A<X = u32> in its API but envisages switching to trait C: A in the future — seems unlikely).

@Centril Centril added A-type-system Area: Type system A-trait-system Area: Trait system C-feature-request Category: A feature request, i.e: not implemented / a PR. labels Dec 30, 2018
@Centril
Copy link
Contributor

Centril commented Dec 30, 2018

Seems like this would fall out of rust-lang/rfcs#1672?

@dhardy
Copy link
Contributor Author

dhardy commented Dec 31, 2018

Not sure; that seems to be mostly about mutually exclusive trait implementations. This is about forwarding a required bound.

@dhardy
Copy link
Contributor Author

dhardy commented Oct 5, 2019

This works on the latest stable, so we can close this.

@dhardy dhardy closed this as completed Oct 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-trait-system Area: Trait system A-type-system Area: Type system C-feature-request Category: A feature request, i.e: not implemented / a PR.
Projects
None yet
Development

No branches or pull requests

2 participants