Repository navigation
Tracking Issue for #[align(...)] on function items (fn_align) #82232
Copy link
Copy link
Open
Labels
A-alignArea: alignment control (`repr(align(N))` and so on)Area: alignment control (`repr(align(N))` and so on)A-rust-for-linuxRelevant for the Rust-for-Linux projectRelevant for the Rust-for-Linux projectC-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCF-fn_align`#![feature(fn_align)]``#![feature(fn_align)]`S-tracking-needs-summaryStatus: It's hard to tell what's been done and what hasn't! Someone should do some investigation.Status: It's hard to tell what's been done and what hasn't! Someone should do some investigation.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language teamRelevant to the language team
Description
This feature allows specifying an alignment for function items by adding the #[repr(align(...))] attribute to them.
The feature gate for the issue is #![feature(fn_align)]
Example
#[align(16)]
fn requires_alignment() {
// ...
}Steps
- Accept RFC
- Implementation (Allow specifying alignment for functions #81234)
- Adjust documentation
- Stabilization PR
Blocking issues
- Function alignment does not work on wasm #143368
- What does this mean on the language level? It can't be quite as easy as "function pointers, cast to an integer, are divisible by the alignment" -- that's incorrect on ARM.
Reacted by Diana, Alex Martens, Luo Jia / Zhouqi Jiang, Jakub Beránek, bunnie, Meyer Zinn, Dan Cross, Josh Junon, Parsa, Nazar Mokrynskyi and 1 more
Reacted by Jiji Freya Daniel Maslowski
Metadata
Metadata
Assignees
Labels
A-alignArea: alignment control (`repr(align(N))` and so on)Area: alignment control (`repr(align(N))` and so on)A-rust-for-linuxRelevant for the Rust-for-Linux projectRelevant for the Rust-for-Linux projectC-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCF-fn_align`#![feature(fn_align)]``#![feature(fn_align)]`S-tracking-needs-summaryStatus: It's hard to tell what's been done and what hasn't! Someone should do some investigation.Status: It's hard to tell what's been done and what hasn't! Someone should do some investigation.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language teamRelevant to the language team
Activity
[-]Tracking Issue for `#[repr(align = ...)]` on function items (fn_align)[/-][+]Tracking Issue for `#[repr(align(...))]` on function items (fn_align)[/+]evanrichter commentedon Aug 25, 2021
Is it be possible to apply this to methods as well?
repnop commentedon Aug 26, 2021
I don't see why not? (I'm surprised it doesn't work already honestly lol) I'll see if I can find some time to investigate that and make another PR to allow that 👍
feat: Add MessageMf
bunnie commentedon Dec 25, 2022
Thanks for opening this, I just bumped my head into this exact problem as well!
Rollup merge of rust-lang#110313 - fee1-dead-contrib:repr_align_metho…
workingjubilee commentedon Aug 8, 2024
This should come with a command-line flag to address the request made in #128830 for global code alignment control.
Rollup merge of rust-lang#129421 - jdonszelmann:naked-repr-align-func…
Unrolled build for rust-lang#129421
39 remaining items
Unrolled build for #142854
Rollup merge of rust-lang#142923 - folkertdev:min-function-alignment-…
Unrolled build for #142923
Rollup merge of #142854 - folkertdev:centralize-min-function-alignmen…
RalfJung commentedon Jul 3, 2025
The PR description here is outdated, right? Could someone familiar with the feature update it?
[-]Tracking Issue for `#[repr(align(...))]` on function items (fn_align)[/-][+]Tracking Issue for `#[align(...)]` on function items (fn_align)[/+]Rollup merge of rust-lang#143206 - Jules-Bertholet:align-attr-fixes, …
Unrolled build for #143206
nikic commentedon Aug 22, 2025
For the record, there is a new LLVM RFC related to function alignment that may interact with this feature: https://discourse.llvm.org/t/rfc-enhancing-function-alignment-attributes/88019
Jules-Bertholet commentedon Aug 22, 2025
With that RFC, the Rust
alignattribute would correspond with LLVMminalign, I believe.Rollup merge of #134213 - folkertdev:stabilize-naked-functions, r=tgr…
Rollup merge of #134213 - folkertdev:stabilize-naked-functions, r=tgr…
workingjubilee commentedon Jan 31, 2026
LLVM apparently backed out the
align->minalignchange and the author is proposing adding a newprefalignattribute for that.nazar-pc commentedon May 1, 2026
For those who try to use it, the current syntax is
#[rustc_align(N)], not#[align(N)].#[align(N)]simply errors, while#[repr(align(N))]suggests#[rustc_align(N)].Please update the first comment.