]> git.lizzy.rs Git - rust.git/commitdiff
Added feature gate, updated error messages and tests.
authorCameron Hart <cameron.hart@gmail.com>
Sat, 25 Mar 2017 08:00:49 +0000 (19:00 +1100)
committerCameron Hart <cameron.hart@gmail.com>
Thu, 20 Apr 2017 21:37:10 +0000 (07:37 +1000)
src/doc/unstable-book/src/SUMMARY.md
src/doc/unstable-book/src/language-features/repr-align.md [new file with mode: 0644]
src/libsyntax/attr.rs
src/libsyntax/diagnostic_list.rs
src/libsyntax/feature_gate.rs
src/test/compile-fail/conflicting-repr-hints.rs
src/test/compile-fail/feature-gate-repr_align.rs [new file with mode: 0644]
src/test/compile-fail/repr-align.rs
src/test/compile-fail/repr-packed-contains-align.rs
src/test/run-pass/align-struct.rs
src/test/ui/print_type_sizes/repr-align.rs

index 3e0415439774c52d306bda0402a1ef4d2cd5dfd1..ee4e568a5ca9af263cd3fc50537d3cd18b652a1b 100644 (file)
@@ -72,6 +72,7 @@
     - [proc_macro](language-features/proc-macro.md)
     - [quote](language-features/quote.md)
     - [relaxed_adts](language-features/relaxed-adts.md)
+    - [repr_align](language-features/repr-align.md)
     - [repr_simd](language-features/repr-simd.md)
     - [rustc_attrs](language-features/rustc-attrs.md)
     - [rustc_diagnostic_macros](language-features/rustc-diagnostic-macros.md)
diff --git a/src/doc/unstable-book/src/language-features/repr-align.md b/src/doc/unstable-book/src/language-features/repr-align.md
new file mode 100644 (file)
index 0000000..deea04f
--- /dev/null
@@ -0,0 +1,11 @@
+# `repr_align`
+
+The tracking issue for this feature is: [#33626]
+
+[#33626]: https://github.com/rust-lang/rust/issues/33626
+
+------------------------
+
+
+
+
index 442345ceb3c1872852cdf75cb52f0aee8a79d3e1..82492d976276e05d6ed6d758872c48acc17405ee 100644 (file)
@@ -972,19 +972,24 @@ pub fn find_repr_attrs(diagnostic: &Handler, attr: &Attribute) -> Vec<ReprAttr>
                 } else if let Some((name, value)) = item.name_value_literal() {
                     if name == "align" {
                         recognised = true;
-                        let mut valid_align = false;
+                        let mut align_error = None;
                         if let ast::LitKind::Int(align, ast::LitIntType::Unsuffixed) = value.node {
                             if align.is_power_of_two() {
                                 // rustc::ty::layout::Align restricts align to <= 32768
                                 if align <= 32768 {
                                     acc.push(ReprAlign(align as u16));
-                                    valid_align = true;
+                                } else {
+                                    align_error = Some("larger than 32768");
                                 }
+                            } else {
+                                align_error = Some("not a power of two");
                             }
+                        } else {
+                            align_error = Some("not an unsuffixed integer");
                         }
-                        if !valid_align {
+                        if let Some(align_error) = align_error {
                             span_err!(diagnostic, item.span, E0589,
-                                      "align representation must be a u16 power of two");
+                                      "invalid `repr(align)` attribute: {}", align_error);
                         }
                     }
                 }
index 775775875a4d1097277a0cb1a2b36c505d7cb2d8..01d1277ea6265014c018401a8854033db84931fa 100644 (file)
@@ -292,5 +292,5 @@ fn foo() {}
     E0556, // malformed feature, expected just one word
     E0557, // feature has been removed
     E0584, // file for module `..` found at both .. and ..
-    E0589, // align representation must be a u16 power of two
+    E0589, // invalid `repr(align)` attribute
 }
index 175447e11127058121478dd6a5b0208c0dbbad1a..9b55a860b3595a0e4edd1bfb5e837d22f71ee7fd 100644 (file)
@@ -338,6 +338,9 @@ pub fn new() -> 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)),
+
     // See rust-lang/rfcs#1414. Allows code like `let x: &'static u32 = &42` to work.
     (active, rvalue_static_promotion, "1.15.1", Some(38865)),
 
@@ -1189,6 +1192,11 @@ fn visit_item(&mut self, i: &'a ast::Item) {
                                                     and possibly buggy");
 
                             }
+                            if item.check_name("align") {
+                                gate_feature_post!(&self, repr_align, i.span,
+                                                   "the struct `#[repr(align(u16))]` attribute \
+                                                    is experimental");
+                            }
                         }
                     }
                 }
index af38673d3650e72f1f95ce081509abb2f6d09a94..01fa3ffbaa6ae7a82a9f9644ccba0209b4ee4f77 100644 (file)
@@ -10,6 +10,7 @@
 
 #![allow(dead_code)]
 #![feature(attr_literals)]
+#![feature(repr_align)]
 
 #[repr(C)]
 enum A { A }
diff --git a/src/test/compile-fail/feature-gate-repr_align.rs b/src/test/compile-fail/feature-gate-repr_align.rs
new file mode 100644 (file)
index 0000000..8e986e1
--- /dev/null
@@ -0,0 +1,15 @@
+// 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <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)]
+
+#[repr(align(64))]
+struct Foo(u64, u64); //~ error: the struct `#[repr(align(u16))]` attribute is experimental
+
+fn main() {}
index 96dfe1c05f9a7937bcae41707784894ca807c8f7..eb0b27fe9c07ed5307a658e87da2fda19cc630bb 100644 (file)
@@ -9,14 +9,15 @@
 // except according to those terms.
 #![allow(dead_code)]
 #![feature(attr_literals)]
+#![feature(repr_align)]
 
-#[repr(align(16.0))] //~ ERROR: align representation must be a u16 power of two
+#[repr(align(16.0))] //~ ERROR: invalid `repr(align)` attribute: not an unsuffixed integer
 struct A(i32);
 
-#[repr(align(15))] //~ ERROR: align representation must be a u16 power of two
+#[repr(align(15))] //~ ERROR: invalid `repr(align)` attribute: not a power of two
 struct B(i32);
 
-#[repr(align(65536))] //~ ERROR: align representation must be a u16 power of tw
+#[repr(align(65536))] //~ ERROR: invalid `repr(align)` attribute: larger than 32768
 struct C(i32);
 
 fn main() {}
index 11829dfae8cbe3cfd218df252fe7764959cca0c3..c584dcf3e5993eacd8eeeb083f53d5a88d2386c4 100644 (file)
@@ -8,6 +8,7 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 #![feature(attr_literals)]
+#![feature(repr_align)]
 #![allow(dead_code)]
 
 #[repr(align(16))]
index 4793189d366dfb59d4a6167c386cd0be5ff15574..0b9a3594502b00bc0dcbaa04f9672a6a0e6ecffb 100644 (file)
@@ -8,6 +8,7 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 #![feature(attr_literals)]
+#![feature(repr_align)]
 
 use std::mem;
 
index ea2910f86c458a75837146c630dfba01bb1fb715..e9b43145de469706b199292371e4fa0be7542ede 100644 (file)
@@ -18,6 +18,7 @@
 // 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)]
 #![allow(dead_code)]
 
 #[repr(align(16))]