Add repr(align(2)) to RcInner and ArcInner#146886
Conversation
|
rustbot has assigned @Mark-Simulacrum. Use |
library/alloc/src/sync.rs
Outdated
There was a problem hiding this comment.
It may not be necessary, but why not write it in code as well?
There was a problem hiding this comment.
This is my thought as well. Even though it has no effect, it documents the fact that the type expects that alignment anyway.
|
r=me with ArcInner also similarly updated (per comments above). If you don't have the bandwidth to do that, happy to merge without it, but otherwise would be good to have it in a single commit/PR IMO. |
71f9091 to
9e79fac
Compare
|
Added repr(align(2)) also to ArcInner, and updated the comment to reflect it:
@rustbot ready |
|
@bors r+ rollup |
Rollup of 6 pull requests Successful merges: - #142506 (Add `Path::has_trailing_sep` and related methods) - #146886 (Add repr(align(2)) to RcInner and ArcInner) - #147166 (several small `proc_macro` cleanups) - #147172 (bootstrap: build bootstrap docs with in-tree rustdoc) - #147181 (cg_llvm: Replace enum `MetadataType` with a list of `MetadataKindId` constants) - #147187 (remove unnecessary test directives) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of #146886 - taiki-e:rc-inner-align, r=Mark-Simulacrum Add repr(align(2)) to RcInner and ArcInner `Rc` currently assumes that `RcInner` has at least 2-byte alignment, but on AVR, `usize` has 1-byte alignment (this is because the AVR has 1-byte register sizes, so having 2-byte alignment is generally useless), breaking this assumption. https://github.com/rust-lang/rust/blob/9f32ccf35fb877270bc44a86a126440f04d676d0/library/alloc/src/rc.rs#L3005-L3008 This PR adds `repr(align(2))` to force `RcInner` to always have at least 2-byte alignment. Note that `ArcInner` doesn't need `repr(align(2))` because atomic types have the alignment same as its size. This PR adds a comment about this.
…ulacrum Add repr(align(2)) to RcInner and ArcInner `Rc` currently assumes that `RcInner` has at least 2-byte alignment, but on AVR, `usize` has 1-byte alignment (this is because the AVR has 1-byte register sizes, so having 2-byte alignment is generally useless), breaking this assumption. https://github.com/rust-lang/rust/blob/9f32ccf35fb877270bc44a86a126440f04d676d0/library/alloc/src/rc.rs#L3005-L3008 This PR adds `repr(align(2))` to force `RcInner` to always have at least 2-byte alignment. Note that `ArcInner` doesn't need `repr(align(2))` because atomic types have the alignment same as its size. This PR adds a comment about this.
Rccurrently assumes thatRcInnerhas at least 2-byte alignment, but on AVR,usizehas 1-byte alignment (this is because the AVR has 1-byte register sizes, so having 2-byte alignment is generally useless), breaking this assumption.rust/library/alloc/src/rc.rs
Lines 3005 to 3008 in 9f32ccf
This PR adds
repr(align(2))to forceRcInnerto always have at least 2-byte alignment.Note that
ArcInnerdoesn't needrepr(align(2))because atomic types have the alignment same as its size. This PR adds a comment about this.