about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2025-01-07 21:36:37 +0100
committerMatthias Krüger <matthias.krueger@famsik.de>2025-01-07 21:36:37 +0100
commitb9d6e9e73ffb2eaba9242d14ef40ee2ec61584a0 (patch)
tree4fede47ee574df48437466f63b3724c0ce6d697e
parentad211ced81509462cdfe4c29ed10f97279a0acae (diff)
downloadrust-b9d6e9e73ffb2eaba9242d14ef40ee2ec61584a0.tar.gz
rust-b9d6e9e73ffb2eaba9242d14ef40ee2ec61584a0.zip
warn about broken simd not only on structs but also enums and unions when we didn't opt in to it
-rw-r--r--compiler/rustc_ast_passes/src/feature_gate.rs2
-rw-r--r--tests/ui/feature-gates/feature-gate-repr-simd.rs12
-rw-r--r--tests/ui/feature-gates/feature-gate-repr-simd.stderr44
-rw-r--r--tests/ui/repr/issue-83505-repr-simd.rs2
-rw-r--r--tests/ui/repr/issue-83505-repr-simd.stderr16
5 files changed, 67 insertions, 9 deletions
diff --git a/compiler/rustc_ast_passes/src/feature_gate.rs b/compiler/rustc_ast_passes/src/feature_gate.rs
index 3fbf1210186..c8500098add 100644
--- a/compiler/rustc_ast_passes/src/feature_gate.rs
+++ b/compiler/rustc_ast_passes/src/feature_gate.rs
@@ -242,7 +242,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
                 }
             }
 
