-
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
Namespaced enums are weird in regard to generic paramters #22486
Comments
nominating for discussion at triage meeting. Sounds like there might be a 1.0 issue to address here. |
@alexcrichton points out that it is nice to write But it does seem like an inconsistency, i.e. a wart. P-backcompat-lang, 1.0 beta, I-needs-decision. |
Yeah, the ability to have |
This is not clearly an inconsistency. It depends on how you view enums. In particular, at least under some of the "virtual struct" proposals, enums were kind of "shorthand" for something like:
in which case the current behavior seems perfectly consistent. |
We are going to keep our current syntax/semantics, largely because we like being able to write e.g. |
I just spent some time running into this issue. I agree it was the right decision not to block 1.0 on it, but does that mean the issue will never be addressed? I think the turbofish syntax should also be supported for orthogonality, since it is not at all clear to new Rustaceans such as myself that an enum should be thought of differently. |
I would be open to an RFC proposing a solution, but I don't think it's a priority for us on the lang-team -- happy to discuss it a bit though if you'd like to drive it! Maybe open a thread on internals? |
@nikomatsakis I would love to land a feature (even a tiny one)! Question: does it not being a priority for the lang team (understandable, given all the work going on) mean that even if we hash out a solution and I am able to implement it (neither being a given, you understand ;)) that it would still be unlikely to make it into the codebase? Or does it simply mean the team has limited available cycles for hashing out the feature and implementing it themselves? Thank you for the invitation, @nikomatsakis. 👍 |
@U-007D
This is what I meant, in this case. |
I'd also be very interested in additionally allowing the normal turbofish syntax for variants of generic enums (e.g. And it's very inconsistent/weird having to write I want to be able to write I'd be willing to write a RFC for this. I haven't written a RFC before, but read a lot of RFCs, this one seems to be a good "first RFC" to write, right? Btw, I also wish accessing variants would work for aliased (monomorphized) enums, e.g.: type Foo = MyGenericEnum<i32, usize>;
...
let x = Foo::MyVariant(y); And also for aliased (still generic) enums, e.g.: type Foo = MyGenericEnum;
...
let x = Foo::<i32, usize>::MyVariant(y); |
@Boscop agreed--it would be nice for this to be consistent. I'm wrapping up another small Rust feature and have started a new job, so this is all yours, if you want it. Thanks for taking this on! |
See here for some updates on this topic.
|
Enum variants are namespaced now, but applying generic paramters to them in expressions still works as before, which means the correct way to type annotate a
Option
in a expression is to do this:However, this is inconsistent with other namespaced constructs, like this:
Generally, type parameters of an item are supposed to go on that item in a path, but for enum variants this is not the case.
As a backward compatible solution to this, enum variants could be made to work similar to associated items of traits:
The text was updated successfully, but these errors were encountered: