-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
librustc: Implement associated types behind a feature gate. #16377
Conversation
Awesome! Would it be that much harder to add associated statics? |
This is great! I have tried to use it but faced some bugs.
And finally just a remark, it is a bit cumbersome to prefix types that are declared in the trait with the current trait type, but maybe if it has some implications for the type-checking. If not, it could be cool to have the same shortcut for inherited associated types if there is no ambiguity. All my tries has been done with this version of the compiler. It's not specified in the code snippets but I used |
Yes, associated statics will be a lot of work and this patch is already 5+ KLOC. |
There's no reason for it other than the fact that this is what the compiler already had support for. This patch is already huge so I'd like to implement that in a followup. |
Good catch. That should be an error (because you didn't have a generic type parameter), but instead it ICE'd. You won't be able to do what you want until both this patch and #16432 land. |
I guess associated statics are easier to add to APIs in a backwards compatible way than associated types. This is still awesome nonetheless - I am super excited about using this in gfx-rs and cgmath-rs. |
This is awesome, I've been looking forward to associated types. I've also found need for associated statics/constants, so I hope to see that implemented in the future. |
987e30b
to
e797049
Compare
Updated with the syntax from the RFC. re-r? @nikomatsakis |
Very exciting stuff. I'm testing the PR at yesterday's version (commit e797049fe ) Here are some bug reports already: Inheriting has a bug:
And |
I'd like to do the where clause stuff in a followup since this patch is getting pretty big. (Also it may depend on trait reform.) |
If you forget the associated type in an #![feature(associated_types)]
trait Borrow {
type Owned;
fn borrow<'a>(&'a Borrow::Owned) -> &'a Self;
}
impl Borrow for int {
//type Owned = int;
fn borrow(_: &int) -> &int {
unimplemented!();
}
}
fn main() {} Output: ai.rs:9:6: 9:12 error: internal compiler error: ImplCtxt::associated_type_binding(): didn't find associated type
ai.rs:9 impl Borrow for int { Version: This PR on top of 1dc3195 |
Reviewing latest push now (FYI) |
OK, I more-or-less read through the PR and it all seems to make sense. I'm doing a local build to do some more local testing. It's clear that the PR implements only a subset of what is described in the RFC (e.g., I don't believe that notation like |
On the ride home, it occurred to me that some of the tests seemed to be in error. For example, I don't think it is intended that one can write (@aturon can confirm):
The problem is that |
@nikomatsakis Yes, that's right: the RFC does not give any special treatment to the trait name in the body of the trait, so That said, the full resolution/matching rules still need to be laid out; you and I should sit down and write that up as an RFC soon. (Interesting sidenote: under a possible HKT design, you could allow |
60a88a0
to
13c5acb
Compare
@nikomatsakis Ambiguity (and, relatedly, scoping) rules addressed. re-r? |
The implementation essentially desugars during type collection and AST type conversion time into the parameter scheme we have now. Only fully qualified names--e.g. `<T as Foo>::Bar`--are supported.
13c5acb
to
78a8418
Compare
This is waiting on an RFC, but this basic functionality should be straightforward. The implementation essentially desugars during type collection and AST type conversion time into the parameter scheme we have now. r? @nikomatsakis
@pcwalton I guess this doesn't cover bounds on associated types? |
@bgamari No, it doesn't. I believe @nikomatsakis is working on generalized where clauses, which should make that more straightforward to implement. |
Did you mean to revert jemalloc? |
No, I'll fix that. |
This is waiting on an RFC, but this basic functionality should be
straightforward. The implementation essentially desugars during type
collection and AST type conversion time into the parameter scheme we
have now.
r? @nikomatsakis
(addendum by
pnkfelix
: the feature gate's name isassociated_types
)