Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upCombining explicit T: Sized and T: ?Sized bounds is silently accepted and results in T: Sized. #25776
Comments
eddyb
added
the
A-dst
label
May 25, 2015
This comment has been minimized.
This comment has been minimized.
|
cc @nikomatsakis @pnkfelix @brson Is this considered a bug? |
brson
added
the
I-nominated
label
May 25, 2015
This comment has been minimized.
This comment has been minimized.
|
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. |
This comment has been minimized.
This comment has been minimized.
|
@pnkfelix what about the backwards compatibility issues? How do lints interact with stability guarantees? |
This comment has been minimized.
This comment has been minimized.
|
@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...) |
This comment has been minimized.
This comment has been minimized.
|
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 |
This comment has been minimized.
This comment has been minimized.
Oh, of course |
This comment has been minimized.
This comment has been minimized.
|
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 |
This comment has been minimized.
This comment has been minimized.
|
I don't think there is an actual bug here... going to close. Re-open if you disagree. |
eddyb commentedMay 25, 2015
The above results in no warning or error in 1.0 and 1.1.
While this may seem harmless, the
Sizedbound can be propagated from a trait:This is a backwards-compatibility hazard, as
NotObjectSafecannot be made object-safe (by addingwhere Self: Sizedto each method which requires it) without causingNotObjectSafe + ?Sizedto start allowing unsized types forT, where it previously wouldn't have.A concrete example is
trait Clone: Sizedwhich I believe could be object-safe if theSizedbound was moved to its two methods.Clone: Sizedprevents, e.g.[T]: Copy where T: Copywhich could be used to write constructors forRc<[T]>(and perhaps even forRc<Trait+Copy>).It's also arguably unintuitive, as
?Sizedhas no effect but it may show up in documentation, advertising an usecase which isn't actually supported.