Skip to content

Commit 2e6c84a

Browse files
Add more tests for invalid alignments
1 parent 233e2ef commit 2e6c84a

File tree

2 files changed

+41
-5
lines changed

2 files changed

+41
-5
lines changed

tests/ui/attributes/malformed-fn-align.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@ fn f3() {}
2121
#[repr(align(16))] //~ ERROR `#[repr(align(...))]` is not supported on function items
2222
fn f4() {}
2323

24+
#[align(-1)] //~ ERROR expected unsuffixed literal, found `-`
25+
fn f5() {}
26+
27+
#[align(3)] //~ ERROR invalid alignment value: not a power of two
28+
fn f6() {}
29+
30+
#[align(4usize)] //~ ERROR invalid alignment value: not an unsuffixed integer [E0589]
31+
//~^ ERROR suffixed literals are not allowed in attributes
32+
fn f7() {}
33+
2434
#[align(16)] //~ ERROR `#[align(...)]` is not supported on struct items
2535
struct S1;
2636

tests/ui/attributes/malformed-fn-align.stderr

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
error: expected unsuffixed literal, found `-`
2+
--> $DIR/malformed-fn-align.rs:24:9
3+
|
4+
LL | #[align(-1)]
5+
| ^
6+
7+
error: suffixed literals are not allowed in attributes
8+
--> $DIR/malformed-fn-align.rs:30:9
9+
|
10+
LL | #[align(4usize)]
11+
| ^^^^^^
12+
|
13+
= help: instead of using a suffixed literal (`1u8`, `1.0f32`, etc.), use an unsuffixed version (`1`, `1.0`, etc.)
14+
115
error[E0539]: malformed `align` attribute input
216
--> $DIR/malformed-fn-align.rs:5:5
317
|
@@ -37,6 +51,18 @@ error[E0589]: invalid alignment value: not a power of two
3751
LL | #[align(0)]
3852
| ^
3953

54+
error[E0589]: invalid alignment value: not a power of two
55+
--> $DIR/malformed-fn-align.rs:27:9
56+
|
57+
LL | #[align(3)]
58+
| ^
59+
60+
error[E0589]: invalid alignment value: not an unsuffixed integer
61+
--> $DIR/malformed-fn-align.rs:30:9
62+
|
63+
LL | #[align(4usize)]
64+
| ^^^^^^
65+
4066
error: `#[repr(align(...))]` is not supported on function items
4167
--> $DIR/malformed-fn-align.rs:21:8
4268
|
@@ -50,7 +76,7 @@ LL | #[repr(align(16))]
5076
| ^^^^^^^^^
5177

5278
error: `#[align(...)]` is not supported on struct items
53-
--> $DIR/malformed-fn-align.rs:24:1
79+
--> $DIR/malformed-fn-align.rs:34:1
5480
|
5581
LL | #[align(16)]
5682
| ^^^^^^^^^^^^
@@ -62,30 +88,30 @@ LL + #[repr(align(16))]
6288
|
6389

6490
error: `#[align(...)]` should be applied to a function item
65-
--> $DIR/malformed-fn-align.rs:27:1
91+
--> $DIR/malformed-fn-align.rs:37:1
6692
|
6793
LL | #[align(32)]
6894
| ^^^^^^^^^^^^
6995
LL | const FOO: i32 = 42;
7096
| -------------------- not a function item
7197

7298
error: `#[align(...)]` should be applied to a function item
73-
--> $DIR/malformed-fn-align.rs:30:1
99+
--> $DIR/malformed-fn-align.rs:40:1
74100
|
75101
LL | #[align(32)]
76102
| ^^^^^^^^^^^^
77103
LL | mod test {}
78104
| ----------- not a function item
79105

80106
error: `#[align(...)]` should be applied to a function item
81-
--> $DIR/malformed-fn-align.rs:33:1
107+
--> $DIR/malformed-fn-align.rs:43:1
82108
|
83109
LL | #[align(32)]
84110
| ^^^^^^^^^^^^
85111
LL | use ::std::iter;
86112
| ---------------- not a function item
87113

88-
error: aborting due to 10 previous errors
114+
error: aborting due to 14 previous errors
89115

90116
Some errors have detailed explanations: E0539, E0589, E0805.
91117
For more information about an error, try `rustc --explain E0539`.

0 commit comments

Comments
 (0)