Skip to content

Tracking Issue for #[align(...)] on function items (fn_align) #82232

Description

@repnop

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

Blocking issues

Activity

  1. added
    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFC
    on Feb 17, 2021
  2. changed the title [-]Tracking Issue for `#[repr(align = ...)]` on function items (fn_align)[/-] [+]Tracking Issue for `#[repr(align(...))]` on function items (fn_align)[/+] on Feb 17, 2021
  3. evanrichter commented on Aug 25, 2021

    @evanrichter
    Contributor

    Is it be possible to apply this to methods as well?

    #![feature(fn_align)]
    
    #[repr(align(1))]
    fn main() {
        Bar::foo();
    }
    
    struct Bar;
    
    impl Bar {
        #[repr(align(1))]
        fn foo() {
            println!("bar");
        }
    }
    error[E0517]: attribute should be applied to a struct, enum, function, or union
      --> src/main.rs:11:12
       |
    11 |       #[repr(align(1))]
       |              ^^^^^^^^
    12 | /     fn foo() {
    13 | |         println!("bar");
    14 | |     }
       | |_____- not a struct, enum, function, or union
    
    For more information about this error, try `rustc --explain E0517`.
    error: could not compile `asdf` due to previous error
    
  4. repnop commented on Aug 26, 2021

    @repnop
    ContributorAuthor

    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 👍

  5. added a commit that references this issue on Dec 3, 2022
  6. bunnie commented on Dec 25, 2022

    @bunnie
    Contributor

    Thanks for opening this, I just bumped my head into this exact problem as well!

  7. added a commit that references this issue on Apr 17, 2023
  8. workingjubilee commented on Aug 8, 2024

    @workingjubilee
    Member

    This should come with a command-line flag to address the request made in #128830 for global code alignment control.

  9. added a commit that references this issue on Aug 28, 2024
  10. added a commit that references this issue on Aug 28, 2024
  11. added
    A-alignArea: alignment control (`repr(align(N))` and so on)
    F-fn_align`#![feature(fn_align)]`
    and removed
    F-fn_align`#![feature(fn_align)]`
    on Nov 1, 2024
  12. 39 remaining items

  13. added a commit that references this issue on Jun 23, 2025
  14. added a commit that references this issue on Jun 23, 2025
  15. added a commit that references this issue on Jun 24, 2025
  16. RalfJung commented on Jul 3, 2025

    @RalfJung
    Member

    The PR description here is outdated, right? Could someone familiar with the feature update it?

  17. changed the title [-]Tracking Issue for `#[repr(align(...))]` on function items (fn_align)[/-] [+]Tracking Issue for `#[align(...)]` on function items (fn_align)[/+] on Jul 3, 2025
  18. added a commit that references this issue on Jul 7, 2025
  19. added a commit that references this issue on Jul 7, 2025
  20. added
    S-tracking-needs-summaryStatus: It's hard to tell what's been done and what hasn't! Someone should do some investigation.
    on Jul 21, 2025
  21. nikic commented on Aug 22, 2025

    @nikic
    Contributor

    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

  22. Jules-Bertholet commented on Aug 22, 2025

    @Jules-Bertholet
    Contributor

    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

    With that RFC, the Rust align attribute would correspond with LLVM minalign, I believe.

  23. workingjubilee commented on Jan 31, 2026

    @workingjubilee
    Member

    LLVM apparently backed out the align -> minalign change and the author is proposing adding a new prefalign attribute for that.

  24. nazar-pc commented on May 1, 2026

    @nazar-pc

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-alignArea: alignment control (`repr(align(N))` and so on)A-rust-for-linuxRelevant for the Rust-for-Linux projectC-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCF-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.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions