From 2be697bc215f19b4bf17df6b9b56626ab7b1d994 Mon Sep 17 00:00:00 2001 From: Robin Kruppe Date: Wed, 3 Jan 2018 17:43:30 +0100 Subject: Implement repr(transparent) --- src/libsyntax/attr.rs | 5 ++++- src/libsyntax/feature_gate.rs | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) (limited to 'src/libsyntax') 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 { let mut acc = Vec::new(); if attr.path == "repr" { @@ -1011,6 +1012,7 @@ pub fn find_repr_attrs(diagnostic: &Handler, attr: &Attribute) -> Vec "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"); + } } } } -- cgit 1.4.1-3-g733a5