Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ChaiTRex opened this issue Feb 22, 2024 · 1 comment · Fixed by #121900
Closed

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

ChaiTRex opened this issue Feb 22, 2024 · 1 comment · Fixed by #121900
Assignees
Labels
A-attributes Area: Attributes (`#[…]`, `#![…]`) A-diagnostics Area: Messages for errors, warnings, and lints D-confusing Diagnostics: Confusing error or lint that should be reworked. D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@ChaiTRex
Copy link
Contributor

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

@ChaiTRex ChaiTRex added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 22, 2024
@fmease fmease added A-attributes Area: Attributes (`#[…]`, `#![…]`) D-confusing Diagnostics: Confusing error or lint that should be reworked. D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. labels Feb 22, 2024
@fmease
Copy link
Member

fmease commented Feb 22, 2024

For anyone who'd like to work on this, please also rework the diagnostic for … #[repr(packed(N))] …

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-attributes Area: Attributes (`#[…]`, `#![…]`) A-diagnostics Area: Messages for errors, warnings, and lints D-confusing Diagnostics: Confusing error or lint that should be reworked. D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants