-
Notifications
You must be signed in to change notification settings - Fork 13.3k
transmute
calculates incorrect size of some generic types involving pointers to T: ?Sized
.
#101084
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Labels
C-bug
Category: This is a bug.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
T-opsem
Relevant to the opsem team
Comments
transmute
does not correctly calculate size of some types.transmute
does not correctly calculate size of some generic types involving pointers to T: ?Sized
.
transmute
does not correctly calculate size of some generic types involving pointers to T: ?Sized
.transmute
calculates incorrect size of some generic types involving pointers to T: ?Sized
.
matthiaskrgr
added a commit
to matthiaskrgr/rust
that referenced
this issue
Jun 24, 2024
…li-obk transmute size check: properly account for alignment Fixes another place where ZST alignment was ignored when checking whether something is a newtype. I wonder how many more of these there are... Fixes rust-lang#101084
matthiaskrgr
added a commit
to matthiaskrgr/rust
that referenced
this issue
Jun 24, 2024
…li-obk transmute size check: properly account for alignment Fixes another place where ZST alignment was ignored when checking whether something is a newtype. I wonder how many more of these there are... Fixes rust-lang#101084
tiif
pushed a commit
to tiif/miri
that referenced
this issue
Jun 25, 2024
transmute size check: properly account for alignment Fixes another place where ZST alignment was ignored when checking whether something is a newtype. I wonder how many more of these there are... Fixes rust-lang/rust#101084
flip1995
pushed a commit
to flip1995/rust-clippy
that referenced
this issue
Jun 28, 2024
transmute size check: properly account for alignment Fixes another place where ZST alignment was ignored when checking whether something is a newtype. I wonder how many more of these there are... Fixes rust-lang/rust#101084
lnicola
pushed a commit
to lnicola/rust-analyzer
that referenced
this issue
Jul 11, 2024
transmute size check: properly account for alignment Fixes another place where ZST alignment was ignored when checking whether something is a newtype. I wonder how many more of these there are... Fixes rust-lang/rust#101084
# for free
to join this conversation on GitHub.
Already have an account?
# to comment
Labels
C-bug
Category: This is a bug.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
T-opsem
Relevant to the opsem team
I tried this code: playground link
I expected to see this happen: Compiler error because
*mut T
andPtrAndOverAlignZST<T>
are not (known to be) the same size.Instead, this happened: The above code compiles (and runs), but ICEs miri.
Meta
rustc --version --verbose
:rustc +nightly --version --verbose
:Backtrace
No backtrace for `rustc`, since no error occurs.
AFICT, rustc currently only supports transmuting a subset of Sized types that it conservatively can guarantee are the same size. For generic struct types with ?Sized parameters, I think rustc can only guarantee the size if the whole struct's size does not depend on the parameters, or if the struct's only non-zst field is a (transitive transparent wrapper of a) pointer type depending on a generic parameter (
rustc_middle::ty::layout::SizeSkeleton
only hasKnown(usize)
andPointer { .. }
variants, so can only express completely known and only-a-pointer sizes). I think this size-calculation ignoring all ZSTs (not just 1-ZSTs) when there is a pointer field can cause transmute to (incorrectly?) allow transmuting between differently-sized types.rustc_middle::ty::layout::SizeSkeleton
probably needs to be made aware of alignment, and then needs to changecompute
to account for alignment when checking fields.See also: #101081
The text was updated successfully, but these errors were encountered: