-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Dynamically sized type parameter syntax #357
Comments
I agree and would really like to see a proper DST RFC surface and be discussed by the community so we can iron-out kinks like this one and have an official "source of truth" for what DST is, why it's being added to Rust, and what the exact features it brings are. This is just one small issue that could be clarified with a real RFC. |
To give a bit of background on the naming, we need a name which means 'maybe sized' rather than 'unsized', since we are relaxing the 'Sized' bound rather than asserting the type is definitely not sized. Thus OTOH, no-one is really happy with the |
I agree that it would be good to have some syntax that works with Regarding the positioning of the tokens here: My recollection was that there was one particularly good reason for a generalization marker like A concrete example:
In the case of In the case of These are complete opposites in terms of the reasoning involved. A statement like "having a bound (sic) before the parameter is pretty weird" just re-enforces this point to me: These are weird. A weird syntax is appropriate. You should have to think a little harder when encountering it. |
Considering the |
@pnkfelix This is all the more reason to have an RFC. You've expressed a strong and intelligent design rationale for the way things are, just the sort of thing that should go in an RFC. The design rationale for DST was never really covered anywhere, and I know I'm not alone in just being lost at trying to understand how DST works, why we have it, what problems it solves, why it looks this way, how do I use it, &c. An RFC would really help inform the community about all of these things. |
I think this is basically settled now. Closing. |
The current syntax for denoting a dynamically-sized type parameter is
Sized? T
. This acts as a way of removing the implicitSized
bound that all type parameters have by default. This has the nice advantage of being open to adding other default trait bounds in the future with a similar syntax for opting out. (Drop
could be one: uninitialised pointers are not able to be dropped, but everything else is.) However, to me it seems inconsistent with the syntax for normal bounds, which come after the type parameter name. It also can’t be used in awhere
clause, unlike everything else applied to type parameters. Because DST never went through a proper RFC, and the syntax for DSTs has changed twice, it would be nice if we could get some proper feedback on want the syntax should actually be. I personally preferT: Sized?
, but perhaps other people will have other ideas.For the record, here are the different syntaxes we’ve gone through:
unsized T
: the original, obvious syntaxtype T
: there was a blog post on thisSized? T
: the current syntaxSized
bound normally present in all type parameters optionalThe text was updated successfully, but these errors were encountered: