File tree Expand file tree Collapse file tree 3 files changed +56
-8
lines changed Expand file tree Collapse file tree 3 files changed +56
-8
lines changed Original file line number Diff line number Diff line change 55use std:: mem;
66
77// Raising alignment
8- #[ repr( align( 8 ) ) ]
9- enum Align8 {
8+ #[ repr( align( 16 ) ) ]
9+ enum Align16 {
1010 Foo { foo : u32 } ,
1111 Bar { bar : u32 } ,
1212}
1313
14+ // Raise alignment by maximum
15+ #[ repr( align( 1 ) , align( 16 ) ) ]
16+ #[ repr( align( 32 ) ) ]
17+ #[ repr( align( 4 ) ) ]
18+ enum Align32 {
19+ Foo ,
20+ Bar ,
21+ }
22+
23+ // Not reducing alignment
24+ #[ repr( align( 4 ) ) ]
25+ enum AlsoAlign16 {
26+ Foo { limb_with_align16 : Align16 } ,
27+ Bar ,
28+ }
29+
30+ // No niche for discriminant when used as limb
31+ #[ repr( align( 16 ) ) ]
32+ struct NoNiche16 ( u64 , u64 ) ;
33+
34+ // Discriminant will require extra space, but enum needs to stay compatible
35+ // with alignment 16
36+ #[ repr( align( 1 ) ) ]
37+ enum AnotherAlign16 {
38+ Foo { limb_with_noniche16 : NoNiche16 } ,
39+ Bar ,
40+ Baz ,
41+ }
42+
1443fn main ( ) {
15- assert_eq ! ( mem:: align_of:: <Align8 >( ) , 8 ) ;
16- assert_eq ! ( mem:: size_of:: <Align8 >( ) , 8 ) ;
44+ assert_eq ! ( mem:: align_of:: <Align16 >( ) , 16 ) ;
45+ assert_eq ! ( mem:: size_of:: <Align16 >( ) , 16 ) ;
46+
47+ assert_eq ! ( mem:: align_of:: <Align32 >( ) , 32 ) ;
48+ assert_eq ! ( mem:: size_of:: <Align32 >( ) , 32 ) ;
49+
50+ assert_eq ! ( mem:: align_of:: <AlsoAlign16 >( ) , 16 ) ;
51+ assert_eq ! ( mem:: size_of:: <AlsoAlign16 >( ) , 16 ) ;
52+
53+ assert_eq ! ( mem:: align_of:: <AnotherAlign16 >( ) , 16 ) ;
54+ assert_eq ! ( mem:: size_of:: <AnotherAlign16 >( ) , 32 ) ;
1755}
Original file line number Diff line number Diff line change 1+ #![ feature( repr_align_enum) ]
12#![ allow( dead_code) ]
23
34#[ repr( align( 16.0 ) ) ] //~ ERROR: invalid `repr(align)` attribute: not an unsuffixed integer
@@ -12,4 +13,7 @@ struct C(i32);
1213#[ repr( align( 536870912 ) ) ] // ok: this is the largest accepted alignment
1314struct D ( i32 ) ;
1415
16+ #[ repr( align( 15 ) ) ] //~ ERROR: invalid `repr(align)` attribute: not a power of two
17+ enum E { Left , Right }
18+
1519fn main ( ) { }
Original file line number Diff line number Diff line change 11error[E0589]: invalid `repr(align)` attribute: not an unsuffixed integer
2- --> $DIR/repr-align.rs:3 :8
2+ --> $DIR/repr-align.rs:4 :8
33 |
44LL | #[repr(align(16.0))] //~ ERROR: invalid `repr(align)` attribute: not an unsuffixed integer
55 | ^^^^^^^^^^^
66
77error[E0589]: invalid `repr(align)` attribute: not a power of two
8- --> $DIR/repr-align.rs:6 :8
8+ --> $DIR/repr-align.rs:7 :8
99 |
1010LL | #[repr(align(15))] //~ ERROR: invalid `repr(align)` attribute: not a power of two
1111 | ^^^^^^^^^
1212
1313error[E0589]: invalid `repr(align)` attribute: larger than 2^29
14- --> $DIR/repr-align.rs:9 :8
14+ --> $DIR/repr-align.rs:10 :8
1515 |
1616LL | #[repr(align(4294967296))] //~ ERROR: invalid `repr(align)` attribute: larger than 2^29
1717 | ^^^^^^^^^^^^^^^^^
1818
19- error: aborting due to 3 previous errors
19+ error[E0589]: invalid `repr(align)` attribute: not a power of two
20+ --> $DIR/repr-align.rs:16:8
21+ |
22+ LL | #[repr(align(15))] //~ ERROR: invalid `repr(align)` attribute: not a power of two
23+ | ^^^^^^^^^
24+
25+ error: aborting due to 4 previous errors
2026
2127For more information about this error, try `rustc --explain E0589`.
You can’t perform that action at this time.
0 commit comments