Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign uplibrustc: Implement associated types behind a feature gate. #16377
Conversation
pcwalton
referenced this pull request
Aug 13, 2014
Merged
RFC: associated items and multidispatch #195
This comment has been minimized.
This comment has been minimized.
|
Awesome! Would it be that much harder to add associated statics? |
This comment has been minimized.
This comment has been minimized.
ptal
commented
Aug 13, 2014
|
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 |
This comment has been minimized.
This comment has been minimized.
|
Yes, associated statics will be a lot of work and this patch is already 5+ KLOC. |
This comment has been minimized.
This comment has been minimized.
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. |
This comment has been minimized.
This comment has been minimized.
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. |
This comment has been minimized.
This comment has been minimized.
|
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 comment has been minimized.
This comment has been minimized.
nmsmith
commented
Aug 20, 2014
|
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. |
pcwalton
force-pushed the
pcwalton:associated-items
branch
3 times, most recently
from
987e30b
to
e797049
Sep 9, 2014
This comment has been minimized.
This comment has been minimized.
|
Updated with the syntax from the RFC. re-r? @nikomatsakis |
This comment has been minimized.
This comment has been minimized.
|
Very exciting stuff. I'm testing the PR at yesterday's version (commit e797049 ) Here are some bug reports already: Inheriting has a bug:
And |
This comment has been minimized.
This comment has been minimized.
|
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.) |
This comment has been minimized.
This comment has been minimized.
|
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 |
This comment has been minimized.
This comment has been minimized.
|
Reviewing latest push now (FYI) |
This comment has been minimized.
This comment has been minimized.
|
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 |
This comment has been minimized.
This comment has been minimized.
|
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 |
This comment has been minimized.
This comment has been minimized.
|
@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 |
pcwalton
force-pushed the
pcwalton:associated-items
branch
3 times, most recently
from
60a88a0
to
13c5acb
Sep 16, 2014
This comment has been minimized.
This comment has been minimized.
|
@nikomatsakis Ambiguity (and, relatedly, scoping) rules addressed. re-r? |
pcwalton
force-pushed the
pcwalton:associated-items
branch
from
13c5acb
to
78a8418
Sep 17, 2014
This comment has been minimized.
This comment has been minimized.
|
r=nikomatsakis |
This comment has been minimized.
This comment has been minimized.
|
saw approval from nikomatsakis |
This comment has been minimized.
This comment has been minimized.
|
merging pcwalton/rust/associated-items = 78a8418 into auto |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
fast-forwarding master to auto = 9508faa |
bors
added a commit
that referenced
this pull request
Sep 17, 2014
bors
closed this
Sep 18, 2014
This comment has been minimized.
This comment has been minimized.
|
@pcwalton I guess this doesn't cover bounds on associated types? |
pcwalton
deleted the
pcwalton:associated-items
branch
Sep 18, 2014
This comment has been minimized.
This comment has been minimized.
|
@bgamari No, it doesn't. I believe @nikomatsakis is working on generalized where clauses, which should make that more straightforward to implement. |
This comment has been minimized.
This comment has been minimized.
|
Did you mean to revert jemalloc? |
This comment has been minimized.
This comment has been minimized.
|
No, I'll fix that. |
pcwalton commentedAug 9, 2014
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)