rust-lang / nomicon

The Dark Arts of Advanced and Unsafe Rust Programming
https://doc.rust-lang.org/nomicon/
Apache License 2.0
1.8k stars 261 forks source link

Nomicon incorrectly implies that types with alignment > 1 cannot be ZSTs #226

Closed joshlf closed 3 years ago

joshlf commented 4 years ago

On the repr(Rust) page, it reads:

A type's size must always be a multiple of its alignment. This ensures that an array of that type may always be indexed by offsetting by a multiple of its size.

This wording is ambiguous with respect to zero-sized types. One reading of it (which was my interpretation for years) is that a type's size must be a non-zero multiple of its alignment in order to satisfy the array indexing requirement. In fact, the reality is that the size may be zero regardless of the alignment. It would be good to clarify the wording to make that clear.

cc @jswrenn

nico-abram commented 3 years ago

Is zero not a multiple of every number? Either way, clarifying that would be nice since it does seem confusing

nico-abram commented 3 years ago

I tentatively opened a PR aiming to clarify this https://github.com/rust-lang/nomicon/pull/246