about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJules Bertholet <julesbertholet@quoi.xyz>2025-07-01 16:13:37 -0400
committerJules Bertholet <julesbertholet@quoi.xyz>2025-07-06 16:56:42 -0400
commit196e3ed94357c29d2b29386023e19cc6cc83a175 (patch)
tree9ff7c1b240bf875f28b98aa8ab232bd4f66c30de
parent1c93e16c10ef18e4c4da27772899bf8c64d9eaf3 (diff)
downloadrust-196e3ed94357c29d2b29386023e19cc6cc83a175.tar.gz
rust-196e3ed94357c29d2b29386023e19cc6cc83a175.zip
Add more tests for invalid alignments
-rw-r--r--tests/ui/attributes/malformed-fn-align.rs15
-rw-r--r--tests/ui/attributes/malformed-fn-align.stderr42
2 files changed, 52 insertions, 5 deletions
diff --git a/tests/ui/attributes/malformed-fn-align.rs b/tests/ui/attributes/malformed-fn-align.rs
index 870bc34d454..e06e6116842 100644
--- a/tests/ui/attributes/malformed-fn-align.rs
+++ b/tests/ui/attributes/malformed-fn-align.rs
@@ -21,6 +21,21 @@ fn f3() {}
 #[repr(align(16))] //~ ERROR `#[repr(align(...))]` is not supported on function items
 fn f4() {}
 
+#[align(-1)] //~ ERROR expected unsuffixed literal, found `-`
+fn f5() {}
+
+#[align(3)] //~ ERROR invalid alignment value: not a power of two
+fn f6() {}
+
+#[align(4usize)] //~ ERROR invalid alignment value: not an unsuffixed integer [E0589]
+//~^ ERROR suffixed literals are not allowed in attributes
+fn f7() {}
+
+#[align(16)]
+#[align(3)] //~ ERROR invalid alignment value: not a power of two
+#[align(16)]
+fn f8() {}
+
 #[align(16)] //~ ERROR `#[align(...)]` is not supported on struct items
 struct S1;
 
diff --git a/tests/ui/attributes/malformed-fn-align.stderr b/tests/ui/attributes/malformed-fn-align.stderr
index e1fe5353a41..af3625b1f3b 100644
--- a/tests/ui/attributes/malformed-fn-align.stderr
+++ b/tests/ui/attributes/malformed-fn-align.stderr
@@ -1,3 +1,17 @@
+error: expected unsuffixed literal, found `-`
+  --> $DIR/malformed-fn-align.rs:24:9
+   |
+LL | #[align(-1)]
+   |         ^
+
+error: suffixed literals are not allowed in attributes
+  --> $DIR/malformed-fn-align.rs:30:9
+   |
+LL | #[align(4usize)]
+   |         ^^^^^^
+   |
+   = help: instead of using a suffixed literal (`1u8`, `1.0f32`, etc.), use an unsuffixed version (`1`, `1.0`, etc.)
+
 error[E0539]: malformed `align` attribute input
   --> $DIR/malformed-fn-align.rs:5:5
    |
@@ -37,6 +51,24 @@ error[E0589]: invalid alignment value: not a power of two
 LL | #[align(0)]
    |         ^
 
+error[E0589]: invalid alignment value: not a power of two
+  --> $DIR/malformed-fn-align.rs:27:9
+   |
+LL | #[align(3)]
+   |         ^
+
+error[E0589]: invalid alignment value: not an unsuffixed integer
+  --> $DIR/malformed-fn-align.rs:30:9
+   |
+LL | #[align(4usize)]
+   |         ^^^^^^
+
+error[E0589]: invalid alignment value: not a power of two
+  --> $DIR/malformed-fn-align.rs:35:9
+   |
+LL | #[align(3)]
+   |         ^
+
 error: `#[repr(align(...))]` is not supported on function items
   --> $DIR/malformed-fn-align.rs:21:8
    |
@@ -50,7 +82,7 @@ LL | #[repr(align(16))]
    |        ^^^^^^^^^
 
 error: `#[align(...)]` is not supported on struct items
-  --> $DIR/malformed-fn-align.rs:24:1
+  --> $DIR/malformed-fn-align.rs:39:1
    |
 LL | #[align(16)]
    | ^^^^^^^^^^^^
@@ -62,7 +94,7 @@ LL + #[repr(align(16))]
    |
 
 error: `#[align(...)]` should be applied to a function item
-  --> $DIR/malformed-fn-align.rs:27:1
+  --> $DIR/malformed-fn-align.rs:42:1
    |
 LL | #[align(32)]
    | ^^^^^^^^^^^^
@@ -70,7 +102,7 @@ LL | const FOO: i32 = 42;
    | -------------------- not a function item
 
 error: `#[align(...)]` should be applied to a function item
-  --> $DIR/malformed-fn-align.rs:30:1
+  --> $DIR/malformed-fn-align.rs:45:1
    |
 LL | #[align(32)]
    | ^^^^^^^^^^^^
@@ -78,14 +110,14 @@ LL | mod test {}
    | ----------- not a function item
 
 error: `#[align(...)]` should be applied to a function item
-  --> $DIR/malformed-fn-align.rs:33:1
+  --> $DIR/malformed-fn-align.rs:48:1
    |
 LL | #[align(32)]
    | ^^^^^^^^^^^^
 LL | use ::std::iter;
    | ---------------- not a function item
 
-error: aborting due to 10 previous errors
+error: aborting due to 15 previous errors
 
 Some errors have detailed explanations: E0539, E0589, E0805.
 For more information about an error, try `rustc --explain E0539`.