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
This commit is contained in:
commit
61a60ce7d3
@ -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);
|
||||
}
|
||||
```
|
@ -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,
|
||||
|
@ -3,7 +3,6 @@
|
||||
// min-llvm-version 7.0
|
||||
|
||||
#![crate_type = "lib"]
|
||||
#![feature(repr_align_enum)]
|
||||
|
||||
#[repr(align(64))]
|
||||
pub enum Align64 {
|
||||
|
@ -1,6 +1,5 @@
|
||||
// run-pass
|
||||
#![allow(dead_code)]
|
||||
#![feature(repr_align_enum)]
|
||||
|
||||
use std::mem;
|
||||
|
||||
|
@ -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() {}
|
||||
|
@ -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)]
|
||||
| ^^^^
|
||||
|
@ -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() { }
|
@ -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`.
|
@ -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() {}
|
||||
|
@ -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`.
|
||||
|
Loading…
x
Reference in New Issue
Block a user