-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Make the implicit type parameter Self
have no default Sized
bound
#546
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
Make the implicit type parameter Self
have no default Sized
bound
#546
Conversation
👍 Traits applicable to DST by default, and opt-out via the |
Hm... How does that interact with possible future default-implied traits? Eg, the hypothetical Specifically, would such an addition still require something similar to the |
@Kimundi I can't speak for other default types, but I think For starters, I believe that if it is defined correctly, (For a more direct demonstration that this is supposed to be the case, by abusing In current Rust, the reverse is also true ( The biggest problem with this is that I see is that the name Is this thought worth pursuing? Should we consider renaming |
@pythonesque I intend to allow unsized types to be moved (via parameter passing only) in the future. It simplifies and cleans up a lot of things. |
Ah, okay, interesting. That line of reasoning doesn't work, then :P Anyway, I like the RFC. It seems much saner. |
You say it only affects default implementations; does that mean it doesn't prevent traits not inheriting Sized from having methods taking or returning values of type Self? |
@comex at the moment, it does not, no. There was some discussion about this point at the weekly meeting, though of course the minutes don't cover it in detail (sigh, taking minutes is hard). The compiler as implemented today, at least, only enforces sizedness of parameters (and some other criteria) on the impl side, or at least only on fns with bodies. Going forward, I'd like generally to move to implied bounds which would formalize this idea even further (but of course that's not been formally proposed). |
What if input trait parameters also had no Size bound? Trait params would be different from other type params, but at least they would be consistent with Self. |
Though this RFC has been up a short time, and hasn't had a great deal of discussion, it needs to be done fast and most people I've heard from seem to be in favor. Merged. Tracking. |
Summary
Sized
default for the implicitly declaredSelf
parameter on traits.
Sized
.Motivation
The primary motivation is to enable a trait object
SomeTrait
toimplement the trait
SomeTrait
. This was the design goal of enforcingobject safety, but there was a detail that was overlooked, which this
RFC aims to correct.
Secondary motivations include:
impl Trait for ?Sized
syntax.
?Sized
default is inheritedlike other supertrait bounds that appear in a similar position.
This change has been implemented. Fallout within the standard library
was quite minimal, since the default only affects default method
implementations.
Rendered view.