Skip to content

Misleading error message when using a named constant as a struct alignment #121425

Closed
@ChaiTRex

Description

@ChaiTRex

Code

const N: usize = 8;
#[repr(align(N))]
struct T;

Current output

error[E0693]: incorrect `repr(align)` attribute format: `align` takes exactly one argument in parentheses
 --> src/main.rs:2:8
  |
2 | #[repr(align(N))]
  |        ^^^^^^^^

Desired output

error[E????]: incorrect `repr(align)` value: alignment must be a literal integer
 --> src/main.rs:2:14
  |
2 | #[repr(align(N))]
  |              ^

Rationale and extra context

#[repr(align(N))] does give align exactly one argument in parentheses, but the error implies that it doesn't.

Other cases

No response

Rust Version

rustc 1.78.0-nightly (b381d3ab2 2024-02-12)
binary: rustc
commit-hash: b381d3ab27f788f990551100c4425bb782d26d76
commit-date: 2024-02-12
host: x86_64-unknown-linux-gnu
release: 1.78.0-nightly
LLVM version: 17.0.6

Anything else?

No response

Metadata

Metadata

Assignees

Labels

A-attributesArea: Attributes (`#[…]`, `#![…]`)A-diagnosticsArea: Messages for errors, warnings, and lintsD-confusingDiagnostics: Confusing error or lint that should be reworked.D-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.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