Skip to content

Commit 846a9c4

Browse files
authored
Rollup merge of rust-lang#135219 - matthiaskrgr:simd'nt, r=compiler-errors
warn about broken simd not only on structs but also enums and unions when we didn't opt in to it addresses rust-lang#135208 (comment) r? `@Noratrieb`
2 parents f6508ff + b9d6e9e commit 846a9c4

File tree

5 files changed

+67
-9
lines changed

5 files changed

+67
-9
lines changed

compiler/rustc_ast_passes/src/feature_gate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
242242
}
243243
}
244244

245-
ast::ItemKind::Struct(..) => {
245+
ast::ItemKind::Struct(..) | ast::ItemKind::Enum(..) | ast::ItemKind::Union(..) => {
246246
for attr in attr::filter_by_name(&i.attrs, sym::repr) {
247247
for item in attr.meta_item_list().unwrap_or_else(ThinVec::new) {
248248
if item.has_name(sym::simd) {
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
1-
#[repr(simd)] //~ error: SIMD types are experimental
1+
#[repr(simd)] //~ ERROR: SIMD types are experimental
22
struct Foo([u64; 2]);
33

44
#[repr(C)] //~ ERROR conflicting representation hints
55
//~^ WARN this was previously accepted
6-
#[repr(simd)] //~ error: SIMD types are experimental
6+
#[repr(simd)] //~ ERROR: SIMD types are experimental
77
struct Bar([u64; 2]);
88

9+
#[repr(simd)] //~ ERROR: SIMD types are experimental
10+
//~^ ERROR: attribute should be applied to a struct
11+
union U {f: u32}
12+
13+
#[repr(simd)] //~ ERROR: SIMD types are experimental
14+
//~^ error: attribute should be applied to a struct
15+
enum E { X }
16+
917
fn main() {}

tests/ui/feature-gates/feature-gate-repr-simd.stderr

+41-3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,26 @@ LL | #[repr(simd)]
1818
= help: add `#![feature(repr_simd)]` to the crate attributes to enable
1919
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
2020

21+
error[E0658]: SIMD types are experimental and possibly buggy
22+
--> $DIR/feature-gate-repr-simd.rs:9:1
23+
|
24+
LL | #[repr(simd)]
25+
| ^^^^^^^^^^^^^
26+
|
27+
= note: see issue #27731 <https://github.com/rust-lang/rust/issues/27731> for more information
28+
= help: add `#![feature(repr_simd)]` to the crate attributes to enable
29+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
30+
31+
error[E0658]: SIMD types are experimental and possibly buggy
32+
--> $DIR/feature-gate-repr-simd.rs:13:1
33+
|
34+
LL | #[repr(simd)]
35+
| ^^^^^^^^^^^^^
36+
|
37+
= note: see issue #27731 <https://github.com/rust-lang/rust/issues/27731> for more information
38+
= help: add `#![feature(repr_simd)]` to the crate attributes to enable
39+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
40+
2141
error[E0566]: conflicting representation hints
2242
--> $DIR/feature-gate-repr-simd.rs:4:8
2343
|
@@ -31,10 +51,28 @@ LL | #[repr(simd)]
3151
= note: for more information, see issue #68585 <https://github.com/rust-lang/rust/issues/68585>
3252
= note: `#[deny(conflicting_repr_hints)]` on by default
3353

34-
error: aborting due to 3 previous errors
54+
error[E0517]: attribute should be applied to a struct
55+
--> $DIR/feature-gate-repr-simd.rs:9:8
56+
|
57+
LL | #[repr(simd)]
58+
| ^^^^
59+
LL |
60+
LL | union U {f: u32}
61+
| ---------------- not a struct
62+
63+
error[E0517]: attribute should be applied to a struct
64+
--> $DIR/feature-gate-repr-simd.rs:13:8
65+
|
66+
LL | #[repr(simd)]
67+
| ^^^^
68+
LL |
69+
LL | enum E { X }
70+
| ------------ not a struct
71+
72+
error: aborting due to 7 previous errors
3573

36-
Some errors have detailed explanations: E0566, E0658.
37-
For more information about an error, try `rustc --explain E0566`.
74+
Some errors have detailed explanations: E0517, E0566, E0658.
75+
For more information about an error, try `rustc --explain E0517`.
3876
Future incompatibility report: Future breakage diagnostic:
3977
error[E0566]: conflicting representation hints
4078
--> $DIR/feature-gate-repr-simd.rs:4:8

tests/ui/repr/issue-83505-repr-simd.rs

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#[repr(simd)]
66
//~^ ERROR: attribute should be applied to a struct [E0517]
77
//~| ERROR: unsupported representation for zero-variant enum [E0084]
8+
//~| ERROR: SIMD types are experimental and possibly buggy [E0658]
9+
810
enum Es {}
911
static CLs: Es;
1012
//~^ ERROR: free static item without body

tests/ui/repr/issue-83505-repr-simd.stderr

+13-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
error: free static item without body
2-
--> $DIR/issue-83505-repr-simd.rs:9:1
2+
--> $DIR/issue-83505-repr-simd.rs:11:1
33
|
44
LL | static CLs: Es;
55
| ^^^^^^^^^^^^^^-
66
| |
77
| help: provide a definition for the static: `= <expr>;`
88

9+
error[E0658]: SIMD types are experimental and possibly buggy
10+
--> $DIR/issue-83505-repr-simd.rs:5:1
11+
|
12+
LL | #[repr(simd)]
13+
| ^^^^^^^^^^^^^
14+
|
15+
= note: see issue #27731 <https://github.com/rust-lang/rust/issues/27731> for more information
16+
= help: add `#![feature(repr_simd)]` to the crate attributes to enable
17+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
18+
919
error[E0517]: attribute should be applied to a struct
1020
--> $DIR/issue-83505-repr-simd.rs:5:8
1121
|
@@ -24,7 +34,7 @@ LL | #[repr(simd)]
2434
LL | enum Es {}
2535
| ------- zero-variant enum
2636

27-
error: aborting due to 3 previous errors
37+
error: aborting due to 4 previous errors
2838

29-
Some errors have detailed explanations: E0084, E0517.
39+
Some errors have detailed explanations: E0084, E0517, E0658.
3040
For more information about an error, try `rustc --explain E0084`.

0 commit comments

Comments
 (0)