summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorRobin Kruppe <robin.kruppe@gmail.com>2018-01-03 17:43:30 +0100
committerRobin Kruppe <robin.kruppe@gmail.com>2018-01-16 08:58:32 +0100
commit2be697bc215f19b4bf17df6b9b56626ab7b1d994 (patch)
tree5eaf535d1e91da488908f4ac4a8ab6763e8535fe /src/libsyntax
parent79a521bb9a8ace1a6663578a4c409906adde620d (diff)
downloadrust-2be697bc215f19b4bf17df6b9b56626ab7b1d994.tar.gz
rust-2be697bc215f19b4bf17df6b9b56626ab7b1d994.zip
Implement repr(transparent)
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/attr.rs5
-rw-r--r--src/libsyntax/feature_gate.rs8
2 files changed, 12 insertions, 1 deletions
diff --git a/src/libsyntax/attr.rs b/src/libsyntax/attr.rs
index 4291f811f3f..d18d6f5e6bd 100644
--- a/src/libsyntax/attr.rs
+++ b/src/libsyntax/attr.rs
@@ -992,7 +992,8 @@ pub fn find_deprecation(diagnostic: &Handler, attrs: &[Attribute],
 /// Valid repr contents: any of the primitive integral type names (see
 /// `int_type_of_word`, below) to specify enum discriminant type; `C`, to use
 /// the same discriminant size that the corresponding C enum would or C
-/// structure layout, and `packed` to remove padding.
+/// structure layout, `packed` to remove padding, and `transparent` to elegate representation
+/// concerns to the only non-ZST field.
 pub fn find_repr_attrs(diagnostic: &Handler, attr: &Attribute) -> Vec<ReprAttr> {
     let mut acc = Vec::new();
     if attr.path == "repr" {
@@ -1011,6 +1012,7 @@ pub fn find_repr_attrs(diagnostic: &Handler, attr: &Attribute) -> Vec<ReprAttr>
                         "C" => Some(ReprC),
                         "packed" => Some(ReprPacked),
                         "simd" => Some(ReprSimd),
+                        "transparent" => Some(ReprTransparent),
                         _ => match int_type_of_word(word) {
                             Some(ity) => Some(ReprInt(ity)),
                             None => {
@@ -1082,6 +1084,7 @@ pub enum ReprAttr {
     ReprC,
     ReprPacked,
     ReprSimd,
+    ReprTransparent,
     ReprAlign(u32),
 }
 
diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs
index 196fadcc997..953b2deb877 100644
--- a/src/libsyntax/feature_gate.rs
+++ b/src/libsyntax/feature_gate.rs
@@ -452,6 +452,9 @@ declare_features! (
 
     // `extern` in paths
     (active, extern_in_paths, "1.23.0", Some(44660)),
+
+    // Allows `#[repr(transparent)]` attribute on newtype structs
+    (active, repr_transparent, "1.25.0", Some(43036)),
 );
 
 declare_features! (
@@ -1524,6 +1527,11 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
                                                "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 \
+                                               is experimental");
+                        }
                     }
                 }
             }