Closed eduardosm closed 3 years ago
Hm, I don't think this how align
works?
For align, if the specified alignment is less than the alignment of the type without the align modifier, then the alignment is unaffected.
from https://doc.rust-lang.org/reference/type-layout.html#the-alignment-modifiers
Ouch, I mixed the align
and packed
concepts, sorry. Closing this PR then.
It's all good!
JFYI, here's how I figured that align might not work that way:
If align were to force the alignment, than it would be unsafe to do field access with such a struct. Given that there's no unsafe in the attribute, and the compiler doesn't require unsafe when accessing fields (which would be the case for packed), then it seems likely that it only sets the min alighment.
Using
#[repr(align(4))]
directly onWaiter
will downgrade alignment form 8 to 4 bytes on 64-bit targets.To fix this, an empty struct is defined (
Align4
), which is tagged with#[repr(align(4))]
, and an instance of this empty struct is added toWaiter
.Waiter
will now have an alignment of at least 4 bytes, but it will be greater on targets that require it.