Skip to content
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 size != stride to frequently requested changes #216

Merged
merged 7 commits into from
Oct 18, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/frequently-requested-changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,19 @@ statement, and only later see the `if` and realize it's a conditional return.

Such a change would also have non-obvious evaluation order (evaluating the
condition before the return expression).

## Size != Stride

Rust assumes that the size of an object is equivalent to the stride of an object -
this means that the size of `[T; N]` is `N * std::mem::size_of::<T>`. Other languages
may have objects that take up less space in arrays due to the reuse of tail
padding, and allow interop with other languages which do this optimization.

Rust makes several guarantees that make supporting these types difficult in the general case.
The combianation `std::array::from_ref` and array indexing is a stable guarantee that a pointer
carbotaniuman marked this conversation as resolved.
Show resolved Hide resolved
(or reference) to an type is convertible to a pointer to a 1-array of that type.
carbotaniuman marked this conversation as resolved.
Show resolved Hide resolved

Such a change could also pose problems for existing unsafe code, which may assume that pointers
can be manually offset by the size of the type to access the next array element. Unsafe
code may also assume that overwriting trailing padding is allowed, which would conflict with
the repurposing of such padding for data storage.
carbotaniuman marked this conversation as resolved.
Show resolved Hide resolved