Skip to content

warn about broken simd not only on structs but also enums and unions when we didn't opt in to it #135219

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 8, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_ast_passes/src/feature_gate.rs
Original file line number Diff line number Diff line change
@@ -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) {
12 changes: 10 additions & 2 deletions tests/ui/feature-gates/feature-gate-repr-simd.rs
Original file line number Diff line number Diff line change
@@ -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() {}
44 changes: 41 additions & 3 deletions tests/ui/feature-gates/feature-gate-repr-simd.stderr
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions tests/ui/repr/issue-83505-repr-simd.rs
Original file line number Diff line number Diff line change
@@ -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
16 changes: 13 additions & 3 deletions tests/ui/repr/issue-83505-repr-simd.stderr
Original file line number Diff line number Diff line change
@@ -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`.