-            ast::ItemKind::Struct(..) => {
+            ast::ItemKind::Struct(..) | ast::ItemKind::Enum(..) | ast::ItemKind::Union(..) => {
                 for attr in attr::filter_by_name(&i.attrs, sym::repr) {
                     for item in attr.meta_item_list().unwrap_or_else(ThinVec::new) {
                         if item.has_name(sym::simd) {
diff --git a/tests/ui/feature-gates/feature-gate-repr-simd.rs b/tests/ui/feature-gates/feature-gate-repr-simd.rs
index 65ade97c7e1..091dc479ef3 100644
--- a/tests/ui/feature-gates/feature-gate-repr-simd.rs
+++ b/tests/ui/feature-gates/feature-gate-repr-simd.rs
@@ -1,9 +1,17 @@
-#[repr(simd)] //~ error: SIMD types are experimental
+#[repr(simd)] //~ ERROR: SIMD types are experimental
 struct Foo([u64; 2]);
 
 #[repr(C)] //~ ERROR conflicting representation hints
 //~^ WARN this was previously accepted
-#[repr(simd)] //~ error: SIMD types are experimental
+#[repr(simd)] //~ ERROR: SIMD types are experimental
 struct Bar([u64; 2]);
 
+#[repr(simd)] //~ ERROR: SIMD types are experimental
+//~^ ERROR: attribute should be applied to a struct
+union U {f: u32}
+
+#[repr(simd)] //~ ERROR: SIMD types are experimental
+//~^ error: attribute should be applied to a struct
+enum E { X }
+
 fn main() {}
diff --git a/tests/ui/feature-gates/feature-gate-repr-simd.stderr b/tests/ui/feature-gates/feature-gate-repr-simd.stderr
index 5a0ceb2dd74..3bf8ec61705 100644
--- a/tests/ui/feature-gates/feature-gate-repr-simd.stderr
+++ b/tests/ui/feature-gates/feature-gate-repr-simd.stderr
@@ -18,6 +18,26 @@ LL | #[repr(simd)]
    = help: add `#![feature(repr_simd)]` to the crate attributes to enable
    = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
 
+error[E0658]: SIMD types are experimental and possibly buggy
+  --> $DIR/feature-gate-repr-simd.rs:9:1
+   |
+LL | #[repr(simd)]
+   | ^^^^^^^^^^^^^
+   |
+   = note: see issue #27731 <https://github.com/rust-lang/rust/issues/27731> for more information
+   = help: add `#![feature(repr_simd)]` to the crate attributes to enable
+   = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
+
+error[E0658]: SIMD types are experimental and possibly buggy
+  --> $DIR/feature-gate-repr-simd.rs:13:1
+   |
+LL | #[repr(simd)]
+   | ^^^^^^^^^^^^^
+   |
+   = note: see issue #27731 <https://github.com/rust-lang/rust/issues/27731> for more information
+   = help: add `#![feature(repr_simd)]` to the crate attributes to enable
+   = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
+
 error[E0566]: conflicting representation hints
   --> $DIR/feature-gate-repr-simd.rs:4:8
    |
@@ -31,10 +51,28 @@ LL | #[repr(simd)]
    = note: for more information, see issue #68585 <https://github.com/rust-lang/rust/issues/68585>
    = note: `#[deny(conflicting_repr_hints)]` on by default
 
-error: aborting due to 3 previous errors
+error[E0517]: attribute should be applied to a struct
+  --> $DIR/feature-gate-repr-simd.rs:9:8
+   |
+LL | #[repr(simd)]
+   |        ^^^^
+LL |
+LL | union U {f: u32}
+   | ---------------- not a struct
+
+error[E0517]: attribute should be applied to a struct
+  --> $DIR/feature-gate-repr-simd.rs:13:8
+   |
+LL | #[repr(simd)]
+   |        ^^^^
+LL |
+LL | enum E { X }
+   | ------------ not a struct
+
+error: aborting due to 7 previous errors
 
-Some errors have detailed explanations: E0566, E0658.
-For more information about an error, try `rustc --explain E0566`.
+Some errors have detailed explanations: E0517, E0566, E0658.
+For more information about an error, try `rustc --explain E0517`.
 Future incompatibility report: Future breakage diagnostic:
 error[E0566]: conflicting representation hints
   --> $DIR/feature-gate-repr-simd.rs:4:8
diff --git a/tests/ui/repr/issue-83505-repr-simd.rs b/tests/ui/repr/issue-83505-repr-simd.rs
index 280b771d015..bebbc636728 100644
--- a/tests/ui/repr/issue-83505-repr-simd.rs
+++ b/tests/ui/repr/issue-83505-repr-simd.rs
@@ -5,6 +5,8 @@
 #[repr(simd)]
 //~^ ERROR: attribute should be applied to a struct [E0517]
 //~| ERROR: unsupported representation for zero-variant enum [E0084]
+//~| ERROR: SIMD types are experimental and possibly buggy [E0658]
+
 enum Es {}
 static CLs: Es;
 //~^ ERROR: free static item without body
diff --git a/tests/ui/repr/issue-83505-repr-simd.stderr b/tests/ui/repr/issue-83505-repr-simd.stderr
index df99baaf522..44e154b4bb6 100644
--- a/tests/ui/repr/issue-83505-repr-simd.stderr
+++ b/tests/ui/repr/issue-83505-repr-simd.stderr
@@ -1,11 +1,21 @@
 error: free static item without body
-  --> $DIR/issue-83505-repr-simd.rs:9:1
+  --> $DIR/issue-83505-repr-simd.rs:11:1
    |
 LL | static CLs: Es;
    | ^^^^^^^^^^^^^^-
    |               |
    |               help: provide a definition for the static: `= <expr>;`
 
+error[E0658]: SIMD types are experimental and possibly buggy
+  --> $DIR/issue-83505-repr-simd.rs:5:1
+   |
+LL | #[repr(simd)]
+   | ^^^^^^^^^^^^^
+   |
+   = note: see issue #27731 <https://github.com/rust-lang/rust/issues/27731> for more information
+   = help: add `#![feature(repr_simd)]` to the crate attributes to enable
+   = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
+
 error[E0517]: attribute should be applied to a struct
   --> $DIR/issue-83505-repr-simd.rs:5:8
    |
@@ -24,7 +34,7 @@ LL | #[repr(simd)]
 LL | enum Es {}
    | ------- zero-variant enum
 
-error: aborting due to 3 previous errors
+error: aborting due to 4 previous errors
 
-Some errors have detailed explanations: E0084, E0517.
+Some errors have detailed explanations: E0084, E0517, E0658.
 For more information about an error, try `rustc --explain E0084`.