-
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
Consider making common traits object-safe #1468
Comments
I personally don't agree with this. Removing the sized bounds on these traits by moving them onto their relevant methods really destroys the semantic meaning of the trait. Clone is for values that can copy themselves. Default is for types for which a default value can always be produced. Implementing this suggestion is basically adding an asterisk to each of those descriptions reading "...except not always". While derived implementations of The contracts of these traits really do hinge on the types being sized. Changing that will only cause people more confusion. |
Type parameters that are bound with these traits are already The implication for code like this: trait Default {
fn default() -> Self where Self: Sized;
}
trait Foo: Default {
...
} is that all types that implement |
👍, these bounds are essentially unnecessary. |
Once unsized by-value exists, it seems like the best approach would be to remove the |
This feels like it could be useful but I can't think of any actual use cases. What was your motivation? |
@Stebalien I came across this while experimenting with a trait hierarchy in https://github.com/apasel422/eclectic, and it would be nice to reuse the existing traits instead of creating ad-hoc methods (e.g. But it might be better to hold off on any changes related to this until we have a clearer picture of how the by-value unsized stuff works. |
Sadly, this is not backwards-compatible due to rust-lang/rust#25776. |
@eddyb I believe this regression is small enough for the price being worth paying. |
@ticki It's actually even worse, because EDIT: Apparently it needs to be |
I'm trying this for a crater run. (There's already fallout within the compiler so I'm not expecting an easy ride.) It seems that |
We shouldn't go ahead with this if DST moves are going to happen: rust-lang/rust#20021 (comment). |
Does DST-by-value just eliminate object safety as a concern? |
Keep in mind you can't just return a DST. There is a hack where you magically pass an |
Just hit a use case where I want to have an argument of type I have an AstNode trait. It is Now I want to process all There are several workarounds which I could use here, but it would be really nice if this just worked :) |
If |
The following traits have
Sized
as a supertrait:Clone
Default
From
FromStr
Into
The bound on the first four can be moved from the trait to a method-level where clause, while the bound on
Into
can be removed entirely.Doing this has the benefit of allowing otherwise object-safe traits to use these as a supertrait, but has the drawback of being a breaking change (albeit one that I doubt affects much code).
These other traits also extend
Sized
, but are unstable:One
Step
Zero
The text was updated successfully, but these errors were encountered: