Skip to content

Associated types and supertraits #19541

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

Closed
nrc opened this issue Dec 4, 2014 · 0 comments · Fixed by #20572
Closed

Associated types and supertraits #19541

nrc opened this issue Dec 4, 2014 · 0 comments · Fixed by #20572
Labels
A-associated-items Area: Associated items (types, constants & functions)

Comments

@nrc
Copy link
Member

nrc commented Dec 4, 2014

These basically don't work well together. The following works:

pub trait Bar {
    type B;
}

pub trait Foo: Bar<A=int> {
    type A;
}

The following gives an error (the wrong error too), but should compile:

pub trait Bar {
    type B;
}

pub trait Foo: Bar {
    type A;
}

In this case, B should be treated like an associated type on Foo.

I am not sure if type B = int or even type B: Baz should be allowed in Foo, but I assume not (at least for now).

When the above works, we should require super trait associated types are given in type bindings, e.g., Foo<A=int, B=int>.

We should also allow Self::B in the body of Foo and if type T has bound Foo, then we should allow T::B.

@nrc nrc added the A-associated-items Area: Associated items (types, constants & functions) label Dec 4, 2014
bors added a commit that referenced this issue Jan 5, 2015
The first few commits in the PR are just general refactoring. I was intending them for some other code I didn't get around to writing yet, but might as well land them now. 

cc @japaric

Fixes #19541
lnicola pushed a commit to lnicola/rust that referenced this issue Apr 28, 2025
fix(auto-import): Prefer imports of matching types for argument lists
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)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant