-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Add a compiler check that std::mem::size_of
isn’t called on unsized types?
#80795
Comments
0 is the lower bound on the dereferencable size for references to unsized types as told to LLVM. |
FWIW, given that this relies on the coherence bug, I think trying to fix this is a game of whack-a-mole... we already check that |
OTOH, I guess if it's as easy as this check then it doesn't really hurt either.^^ |
it looks like we already implement the check described here. Don't think that we need to add a test for this. |
There's still a bug though, see #79047. |
yeah, but that bug isn't tracked by this issue, is it? |
Not sure... the bug that the original code here leads to invalid MIR remains. |
while this is true, that bug is tracked as part of #57893 |
For the record, I’m of the opinion that it’s correct that this issue is closed. |
Wait.. actually, I’m confused: Why exactly does it hit “SizeOf nullary MIR operator called for unsized type” now and didn’t before? Which one was the relevant change? That line that triggers the “SizeOf nullary MIR operator called for unsized type” message seems to be pretty old already.. |
This has nothing to do with #57893. rustc is showing an error after all. I would not have accepted a Miri patch that just works around that coherence issue. The problem is that rustc produces MIR despite their being a type error, and then runs CTFE on that broken MIR. This is tracked in #79047 for |
ah yeah, rustc trying to eval broken mir seems like a separate bug to me. |
While re-discovering #57893 (in #80783) and in particular while poking around in the world of all the wonderful ICEs that you can get once you’ve convinced the compiler that a trait object is actually
Sized
, I noticed that callingsize_of
does actually still compile without any error. It returns0
, e.g. see this example:I wonder what that value of
0
is good for! Couldn’t it raise an ICE instead?@rustbot modify labels: T-compiler, C-enhancement, A-dst
The text was updated successfully, but these errors were encountered: