Skip to content

#[repr(align(…))] should allow arbitrary constant expressions, not just integer literals #52840

@comex

Description

@comex

For example:

const ALIGN_OF_FOO: usize = 32;
#[repr(align(ALIGN_OF_FOO))]
struct Foo;

Currently this produces an error:

error[E0552]: unrecognized representation hint
 --> src/main.rs:2:8
  |
2 | #[repr(align(ALIGN_OF_FOO))]
  |        ^^^^^^^^^^^^^^^^^^^

A potential use case is for opaque struct definitions.

I could submit this as a new RFC, but I can't think of any reason not to allow it or any ambiguity as to how it should work, so I'm hoping an issue report may be sufficient.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-reprArea: the `#[repr(stuff)]` attributeC-feature-requestCategory: A feature request, i.e: not implemented / a PR.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions