Skip to content

Commit 61a60ce

Browse files
committed
Auto merge of #61229 - Centril:stabilize-repr_align_enum, r=nagisa
Stabilize #![feature(repr_align_enum)] in Rust 1.37.0 On an `enum` item, you may now write: ```rust #[repr(align(X))] enum Foo { // ... } ``` This has equivalent effects to first defining: ```rust #[repr(align(X))] struct AlignX<T>(T); ``` and then using `AlignX<Foo>` in `Foo`'s stead. r? @nagisa
2 parents 400b409 + c25e3d2 commit 61a60ce

File tree

10 files changed

+38
-96
lines changed

10 files changed

+38
-96
lines changed

src/doc/unstable-book/src/language-features/repr-align-enum.md

-42
This file was deleted.

src/libsyntax/feature_gate.rs

+3-14
Original file line numberDiff line numberDiff line change
@@ -551,9 +551,6 @@ declare_features! (
551551
// Allows using `#[optimize(X)]`.
552552
(active, optimize_attribute, "1.34.0", Some(54882), None),
553553

554-
// Allows using `#[repr(align(X))]` on enums.
555-
(active, repr_align_enum, "1.34.0", Some(57996), None),
556-
557554
// Allows using C-variadics.
558555
(active, c_variadic, "1.34.0", Some(44930), None),
559556

@@ -843,6 +840,9 @@ declare_features! (
843840
(accepted, extern_crate_self, "1.34.0", Some(56409), None),
844841
// Allows arbitrary delimited token streams in non-macro attributes.
845842
(accepted, unrestricted_attribute_tokens, "1.34.0", Some(55208), None),
843+
// Allows using `#[repr(align(X))]` on enums with equivalent semantics
844+
// to wrapping an enum in a wrapper struct with `#[repr(align(X))]`.
845+
(accepted, repr_align_enum, "1.37.0", Some(57996), None),
846846

847847
// -------------------------------------------------------------------------
848848
// feature-group-end: accepted features
@@ -2033,17 +2033,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
20332033
}
20342034
}
20352035

2036-
ast::ItemKind::Enum(..) => {
2037-
for attr in attr::filter_by_name(&i.attrs[..], sym::repr) {
2038-
for item in attr.meta_item_list().unwrap_or_else(Vec::new) {
2039-
if item.check_name(sym::align) {
2040-
gate_feature_post!(&self, repr_align_enum, attr.span,
2041-
"`#[repr(align(x))]` on enums is experimental");
2042-
}
2043-
}
2044-
}
2045-
}
2046-
20472036
ast::ItemKind::Impl(_, polarity, defaultness, _, _, _, _) => {
20482037
if polarity == ast::ImplPolarity::Negative {
20492038
gate_feature_post!(&self, optin_builtin_traits,

src/test/codegen/align-enum.rs

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// min-llvm-version 7.0
44

55
#![crate_type = "lib"]
6-
#![feature(repr_align_enum)]
76

87
#[repr(align(64))]
98
pub enum Align64 {

src/test/run-pass/structs-enums/align-enum.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// run-pass
22
#![allow(dead_code)]
3-
#![feature(repr_align_enum)]
43

54
use std::mem;
65

src/test/ui/attr-usage-repr.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#![feature(repr_simd)]
2-
#![feature(repr_align_enum)]
32

43
#[repr(C)] //~ ERROR: attribute should be applied to struct, enum or union
54
fn f() {}

src/test/ui/attr-usage-repr.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
error[E0517]: attribute should be applied to struct, enum or union
2-
--> $DIR/attr-usage-repr.rs:4:8
2+
--> $DIR/attr-usage-repr.rs:3:8
33
|
44
LL | #[repr(C)]
55
| ^
66
LL | fn f() {}
77
| --------- not a struct, enum or union
88

99
error[E0517]: attribute should be applied to enum
10-
--> $DIR/attr-usage-repr.rs:16:8
10+
--> $DIR/attr-usage-repr.rs:15:8
1111
|
1212
LL | #[repr(i8)]
1313
| ^^
1414
LL | struct SInt(f64, f64);
1515
| ---------------------- not an enum
1616

1717
error[E0517]: attribute should be applied to struct or union
18-
--> $DIR/attr-usage-repr.rs:25:8
18+
--> $DIR/attr-usage-repr.rs:24:8
1919
|
2020
LL | #[repr(packed)]
2121
| ^^^^^^
2222
LL | enum EPacked { A, B }
2323
| --------------------- not a struct or union
2424

2525
error[E0517]: attribute should be applied to struct
26-
--> $DIR/attr-usage-repr.rs:28:8
26+
--> $DIR/attr-usage-repr.rs:27:8
2727
|
2828
LL | #[repr(simd)]
2929
| ^^^^

src/test/ui/feature-gates/feature-gate-repr_align_enum.rs

-10
This file was deleted.

src/test/ui/feature-gates/feature-gate-repr_align_enum.stderr

-12
This file was deleted.

src/test/ui/repr/repr-align.rs

+14-6
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,27 @@
1-
#![feature(repr_align_enum)]
21
#![allow(dead_code)]
32

43
#[repr(align(16.0))] //~ ERROR: invalid `repr(align)` attribute: not an unsuffixed integer
5-
struct A(i32);
4+
struct S0(i32);
65

76
#[repr(align(15))] //~ ERROR: invalid `repr(align)` attribute: not a power of two
8-
struct B(i32);
7+
struct S1(i32);
98

109
#[repr(align(4294967296))] //~ ERROR: invalid `repr(align)` attribute: larger than 2^29
11-
struct C(i32);
10+
struct S2(i32);
1211

1312
#[repr(align(536870912))] // ok: this is the largest accepted alignment
14-
struct D(i32);
13+
struct S3(i32);
14+
15+
#[repr(align(16.0))] //~ ERROR: invalid `repr(align)` attribute: not an unsuffixed integer
16+
enum E0 { A, B }
1517

1618
#[repr(align(15))] //~ ERROR: invalid `repr(align)` attribute: not a power of two
17-
enum E { Left, Right }
19+
enum E1 { A, B }
20+
21+
#[repr(align(4294967296))] //~ ERROR: invalid `repr(align)` attribute: larger than 2^29
22+
enum E2 { A, B }
23+
24+
#[repr(align(536870912))] // ok: this is the largest accepted alignment
25+
enum E3 { A, B }
1826

1927
fn main() {}

src/test/ui/repr/repr-align.stderr

+17-5
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,39 @@
11
error[E0589]: invalid `repr(align)` attribute: not an unsuffixed integer
2-
--> $DIR/repr-align.rs:4:8
2+
--> $DIR/repr-align.rs:3:8
33
|
44
LL | #[repr(align(16.0))]
55
| ^^^^^^^^^^^
66

77
error[E0589]: invalid `repr(align)` attribute: not a power of two
8-
--> $DIR/repr-align.rs:7:8
8+
--> $DIR/repr-align.rs:6:8
99
|
1010
LL | #[repr(align(15))]
1111
| ^^^^^^^^^
1212

1313
error[E0589]: invalid `repr(align)` attribute: larger than 2^29
14-
--> $DIR/repr-align.rs:10:8
14+
--> $DIR/repr-align.rs:9:8
1515
|
1616
LL | #[repr(align(4294967296))]
1717
| ^^^^^^^^^^^^^^^^^
1818

19+
error[E0589]: invalid `repr(align)` attribute: not an unsuffixed integer
20+
--> $DIR/repr-align.rs:15:8
21+
|
22+
LL | #[repr(align(16.0))]
23+
| ^^^^^^^^^^^
24+
1925
error[E0589]: invalid `repr(align)` attribute: not a power of two
20-
--> $DIR/repr-align.rs:16:8
26+
--> $DIR/repr-align.rs:18:8
2127
|
2228
LL | #[repr(align(15))]
2329
| ^^^^^^^^^
2430

25-
error: aborting due to 4 previous errors
31+
error[E0589]: invalid `repr(align)` attribute: larger than 2^29
32+
--> $DIR/repr-align.rs:21:8
33+
|
34+
LL | #[repr(align(4294967296))]
35+
| ^^^^^^^^^^^^^^^^^
36+
37+
error: aborting due to 6 previous errors
2638

2739
For more information about this error, try `rustc --explain E0589`.

0 commit comments

Comments
 (0)