File tree 3 files changed +56
-8
lines changed
3 files changed +56
-8
lines changed Original file line number Diff line number Diff line change 5
5
use std:: mem;
6
6
7
7
// Raising alignment
8
- #[ repr( align( 8 ) ) ]
9
- enum Align8 {
8
+ #[ repr( align( 16 ) ) ]
9
+ enum Align16 {
10
10
Foo { foo : u32 } ,
11
11
Bar { bar : u32 } ,
12
12
}
13
13
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
+
14
43
fn 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 ) ;
17
55
}
Original file line number Diff line number Diff line change
1
+ #![ feature( repr_align_enum) ]
1
2
#![ allow( dead_code) ]
2
3
3
4
#[ repr( align( 16.0 ) ) ] //~ ERROR: invalid `repr(align)` attribute: not an unsuffixed integer
@@ -12,4 +13,7 @@ struct C(i32);
12
13
#[ repr( align( 536870912 ) ) ] // ok: this is the largest accepted alignment
13
14
struct D ( i32 ) ;
14
15
16
+ #[ repr( align( 15 ) ) ] //~ ERROR: invalid `repr(align)` attribute: not a power of two
17
+ enum E { Left , Right }
18
+
15
19
fn main ( ) { }
Original file line number Diff line number Diff line change 1
1
error[E0589]: invalid `repr(align)` attribute: not an unsuffixed integer
2
- --> $DIR/repr-align.rs:3 :8
2
+ --> $DIR/repr-align.rs:4 :8
3
3
|
4
4
LL | #[repr(align(16.0))] //~ ERROR: invalid `repr(align)` attribute: not an unsuffixed integer
5
5
| ^^^^^^^^^^^
6
6
7
7
error[E0589]: invalid `repr(align)` attribute: not a power of two
8
- --> $DIR/repr-align.rs:6 :8
8
+ --> $DIR/repr-align.rs:7 :8
9
9
|
10
10
LL | #[repr(align(15))] //~ ERROR: invalid `repr(align)` attribute: not a power of two
11
11
| ^^^^^^^^^
12
12
13
13
error[E0589]: invalid `repr(align)` attribute: larger than 2^29
14
- --> $DIR/repr-align.rs:9 :8
14
+ --> $DIR/repr-align.rs:10 :8
15
15
|
16
16
LL | #[repr(align(4294967296))] //~ ERROR: invalid `repr(align)` attribute: larger than 2^29
17
17
| ^^^^^^^^^^^^^^^^^
18
18
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
20
26
21
27
For more information about this error, try `rustc --explain E0589`.
You can’t perform that action at this time.
0 commit comments