-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Contradiction in documentation about alignment of AtomicBool #126084
Comments
the alignment requirement seems to have been copy-pasted across every |
Rust guarantees that
so that it is clear that alignment is being considered, it's just never an issue. The docs for Tangent about "[...] allow emulating AtomicBool on platforms that only have word-sized atomic operations [...]"Note that at the codegen level (but not at the language level), this is sort of already being done. E.g. if the platform only has 32-bit atomics, we mask the address to the aligned 4-byte word containing the |
Rollup merge of rust-lang#126213 - zachs18:atomicbool-u8-i8-from-ptr-alignment, r=Nilstrieb Update docs for AtomicBool/U8/I8 with regard to alignment Fixes rust-lang#126084. Since `AtomicBool`/`AtomicU8`/`AtomicI8` are guaranteed to have size == 1, and Rust guarantees that `size % align == 0`, they also must have alignment equal to 1, so some current docs are contradictory/confusing when describing their alignment requirements. Specifically: * Fix `AtomicBool::from_ptr` claiming that `align_of::<AtomicBool>() > align_of::<bool>()` on some platforms. (same for `AtomicU8::from_ptr`/`AtomicI8::from_ptr`) * Explicitly state that `AtomicU8`/`AtomicI8` have the same alignment as `u8`/`i8` (in addition to size and bit validity) * (internal) Change the `if_not_8_bit` macro to be `if_8_bit` and to allow an "if-else"-like structure, instead of just "if"-like. --- I opted to leave the "`ptr` must be aligned" wording in `from_ptr`'s docs and just clarify that it is always satsified, instead of just removing the wording entirely. If that is instead preferred I can do that.
Location
https://doc.rust-lang.org/nightly/core/sync/atomic/struct.AtomicBool.html
Summary
The introductory section for
AtomicBool
states:But later the safety requirements for
from_ptr
state:This seems to be a contradiction. If AtomicBool has the same alignment as
bool
then how canalign_of::<AtomicBool>()
be bigger thanalign_of::<bool>()
.The text was updated successfully, but these errors were encountered: