about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorFolkert de Vries <folkert@folkertdev.nl>2024-12-05 15:32:12 +0100
committerFolkert de Vries <folkert@folkertdev.nl>2024-12-05 16:44:00 +0100
commitdfd76c1cbb9bf053b5362f283277d8064d2604a7 (patch)
tree02b8f008b81857fa6672a6aecb8e5ca1a3df878d /tests
parent0e98766a5478abd9a279777e55e3d3e06e1761c0 (diff)
downloadrust-dfd76c1cbb9bf053b5362f283277d8064d2604a7.tar.gz
rust-dfd76c1cbb9bf053b5362f283277d8064d2604a7.zip
disallow `repr()` on invalid items
Also this generates an error when `repr` is used on a trait method and
the `fn_align` feature is not enabled. Looks like that was missed here:

https://github.com/rust-lang/rust/pull/110313/files

Which first enables the align attribute on trait methods.
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/repr/attr-usage-repr.rs31
-rw-r--r--tests/ui/repr/attr-usage-repr.stderr36
2 files changed, 51 insertions, 16 deletions
diff --git a/tests/ui/repr/attr-usage-repr.rs b/tests/ui/repr/attr-usage-repr.rs
index dc0d4f5be2e..d8515a12e05 100644
--- a/tests/ui/repr/attr-usage-repr.rs
+++ b/tests/ui/repr/attr-usage-repr.rs
@@ -16,18 +16,39 @@ struct SSimd([f64; 2]);
 struct SInt(f64, f64);
 
 #[repr(C)]
-enum EExtern { A, B }
+enum EExtern {
+    A,
+    B,
+}
 
 #[repr(align(8))]
-enum EAlign { A, B }
+enum EAlign {
+    A,
+    B,
+}
 
 #[repr(packed)] //~ ERROR: attribute should be applied to a struct
-enum EPacked { A, B }
+enum EPacked {
+    A,
+    B,
+}
 
 #[repr(simd)] //~ ERROR: attribute should be applied to a struct
-enum ESimd { A, B }
+enum ESimd {
+    A,
+    B,
+}
 
 #[repr(i8)]
-enum EInt { A, B }
+enum EInt {
+    A,
+    B,
+}
+
+#[repr()] //~ attribute should be applied to a struct, enum, function, associated function, or union [E0517]
+type SirThisIsAType = i32;
+
+#[repr()]
+struct EmptyReprArgumentList(i32);
 
 fn main() {}
diff --git a/tests/ui/repr/attr-usage-repr.stderr b/tests/ui/repr/attr-usage-repr.stderr
index 42f65625a46..a25e68c483f 100644
--- a/tests/ui/repr/attr-usage-repr.stderr
+++ b/tests/ui/repr/attr-usage-repr.stderr
@@ -15,21 +15,35 @@ LL | struct SInt(f64, f64);
    | ---------------------- not an enum
 
 error[E0517]: attribute should be applied to a struct or union
-  --> $DIR/attr-usage-repr.rs:24:8
+  --> $DIR/attr-usage-repr.rs:30:8
    |
-LL | #[repr(packed)]
-   |        ^^^^^^
-LL | enum EPacked { A, B }
-   | --------------------- not a struct or union
+LL |   #[repr(packed)]
+   |          ^^^^^^
+LL | / enum EPacked {
+LL | |     A,
+LL | |     B,
+LL | | }
+   | |_- not a struct or union
 
 error[E0517]: attribute should be applied to a struct
-  --> $DIR/attr-usage-repr.rs:27:8
+  --> $DIR/attr-usage-repr.rs:36:8
    |
-LL | #[repr(simd)]
-   |        ^^^^
-LL | enum ESimd { A, B }
-   | ------------------- not a struct
+LL |   #[repr(simd)]
+   |          ^^^^
+LL | / enum ESimd {
+LL | |     A,
+LL | |     B,
+LL | | }
+   | |_- not a struct
 
-error: aborting due to 4 previous errors
+error[E0517]: attribute should be applied to a struct, enum, function, associated function, or union
+  --> $DIR/attr-usage-repr.rs:48:1
+   |
+LL | #[repr()]
+   | ^^^^^^^^^
+LL | type SirThisIsAType = i32;
+   | -------------------------- not a struct, enum, function, associated function, or union
+
+error: aborting due to 5 previous errors
 
 For more information about this error, try `rustc --explain E0517`.