Rollup merge of #142507 - folkertdev:fn-align-align-attribute, r=jdonszelmann

use `#[align]` attribute for `fn_align`

Tracking issue: https://github.com/rust-lang/rust/issues/82232

https://github.com/rust-lang/rfcs/pull/3806 decides to add the `#[align]` attribute for alignment of various items. Right now it's used for functions with `fn_align`, in the future it will get more uses (statics, struct fields, etc.)

(the RFC finishes FCP today)

r? `@ghost`
This commit is contained in:
Trevor Gross 2025-06-18 20:22:49 -04:00 committed by GitHub
commit 07932ad111
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
30 changed files with 322 additions and 135 deletions

View file

@ -1,21 +1,21 @@
//@compile-flags: -Zmin-function-alignment=8
#![feature(fn_align)]
// When a function uses `repr(align(N))`, the function address should be a multiple of `N`.
// When a function uses `align(N)`, the function address should be a multiple of `N`.
#[repr(align(256))]
#[align(256)]
fn foo() {}
#[repr(align(16))]
#[align(16)]
fn bar() {}
#[repr(align(4))]
#[align(4)]
fn baz() {}
fn main() {
assert!((foo as usize).is_multiple_of(256));
assert!((bar as usize).is_multiple_of(16));
// The maximum of `repr(align(N))` and `-Zmin-function-alignment=N` is used.
// The maximum of `align(N)` and `-Zmin-function-alignment=N` is used.
assert!((baz as usize).is_multiple_of(8));
}