-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Combining explicit T: Sized and T: ?Sized bounds is silently accepted and results in T: Sized. #25776
Comments
cc @nikomatsakis @pnkfelix @brson Is this considered a bug? |
Certainly the current semantics (that a lint seems like a good idea to me. I wouldn't want a hard error due to potential for macros to expand into such combinations. |
@pnkfelix what about the backwards compatibility issues? How do lints interact with stability guarantees? |
@eddyb my understanding is that we are allowing warning lints to start or stop firing with arbitrary releases of Rust; i.e. that there are no guarantees with respect to the stability of lints (or at least of lints that are not set to error-by-default; not sure how many of those we actually have). The other supposed backwards compatibility issue you raise (or, if you prefer, the main such issue) is this:
But my understanding is that this would solely allow more code to compile than before -- it won't cause any potential code to start being rejected, right? I ask because as I understand it, such a change is also not a backwards-compatibility hazard. (Interestingly, I don't think the current draft rust-lang/rfcs#1122 actually attempts to actually define backwards-compatibility hazards of this sort...) |
I was asking about lints being used to defend stability guarantees: i.e. can we make a backwards-incompatible change if the only uses would have required disabling an error-by-default lint? In my example |
Oh, of course |
So @pnkfelix raised this question of the fact that First, Copy today combines two things: "affine" and "can be memcpy". We've thought about separating this in the past ( I personally expect unsized values to be affine. Currently, they can never be moved by the compiler, but the only way that they could that I can see is we passed a pointer into the current location (since the size is not known to the compiler at compilation time). I've described this before as permitting unsized values to be passed as parameters. This only makes sense if all unsized things are affine, because otherwise when the callee mutates the value, it will mutate a copy that the caller can see, which violates the mental model. If we did support moves, then you could move a It seems like wanting to copy/clone a Finally, we could add a |
I don't think there is an actual bug here... going to close. Re-open if you disagree. |
The above results in no warning or error in 1.0 and 1.1.
While this may seem harmless, the
Sized
bound can be propagated from a trait:This is a backwards-compatibility hazard, as
NotObjectSafe
cannot be made object-safe (by addingwhere Self: Sized
to each method which requires it) without causingNotObjectSafe + ?Sized
to start allowing unsized types forT
, where it previously wouldn't have.A concrete example is
trait Clone: Sized
which I believe could be object-safe if theSized
bound was moved to its two methods.Clone: Sized
prevents, e.g.[T]: Copy where T: Copy
which could be used to write constructors forRc<[T]>
(and perhaps even forRc<Trait+Copy>
).It's also arguably unintuitive, as
?Sized
has no effect but it may show up in documentation, advertising an usecase which isn't actually supported.The text was updated successfully, but these errors were encountered: