Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stabilized #[repr(align(x))] attribute (RFC 1358) #47006

Merged
merged 1 commit into from
Jan 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/liballoc/tests/lib.rs
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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