1
Fork 0

Stabilize repr_align_enum in 1.37.0.

This commit is contained in:
Mazdak Farrokhzad 2019-05-27 07:26:11 +02:00
parent ed2a5115da
commit de1e1ad706
10 changed files with 11 additions and 90 deletions

View file

@ -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);
}
```

View file

@ -548,9 +548,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),
@ -833,6 +830,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
@ -1995,17 +1995,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,

View file

@ -3,7 +3,6 @@
// min-llvm-version 7.0
#![crate_type = "lib"]
#![feature(repr_align_enum)]
#[repr(align(64))]
pub enum Align64 {

View file

@ -1,6 +1,5 @@
// run-pass
#![allow(dead_code)]
#![feature(repr_align_enum)]
use std::mem;

View file

@ -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() {}

View file

@ -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)]
| ^^^^

View file

@ -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() { }

View file

@ -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`.

View file

@ -1,4 +1,3 @@
#![feature(repr_align_enum)]
#![allow(dead_code)]
#[repr(align(16.0))] //~ ERROR: invalid `repr(align)` attribute: not an unsuffixed integer

View file

@ -1,23 +1,23 @@
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 a power of two
--> $DIR/repr-align.rs:16:8
--> $DIR/repr-align.rs:15:8
|
LL | #[repr(align(15))]
| ^^^^^^^^^