Skip to content

Commit

Permalink
Auto merge of #47006 - bitshifter:stabilize-repr-align, r=eddyb
Browse files Browse the repository at this point in the history
Stabilized `#[repr(align(x))]` attribute (RFC 1358)

Stabilzed `#[repr(align(x))]` with attr_literal syntax as proposed by @eddyb #33626 (comment)
  • Loading branch information
bors committed Jan 25, 2018
2 parents a0dcecf + 651ea8e commit a0a9007
Show file tree
Hide file tree
Showing 14 changed files with 20 additions and 65 deletions.
1 change: 0 additions & 1 deletion src/liballoc/tests/lib.rs
Expand Up @@ -23,7 +23,6 @@
#![feature(pattern)]
#![feature(placement_in_syntax)]
#![feature(rand)]
#![feature(repr_align)]
#![feature(slice_rotate)]
#![feature(splice)]
#![feature(str_escape)]
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/lib.rs
Expand Up @@ -296,7 +296,6 @@
#![feature(ptr_internals)]
#![feature(rand)]
#![feature(raw)]
#![feature(repr_align)]
#![feature(rustc_attrs)]
#![feature(sip_hash_13)]
#![feature(slice_bytes)]
Expand All @@ -323,6 +322,7 @@
#![feature(doc_spotlight)]
#![cfg_attr(test, feature(update_panic_count))]
#![cfg_attr(windows, feature(used))]
#![cfg_attr(stage0, feature(repr_align))]

#![default_lib_allocator]

Expand Down
30 changes: 17 additions & 13 deletions src/libsyntax/feature_gate.rs
Expand Up @@ -343,9 +343,6 @@ declare_features! (
// Allows the `catch {...}` expression
(active, catch_expr, "1.17.0", Some(31436)),

// Allows `repr(align(u16))` struct attribute (RFC 1358)
(active, repr_align, "1.17.0", Some(33626)),

// Used to preserve symbols (see llvm.used)
(active, used, "1.18.0", Some(40289)),

Expand Down Expand Up @@ -546,6 +543,8 @@ declare_features! (
// Allows the sysV64 ABI to be specified on all platforms
// instead of just the platforms on which it is the C ABI
(accepted, abi_sysv64, "1.24.0", Some(36167)),
// Allows `repr(align(16))` struct attribute (RFC 1358)
(accepted, repr_align, "1.24.0", Some(33626)),
);

// If you change this, please modify src/doc/unstable-book as well. You must
Expand Down Expand Up @@ -1456,15 +1455,25 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
}
}

// allow attr_literals in #[repr(align(x))]
let mut is_repr_align = false;
if attr.path == "repr" {
if let Some(content) = attr.meta_item_list() {
is_repr_align = content.iter().any(|c| c.check_name("align"));
}
}

if self.context.features.proc_macro && attr::is_known(attr) {
return
}

let meta = panictry!(attr.parse_meta(self.context.parse_sess));
if contains_novel_literal(&meta) {
gate_feature_post!(&self, attr_literals, attr.span,
"non-string literals in attributes, or string \
literals in top-level positions, are experimental");
if !is_repr_align {
let meta = panictry!(attr.parse_meta(self.context.parse_sess));
if contains_novel_literal(&meta) {
gate_feature_post!(&self, attr_literals, attr.span,
"non-string literals in attributes, or string \
literals in top-level positions, are experimental");
}
}
}

Expand Down Expand Up @@ -1522,11 +1531,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
gate_feature_post!(&self, repr_simd, attr.span,
"SIMD types are experimental and possibly buggy");
}
if item.check_name("align") {
gate_feature_post!(&self, repr_align, attr.span,
"the struct `#[repr(align(u16))]` attribute \
is experimental");
}
if item.check_name("transparent") {
gate_feature_post!(&self, repr_transparent, attr.span,
"the `#[repr(transparent)]` attribute \
Expand Down
3 changes: 0 additions & 3 deletions src/test/codegen/align-struct.rs
Expand Up @@ -13,9 +13,6 @@

#![crate_type = "lib"]

#![feature(attr_literals)]
#![feature(repr_align)]

#[repr(align(64))]
pub struct Align64(i32);
// CHECK: %Align64 = type { [0 x i32], i32, [15 x i32] }
Expand Down
2 changes: 0 additions & 2 deletions src/test/compile-fail/conflicting-repr-hints.rs
Expand Up @@ -9,8 +9,6 @@
// except according to those terms.

#![allow(dead_code)]
#![feature(attr_literals)]
#![feature(repr_align)]

#[repr(C)]
enum A { A }
Expand Down
2 changes: 0 additions & 2 deletions src/test/compile-fail/repr-align.rs
Expand Up @@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![allow(dead_code)]
#![feature(attr_literals)]
#![feature(repr_align)]

#[repr(align(16.0))] //~ ERROR: invalid `repr(align)` attribute: not an unsuffixed integer
struct A(i32);
Expand Down
2 changes: 0 additions & 2 deletions src/test/compile-fail/repr-packed-contains-align.rs
Expand Up @@ -7,8 +7,6 @@
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(attr_literals)]
#![feature(repr_align)]
#![feature(untagged_unions)]
#![allow(dead_code)]

Expand Down
2 changes: 0 additions & 2 deletions src/test/run-pass/align-struct.rs
Expand Up @@ -7,8 +7,6 @@
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(attr_literals)]
#![feature(repr_align)]
#![feature(box_syntax)]

use std::mem;
Expand Down
2 changes: 0 additions & 2 deletions src/test/run-pass/union/union-align.rs
Expand Up @@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(attr_literals)]
#![feature(repr_align)]
#![feature(untagged_unions)]

use std::mem::{size_of, size_of_val, align_of, align_of_val};
Expand Down
15 changes: 0 additions & 15 deletions src/test/ui/feature-gate-repr_align.rs

This file was deleted.

10 changes: 0 additions & 10 deletions src/test/ui/feature-gate-repr_align.stderr

This file was deleted.

2 changes: 0 additions & 2 deletions src/test/ui/print_type_sizes/repr-align.rs
Expand Up @@ -18,8 +18,6 @@
// It avoids using u64/i64 because on some targets that is only 4-byte
// aligned (while on most it is 8-byte aligned) and so the resulting
// padding and overall computed sizes can be quite different.
#![feature(attr_literals)]
#![feature(repr_align)]
#![feature(start)]
#![allow(dead_code)]

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/span/gated-features-attr-spans.rs
Expand Up @@ -10,7 +10,7 @@

#![feature(attr_literals)]

#[repr(align(16))] //~ ERROR is experimental
#[repr(align(16))]
struct Gem {
mohs_hardness: u8,
poofed: bool,
Expand Down
10 changes: 1 addition & 9 deletions src/test/ui/span/gated-features-attr-spans.stderr
@@ -1,11 +1,3 @@
error[E0658]: the struct `#[repr(align(u16))]` attribute is experimental (see issue #33626)
--> $DIR/gated-features-attr-spans.rs:13:1
|
13 | #[repr(align(16))] //~ ERROR is experimental
| ^^^^^^^^^^^^^^^^^^
|
= help: add #![feature(repr_align)] to the crate attributes to enable

error[E0658]: SIMD types are experimental and possibly buggy (see issue #27731)
--> $DIR/gated-features-attr-spans.rs:20:1
|
Expand All @@ -30,5 +22,5 @@ warning: `#[must_use]` on functions is experimental (see issue #43302)
|
= help: add #![feature(fn_must_use)] to the crate attributes to enable

error: aborting due to 2 previous errors
error: aborting due to previous error

0 comments on commit a0a9007

Please sign in to comment.