Support setting alignment on globals

Currently if one wants to set alignment on globals (either static or const) it needs to use a wrapper:

#[repr(align(8))]
struct Aligned(u8);

static X: Aligned = Aligned(0);
const Y: Aligned = Aligned(0);

instead it would be nice to support align on static/const directly:

#[repr(align(8))] // or maybe #[align(8)]
static X: u8 = 0;
#[repr(align(8))] // or maybe #[align(8)]
const Y: u8 = 0;
4 Likes

Yes it needs a wrapper. The type contains its align. Calling a function that need align on a not-aligned struct is unsafe (and perhaps unsound)

if a function needs a u8, the function should not acquire the u8 is aligned, and if that function required an aligned item, it should not require u8 type directly in safe Rust.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.