Skip to content

Commit

Permalink
runtime-sized in const is unsound
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtwco committed Dec 2, 2024
1 parent 72743b6 commit 9fd3dff
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions text/3729-sized-hierarchy.md
Original file line number Diff line number Diff line change
Expand Up @@ -1136,8 +1136,9 @@ with const functions, adding a lot of complexity to const code.
More importantly, the size of a runtime-sized type could differ between
the host and the target and if the size from a const context were to be used
at runtime with runtime-sized types, then that could result in incorrect
code. It is unintuitive that `const { size_of::<svint8_t>() }` would not
be equal to `size_of::<svint8_t>()`.
code. Not only is it unintuitive that `const { size_of::<svint8_t>() }` would
not be equal to `size_of::<svint8_t>()`, but the layout of types could differ
between const and runtime contexts which would be unsound.
Changing `size_of` and `size_of_val` to `~const Sized` bounds ensures that
`const { size_of:<svint8_t>() }` is not possible.
Expand Down

0 comments on commit 9fd3dff

Please sign in to comment.