Auto merge of #60463 - mjbshaw:transparent, r=varkor,rkruppe

Implement RFC 2645 (transparent enums and unions)

Tracking issue: #60405
This commit is contained in:
bors 2019-06-11 11:06:38 +00:00
commit 8e948df707
34 changed files with 730 additions and 208 deletions

View file

@ -181,12 +181,9 @@ impl<'a, 'tcx> CheckAttrVisitor<'a, 'tcx> {
let (article, allowed_targets) = match hint.name_or_empty() {
name @ sym::C | name @ sym::align => {
is_c |= name == sym::C;
if target != Target::Struct &&
target != Target::Union &&
target != Target::Enum {
("a", "struct, enum or union")
} else {
continue
match target {
Target::Struct | Target::Union | Target::Enum => continue,
_ => ("a", "struct, enum, or union"),
}
}
sym::packed => {
@ -207,10 +204,9 @@ impl<'a, 'tcx> CheckAttrVisitor<'a, 'tcx> {
}
sym::transparent => {
is_transparent = true;
if target != Target::Struct {
("a", "struct")
} else {
continue
match target {
Target::Struct | Target::Union | Target::Enum => continue,
_ => ("a", "struct, enum, or union"),
}
}
sym::i8 | sym::u8 | sym::i16 | sym::u16 |
@ -241,7 +237,7 @@ impl<'a, 'tcx> CheckAttrVisitor<'a, 'tcx> {
if is_transparent && hints.len() > 1 {
let hint_spans: Vec<_> = hint_spans.clone().collect();
span_err!(self.tcx.sess, hint_spans, E0692,
"transparent struct cannot have other repr hints");
"transparent {} cannot have other repr hints", target);
}
// Warn on repr(u8, u16), repr(C, simd), and c-like-enum-repr(C, u8)
if (int_reprs > 1)
@ -277,7 +273,7 @@ impl<'a, 'tcx> CheckAttrVisitor<'a, 'tcx> {
attr.span,
stmt.span,
"attribute should not be applied to a statement",
"not a struct, enum or union",
"not a struct, enum, or union",
);
}
}
@ -298,7 +294,7 @@ impl<'a, 'tcx> CheckAttrVisitor<'a, 'tcx> {
attr.span,
expr.span,
"attribute should not be applied to an expression",
"not defining a struct, enum or union",
"not defining a struct, enum, or union",
);
}
}

View file

@ -2303,7 +2303,7 @@ impl<'a, 'gcx, 'tcx> AdtDef {
/// Returns an iterator over all fields contained
/// by this ADT.
#[inline]
pub fn all_fields<'s>(&'s self) -> impl Iterator<Item = &'s FieldDef> {
pub fn all_fields<'s>(&'s self) -> impl Iterator<Item = &'s FieldDef> + Clone {
self.variants.iter().flat_map(|v| v.fields.iter())
}