Extending alignment to any constant-evaluable expression

Using Elain — Rust library // Lib.rs as an inspiration: extend #[repr(align(N))] to where N can be any constant-evaluable expression, not just a positive integer.

Thoughts on this? Inspired by approach from @scottmcm: #[repr(align(…))] should allow any constant expression, not just integer literals - #4 by scottmcm

There's the (to me) immediately obvious problem of being able to use align_of::<T>() in const eval. Anything that's self-referential, even behind arbitrary levels of indirection, would be an issue.

Well my point there is that I don't want to put expressions in the repr.

I don't see any problems there. The compiler already has to handle self-reference. For example, the following code already produces a normal(ish) compiler error:

struct Thing {
    field: [u8; size_of::<Thing>()],
}
7 Likes