-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Implement equality constraints in where clauses #22074
Conversation
Tidy errors: https://travis-ci.org/rust-lang/rust/builds/49909684 |
@sfackler yeah I just saw them, waiting on a local |
@jroesch so this looks great, as far as it goes. The reason though that I've been avoiding implementing (or suggesting we implement) this feature goes a bit beyond the parsing. In particular, there are several scenarios that will not (I think) work as expected with this patch. One is that this will not affect the normalization code, so something like: fn foo<T:Iterator>(t: T) -> u32
where T::Item = u32
{
t.next().unwrap()
} will fail to type-check. Similarly, this won't work if you equate random type parameters: fn foo<A,B>(a: A) -> B
where A = B
{
a
} I'm not necessarily opposed to landing this patch: it's still a handy feature and it's good to have the parsing code etc in place. But I would at minimum want to land it feature-gated. I've been doing research into the best way to restructure our code so that we can support examples like the ones above, but changes in that area are beyond the scope of the present release milestones, I think. |
@nikomatsakis I has a suspicion this may be true, but couldn't sleep the other night and needed something to work on ;). I will feature gate this and we can land it in its imperfect form if that works. |
I read |
@Stebalien internally The above example: where T::Item = u32 when fully expanded is really: where <T as Iterator>::Item = u32 which is the same as: where T : Iterator<Item=u32> |
|
@nikomatsakis are you still in favor of landing this with a gate? |
The change from |
This is old so going to close. I'll be in touch with @jroesch with respect to rebasing and reimplementing this work. |
@nikomatsakis @jroesch Did this go anywhere? |
I haven't had a ton of cycles to work on Rust lately. I did just catch up with @nikomatsakis in Paris, and we talked about this issue briefly. I think this should be implementable in the new forthcoming trait engine. |
This fixes #20041. I was thinking that the necessary machinery this required must be in place for associated types. So I went ahead and implemented the parsing and translation in collect when I was bored last night.
I currently have syntax of the form:
where A = T
since it seemed cleaner, as well as consistent with the associated types syntax ofFoo<A=T>
while not introducing ambiguity. If that is not what we want I'm happy to use the==
syntax originally present in the RFC.r? @nikomatsakis
I think this should cover everything let me know otherwise.
cc @darinmorrison