From 651ea8ea44d8ac8a02dc357412eb73f830057cae Mon Sep 17 00:00:00 2001 From: Cameron Hart Date: Tue, 26 Dec 2017 10:24:23 +1100 Subject: [PATCH] Stabilized `#[repr(align(x))]` attribute (RFC 1358) --- src/liballoc/tests/lib.rs | 1 - src/libstd/lib.rs | 2 +- src/libsyntax/feature_gate.rs | 30 +++++++++++-------- src/test/codegen/align-struct.rs | 3 -- .../compile-fail/conflicting-repr-hints.rs | 2 -- src/test/compile-fail/repr-align.rs | 2 -- .../repr-packed-contains-align.rs | 2 -- src/test/run-pass/align-struct.rs | 2 -- src/test/run-pass/union/union-align.rs | 2 -- src/test/ui/feature-gate-repr_align.rs | 15 ---------- src/test/ui/feature-gate-repr_align.stderr | 10 ------- src/test/ui/print_type_sizes/repr-align.rs | 2 -- src/test/ui/span/gated-features-attr-spans.rs | 2 +- .../ui/span/gated-features-attr-spans.stderr | 10 +------ 14 files changed, 20 insertions(+), 65 deletions(-) delete mode 100644 src/test/ui/feature-gate-repr_align.rs delete mode 100644 src/test/ui/feature-gate-repr_align.stderr diff --git a/src/liballoc/tests/lib.rs b/src/liballoc/tests/lib.rs index eee229bc6fdfa..427a7adcbded1 100644 --- a/src/liballoc/tests/lib.rs +++ b/src/liballoc/tests/lib.rs @@ -23,7 +23,6 @@ #![feature(pattern)] #![feature(placement_in_syntax)] #![feature(rand)] -#![feature(repr_align)] #![feature(slice_rotate)] #![feature(splice)] #![feature(str_escape)] diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index 91cc6d25cce01..a8049e676b3bb 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -296,7 +296,6 @@ #![feature(ptr_internals)] #![feature(rand)] #![feature(raw)] -#![feature(repr_align)] #![feature(rustc_attrs)] #![feature(sip_hash_13)] #![feature(slice_bytes)] @@ -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] diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index ac5a10ec70364..5a7b53153fd61 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -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)), @@ -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 @@ -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"); + } } } @@ -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 \ diff --git a/src/test/codegen/align-struct.rs b/src/test/codegen/align-struct.rs index ab9f5dda3a1b7..155319cb1541f 100644 --- a/src/test/codegen/align-struct.rs +++ b/src/test/codegen/align-struct.rs @@ -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] } diff --git a/src/test/compile-fail/conflicting-repr-hints.rs b/src/test/compile-fail/conflicting-repr-hints.rs index 12ac8fb57b1f8..8acc8b7bb1e5c 100644 --- a/src/test/compile-fail/conflicting-repr-hints.rs +++ b/src/test/compile-fail/conflicting-repr-hints.rs @@ -9,8 +9,6 @@ // except according to those terms. #![allow(dead_code)] -#![feature(attr_literals)] -#![feature(repr_align)] #[repr(C)] enum A { A } diff --git a/src/test/compile-fail/repr-align.rs b/src/test/compile-fail/repr-align.rs index bc9cf065e5a0a..7c8eb6a2de93a 100644 --- a/src/test/compile-fail/repr-align.rs +++ b/src/test/compile-fail/repr-align.rs @@ -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); diff --git a/src/test/compile-fail/repr-packed-contains-align.rs b/src/test/compile-fail/repr-packed-contains-align.rs index 78d43064ea3d2..27890333a5165 100644 --- a/src/test/compile-fail/repr-packed-contains-align.rs +++ b/src/test/compile-fail/repr-packed-contains-align.rs @@ -7,8 +7,6 @@ // , 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)] diff --git a/src/test/run-pass/align-struct.rs b/src/test/run-pass/align-struct.rs index e42aa868c47ee..dea8462705f28 100644 --- a/src/test/run-pass/align-struct.rs +++ b/src/test/run-pass/align-struct.rs @@ -7,8 +7,6 @@ // , 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; diff --git a/src/test/run-pass/union/union-align.rs b/src/test/run-pass/union/union-align.rs index c0100df53e7c1..54e4e12d24fa5 100644 --- a/src/test/run-pass/union/union-align.rs +++ b/src/test/run-pass/union/union-align.rs @@ -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}; diff --git a/src/test/ui/feature-gate-repr_align.rs b/src/test/ui/feature-gate-repr_align.rs deleted file mode 100644 index 9591d367a2d19..0000000000000 --- a/src/test/ui/feature-gate-repr_align.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2017 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. -#![feature(attr_literals)] - -#[repr(align(64))] //~ error: the struct `#[repr(align(u16))]` attribute is experimental -struct Foo(u64, u64); - -fn main() {} diff --git a/src/test/ui/feature-gate-repr_align.stderr b/src/test/ui/feature-gate-repr_align.stderr deleted file mode 100644 index dd88067d58f9a..0000000000000 --- a/src/test/ui/feature-gate-repr_align.stderr +++ /dev/null @@ -1,10 +0,0 @@ -error[E0658]: the struct `#[repr(align(u16))]` attribute is experimental (see issue #33626) - --> $DIR/feature-gate-repr_align.rs:12:1 - | -12 | #[repr(align(64))] //~ error: the struct `#[repr(align(u16))]` attribute is experimental - | ^^^^^^^^^^^^^^^^^^ - | - = help: add #![feature(repr_align)] to the crate attributes to enable - -error: aborting due to previous error - diff --git a/src/test/ui/print_type_sizes/repr-align.rs b/src/test/ui/print_type_sizes/repr-align.rs index 108b8dbba0198..92928bba1c3ac 100644 --- a/src/test/ui/print_type_sizes/repr-align.rs +++ b/src/test/ui/print_type_sizes/repr-align.rs @@ -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)] diff --git a/src/test/ui/span/gated-features-attr-spans.rs b/src/test/ui/span/gated-features-attr-spans.rs index ace185d01694a..83a4c5d5dd2ff 100644 --- a/src/test/ui/span/gated-features-attr-spans.rs +++ b/src/test/ui/span/gated-features-attr-spans.rs @@ -10,7 +10,7 @@ #![feature(attr_literals)] -#[repr(align(16))] //~ ERROR is experimental +#[repr(align(16))] struct Gem { mohs_hardness: u8, poofed: bool, diff --git a/src/test/ui/span/gated-features-attr-spans.stderr b/src/test/ui/span/gated-features-attr-spans.stderr index 74a2c1d742b15..f15c4a72c5a6b 100644 --- a/src/test/ui/span/gated-features-attr-spans.stderr +++ b/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 | @@ -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