Skip to content
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

Wrong diagnostic for zero-sized array in transparent struct #98064

Closed
lukas-code opened this issue Jun 13, 2022 · 1 comment
Closed

Wrong diagnostic for zero-sized array in transparent struct #98064

lukas-code opened this issue Jun 13, 2022 · 1 comment
Labels
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.

Comments

@lukas-code
Copy link
Member

Given the following code:

#[repr(transparent)]
pub struct Aligned<T, A> {
    align: [A; 0],
    value: T,
}

The current output is:

error[E0690]: transparent struct needs at most one non-zero-sized field, but has 2
 --> kernel/src/align.rs:2:1
  |
2 | pub struct Aligned<T, A> {
  | ^^^^^^^^^^^^^^^^^^^^^^^^ needs at most one non-zero-sized field, but has 2
3 |     align: [A; 0],
  |     ------------- this field is non-zero-sized
4 |     value: T,
  |     -------- this field is non-zero-sized

For more information about this error, try `rustc --explain E0690`.

Ideally the output should look like:

error[E0691]: zero-sized field in transparent struct has alignment larger than 1
 --> kernel/src/align.rs:3:5
  |
3 |     align: [A; 0],
  |     ^^^^^^^^^^^^^ may have alignment larger than 1
  |
help: consider changing `#[repr(transparent)]` to `#[repr(C)]`
  |
1 - #[repr(transparent)]
1 + #[repr(C)]
  | 

For more information about this error, try `rustc --explain E0691`.
@lukas-code lukas-code 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 Jun 13, 2022
@lukas-code
Copy link
Member Author

Closing this as fixed, the compiler output now mentions alignment:

error[E0690]: transparent struct needs at most one field with non-trivial size or alignment, but has 2
 --> src/lib.rs:2:1
  |
2 | pub struct Aligned<T, A> {
  | ^^^^^^^^^^^^^^^^^^^^^^^^ needs at most one field with non-trivial size or alignment, but has 2
3 |     align: [A; 0],
  |     ------------- this field has non-zero size or requires alignment
4 |     value: T,
  |     -------- this field has non-zero size or requires alignment

For more information about this error, try `rustc --explain E0690`.
error: could not compile `playground` (lib) due to 1 previous error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant