You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
#[repr(align(8))] is not accepted for arrays #83595
#[repr(align)] was accepted for arrays in rust v1.50, but is rejected in v1.51.
error[E0517]: attribute should be applied to a struct, enum, or union
--> src/main.rs:3:12
|
3 | #[repr(align(8))]
| ^^^^^^^^
4 | x: [usize; 20]
| -------------- not a struct, enum, or union
I am not entirely sure whether the attribute actually did the alignment in 1.50, or the compiler just ignored it. Regardless, is this expected behavior, and if it is how do I align an array?
Extra validation was added for situations where attributes were ignored (in this case it was #80641). Previous versions issued an unused-attribute warning.
If you want to align an array, I think you can wrap it in a struct with #[repr(align(8))] struct Arr([usize; 20]).
Extra validation was added for situations where attributes were ignored (in this case it was #80641). Previous versions issued an unused-attribute warning.
1.50 didn't warn I think. I haven't specifically configured unusued_attributes in my project. Anyways, it is a good idea to lint/error for unused attributes.
If you want to align an array, I think you can wrap it in a struct with #[repr(align(8))] struct Arr([usize; 20]).
That works, if the compiler guarantees that there will not be any padding at the beginning of Arr struct. Does it?
(Note also the warning for "#[warn(unused_attributes)] on by default".)
It's my understanding that this is known and expected fallout from fixing compiler bugs where it had previously forgotten to run validation in certain positions.
This is an intentional bugfix to resolve a place where attributes weren't being checked but were supposed to have been. Note that this never did anything, so any unsafe code that was expecting this to align things is potentially unsound.
(There have been a few of these, recently -- for example 1.49 fixed this on enum variants.)
repr(Rust) has very few guarantees. If you strictly need no padding at the beginning, you can use #[repr(C, align(8))] on the struct: https://rust.godbolt.org/z/x6648cWrE
Activity
ehuss commentedon Mar 28, 2021
Extra validation was added for situations where attributes were ignored (in this case it was #80641). Previous versions issued an
unused-attributewarning.If you want to align an array, I think you can wrap it in a struct with
#[repr(align(8))] struct Arr([usize; 20]).camelid commentedon Mar 28, 2021
Nominating to see if this was an intended "lint -> hard error" change.
(If there's another way to ask if a change is intended that people on
T-compilerprefer, please let me know :)@rustbot label: +I-nominated
rustbot commentedon Mar 28, 2021
rustbot commentedon Mar 28, 2021
manuthambi commentedon Mar 30, 2021
1.50 didn't warn I think. I haven't specifically configured
unusued_attributesin my project. Anyways, it is a good idea to lint/error for unused attributes.That works, if the compiler guarantees that there will not be any padding at the beginning of
Arrstruct. Does it?scottmcm commentedon Apr 20, 2021
It just ignored it: https://rust.godbolt.org/z/4rso564PP
(Note also the warning for "
#[warn(unused_attributes)]on by default".)It's my understanding that this is known and expected fallout from fixing compiler bugs where it had previously forgotten to run validation in certain positions.
scottmcm commentedon Apr 27, 2021
We discussed this in the lang team meeting today.
This is an intentional bugfix to resolve a place where attributes weren't being checked but were supposed to have been. Note that this never did anything, so any
unsafecode that was expecting this to align things is potentially unsound.(There have been a few of these, recently -- for example 1.49 fixed this on enum variants.)
repr(Rust)has very few guarantees. If you strictly need no padding at the beginning, you can use#[repr(C, align(8))]on the struct: https://rust.godbolt.org/z/x6648cWrEcamelid commentedon Apr 27, 2021
Should
I-nominatedbe removed now that the issue is closed?