Skip to content

Multiple alignments on functions (#![feature(fn_align)]) #132464

Open
@jdonszelmann

Description

This code specifies two alignments, but applies none. A single align(256) does work

#![feature(fn_align)]


#[repr(align(256), align(256))]
pub fn main() {
    let ptr = main as *const u8;
    println!("{ptr:?}");

    assert_eq!(ptr.align_offset(256), 0);
}

See here: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=f841ae6318f0f7abdab285ea9ec641ab

CC: #82232

The culprit is this line here matching on slices of length 1:

codegen_fn_attrs.alignment = if let Some(items) = attr.meta_item_list()
&& let [item] = items.as_slice()
&& let Some((sym::align, literal)) = item.singleton_lit_list()

It's a one line fix, but honestly this is trivially resolved with rust-lang/compiler-team#796 which I'm working on. I'll make it a separate PR at some point, but I'll assign myself since it makes sure changes conflict a little less :)

@rustbot claim

Activity

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

Metadata

Assignees

Labels

A-alignArea: alignment control (`repr(align(N))` and so on)A-reprArea: the `#[repr(stuff)]` attributeC-bugCategory: This is a bug.F-fn_align`#![feature(fn_align)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions