about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2019-06-09 23:50:04 +0000
committerbors <bors@rust-lang.org>2019-06-09 23:50:04 +0000
commit61a60ce7d369b54e209003e9e92bf90d6f5e5d4b (patch)
tree0b606c3a8160219d9b02f75fdeb656c3a3c7a0e2
parent400b409efc4975a082185c5a74412572e49dfd98 (diff)
parentc25e3d2be5825463cf63c518854b583fbc9e8386 (diff)
downloadrust-61a60ce7d369b54e209003e9e92bf90d6f5e5d4b.tar.gz
rust-61a60ce7d369b54e209003e9e92bf90d6f5e5d4b.zip
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
-rw-r--r--src/doc/unstable-book/src/language-features/repr-align-enum.md42
-rw-r--r--src/libsyntax/feature_gate.rs17
-rw-r--r--src/test/codegen/align-enum.rs1
-rw-r--r--src/test/run-pass/structs-enums/align-enum.rs1
-rw-r--r--src/test/ui/attr-usage-repr.rs1
-rw-r--r--src/test/ui/attr-usage-repr.stderr8
-rw-r--r--src/test/ui/feature-gates/feature-gate-repr_align_enum.rs10
-rw-r--r--src/test/ui/feature-gates/feature-gate-repr_align_enum.stderr12
-rw-r--r--src/test/ui/repr/repr-align.rs20
-rw-r--r--src/test/ui/repr/repr-align.stderr22
10 files changed, 38 insertions, 96 deletions
diff --git a/src/doc/unstable-book/src/language-features/repr-align-enum.md b/src/doc/unstable-book/src/language-features/repr-align-enum.md
deleted file mode 100644
index 415c6ebe8b4..00000000000
--- a/src/doc/unstable-book/src/language-features/repr-align-enum.md
+++ /dev/null
@@ -1,42 +0,0 @@
-# `repr_align_enum`
-
-The tracking issue for this feature is: [#57996]
-
-[#57996]: https://github.com/rust-lang/rust/issues/57996
-
-------------------------
-
-The `repr_align_enum` feature allows using the `#[repr(align(x))]` attribute
-on enums, similarly to structs.
-
-# Examples
-
-```rust
-#![feature(repr_align_enum)]
-
-#[repr(align(8))]
-enum Aligned {
-    Foo,
-    Bar { value: u32 },
-}
-
-fn main() {
-    assert_eq!(std::mem::align_of::<Aligned>(), 8);
-}
-```
-
-This is equivalent to using an aligned wrapper struct everywhere:
-
-```rust
-#[repr(align(8))]
-struct Aligned(Unaligned);
-
-enum Unaligned {
-    Foo,
-    Bar { value: u32 },
-}
-
-fn main() {
-    assert_eq!(std::mem::align_of::<Aligned>(), 8);
-}
-```
diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs
index 7119fd13fbb..bbb297e3c4f 100644
--- a/src/libsyntax/feature_gate.rs
+++ b/src/libsyntax/feature_gate.rs
@@ -551,9 +551,6 @@ declare_features! (
     // Allows using `#[optimize(X)]`.
     (active, optimize_attribute, "1.34.0", Some(54882), None),
 
-    // Allows using `#[repr(align(X))]` on enums.
-    (active, repr_align_enum, "1.34.0", Some(57996), None),
-
     // Allows using C-variadics.
     (active, c_variadic, "1.34.0", Some(44930), None),
 
@@ -843,6 +840,9 @@ declare_features! (
     (accepted, extern_crate_self, "1.34.0", Some(56409), None),
     // Allows arbitrary delimited token streams in non-macro attributes.
     (accepted, unrestricted_attribute_tokens, "1.34.0", Some(55208), None),
+    // Allows using `#[repr(align(X))]` on enums with equivalent semantics
+    // to wrapping an enum in a wrapper struct with `#[repr(align(X))]`.
+    (accepted, repr_align_enum, "1.37.0", Some(57996), None),
 
     // -------------------------------------------------------------------------
     // feature-group-end: accepted features
@@ -2033,17 +2033,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
                 }
             }
 
-            ast::ItemKind::Enum(..) => {
-                for attr in attr::filter_by_name(&i.attrs[..], sym::repr) {
-                    for item in attr.meta_item_list().unwrap_or_else(Vec::new) {
-                        if item.check_name(sym::align) {
-                            gate_feature_post!(&self, repr_align_enum, attr.span,
-                                               "`#[repr(align(x))]` on enums is experimental");
-                        }
-                    }
-                }
-            }
-
             ast::ItemKind::Impl(_, polarity, defaultness, _, _, _, _) => {
                 if polarity == ast::ImplPolarity::Negative {
                     gate_feature_post!(&self, optin_builtin_traits,
diff --git a/src/test/codegen/align-enum.rs b/src/test/codegen/align-enum.rs
index 2251c54229e..4241fcea804 100644
--- a/src/test/codegen/align-enum.rs
+++ b/src/test/codegen/align-enum.rs
@@ -3,7 +3,6 @@
 // min-llvm-version 7.0
 
 #![crate_type = "lib"]
-#![feature(repr_align_enum)]
 
 #[repr(align(64))]
 pub enum Align64 {
diff --git a/src/test/run-pass/structs-enums/align-enum.rs b/src/test/run-pass/structs-enums/align-enum.rs
index 8d72b1f6f0d..fa872caa3b4 100644
--- a/src/test/run-pass/structs-enums/align-enum.rs
+++ b/src/test/run-pass/structs-enums/align-enum.rs
@@ -1,6 +1,5 @@
 // run-pass
 #![allow(dead_code)]
-#![feature(repr_align_enum)]
 
 use std::mem;
 
diff --git a/src/test/ui/attr-usage-repr.rs b/src/test/ui/attr-usage-repr.rs
index 1df2947cbe2..ef64dfe20bc 100644
--- a/src/test/ui/attr-usage-repr.rs
+++ b/src/test/ui/attr-usage-repr.rs
@@ -1,5 +1,4 @@
 #![feature(repr_simd)]
-#![feature(repr_align_enum)]
 
 #[repr(C)] //~ ERROR: attribute should be applied to struct, enum or union
 fn f() {}
diff --git a/src/test/ui/attr-usage-repr.stderr b/src/test/ui/attr-usage-repr.stderr
index f8ad7eec454..d1f4f3bfeb2 100644
--- a/src/test/ui/attr-usage-repr.stderr
+++ b/src/test/ui/attr-usage-repr.stderr
@@ -1,5 +1,5 @@
 error[E0517]: attribute should be applied to struct, enum or union
-  --> $DIR/attr-usage-repr.rs:4:8
+  --> $DIR/attr-usage-repr.rs:3:8
    |
 LL | #[repr(C)]
    |        ^
@@ -7,7 +7,7 @@ LL | fn f() {}
    | --------- not a struct, enum or union
 
 error[E0517]: attribute should be applied to enum
-  --> $DIR/attr-usage-repr.rs:16:8
+  --> $DIR/attr-usage-repr.rs:15:8
    |
 LL | #[repr(i8)]
    |        ^^
@@ -15,7 +15,7 @@ LL | struct SInt(f64, f64);
    | ---------------------- not an enum
 
 error[E0517]: attribute should be applied to struct or union
-  --> $DIR/attr-usage-repr.rs:25:8
+  --> $DIR/attr-usage-repr.rs:24:8
    |
 LL | #[repr(packed)]
    |        ^^^^^^
@@ -23,7 +23,7 @@ LL | enum EPacked { A, B }
    | --------------------- not a struct or union
 
 error[E0517]: attribute should be applied to struct
-  --> $DIR/attr-usage-repr.rs:28:8
+  --> $DIR/attr-usage-repr.rs:27:8
    |
 LL | #[repr(simd)]
    |        ^^^^
diff --git a/src/test/ui/feature-gates/feature-gate-repr_align_enum.rs b/src/test/ui/feature-gates/feature-gate-repr_align_enum.rs
deleted file mode 100644
index 8b68caa6f5b..00000000000
--- a/src/test/ui/feature-gates/feature-gate-repr_align_enum.rs
+++ /dev/null
@@ -1,10 +0,0 @@
-#[repr(align(16))]
-struct Foo(u64);
-
-#[repr(align(8))] //~ ERROR `#[repr(align(x))]` on enums is experimental
-enum Bar {
-    Foo { foo: Foo },
-    Baz,
-}
-
-fn main() { }
diff --git a/src/test/ui/feature-gates/feature-gate-repr_align_enum.stderr b/src/test/ui/feature-gates/feature-gate-repr_align_enum.stderr
deleted file mode 100644
index 36924f4c167..00000000000
--- a/src/test/ui/feature-gates/feature-gate-repr_align_enum.stderr
+++ /dev/null
@@ -1,12 +0,0 @@
-error[E0658]: `#[repr(align(x))]` on enums is experimental
-  --> $DIR/feature-gate-repr_align_enum.rs:4:1
-   |
-LL | #[repr(align(8))]
-   | ^^^^^^^^^^^^^^^^^
-   |
-   = note: for more information, see https://github.com/rust-lang/rust/issues/57996
-   = help: add #![feature(repr_align_enum)] to the crate attributes to enable
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0658`.
diff --git a/src/test/ui/repr/repr-align.rs b/src/test/ui/repr/repr-align.rs
index 9ce89e82ca2..bc6a9fe562a 100644
--- a/src/test/ui/repr/repr-align.rs
+++ b/src/test/ui/repr/repr-align.rs
@@ -1,19 +1,27 @@
-#![feature(repr_align_enum)]
 #![allow(dead_code)]
 
 #[repr(align(16.0))] //~ ERROR: invalid `repr(align)` attribute: not an unsuffixed integer
-struct A(i32);
+struct S0(i32);
 
 #[repr(align(15))] //~ ERROR: invalid `repr(align)` attribute: not a power of two
-struct B(i32);
+struct S1(i32);
 
 #[repr(align(4294967296))] //~ ERROR: invalid `repr(align)` attribute: larger than 2^29
-struct C(i32);
+struct S2(i32);
 
 #[repr(align(536870912))] // ok: this is the largest accepted alignment
-struct D(i32);
+struct S3(i32);
+
+#[repr(align(16.0))] //~ ERROR: invalid `repr(align)` attribute: not an unsuffixed integer
+enum E0 { A, B }
 
 #[repr(align(15))] //~ ERROR: invalid `repr(align)` attribute: not a power of two
-enum E { Left, Right }
+enum E1 { A, B }
+
+#[repr(align(4294967296))] //~ ERROR: invalid `repr(align)` attribute: larger than 2^29
+enum E2 { A, B }
+
+#[repr(align(536870912))] // ok: this is the largest accepted alignment
+enum E3 { A, B }
 
 fn main() {}
diff --git a/src/test/ui/repr/repr-align.stderr b/src/test/ui/repr/repr-align.stderr
index 641f117a717..280cab2b4a1 100644
--- a/src/test/ui/repr/repr-align.stderr
+++ b/src/test/ui/repr/repr-align.stderr
@@ -1,27 +1,39 @@
 error[E0589]: invalid `repr(align)` attribute: not an unsuffixed integer
-  --> $DIR/repr-align.rs:4:8
+  --> $DIR/repr-align.rs:3:8
    |
 LL | #[repr(align(16.0))]
    |        ^^^^^^^^^^^
 
 error[E0589]: invalid `repr(align)` attribute: not a power of two
-  --> $DIR/repr-align.rs:7:8
+  --> $DIR/repr-align.rs:6:8
    |
 LL | #[repr(align(15))]
    |        ^^^^^^^^^
 
 error[E0589]: invalid `repr(align)` attribute: larger than 2^29
-  --> $DIR/repr-align.rs:10:8
+  --> $DIR/repr-align.rs:9:8
    |
 LL | #[repr(align(4294967296))]
    |        ^^^^^^^^^^^^^^^^^
 
+error[E0589]: invalid `repr(align)` attribute: not an unsuffixed integer
+  --> $DIR/repr-align.rs:15:8
+   |
+LL | #[repr(align(16.0))]
+   |        ^^^^^^^^^^^
+
 error[E0589]: invalid `repr(align)` attribute: not a power of two
-  --> $DIR/repr-align.rs:16:8
+  --> $DIR/repr-align.rs:18:8
    |
 LL | #[repr(align(15))]
    |        ^^^^^^^^^
 
-error: aborting due to 4 previous errors
+error[E0589]: invalid `repr(align)` attribute: larger than 2^29
+  --> $DIR/repr-align.rs:21:8
+   |
+LL | #[repr(align(4294967296))]
+   |        ^^^^^^^^^^^^^^^^^
+
+error: aborting due to 6 previous errors
 
 For more information about this error, try `rustc --explain E0589`.