From 5d73af2d4c036e97b3fb430d53853ff5c4cd975c Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Sun, 15 Dec 2019 15:11:34 +0100 Subject: [PATCH] make transparent enums more ordinary --- src/librustc_typeck/check/mod.rs | 35 ++++++++++++++++---------------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 43e7bbcf0c0..7e9caa70d35 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -2330,7 +2330,7 @@ fn bad_variant_count<'tcx>(tcx: TyCtxt<'tcx>, adt: &'tcx ty::AdtDef, sp: Span, d ); let mut err = struct_span_err!(tcx.sess, sp, E0731, "transparent enum {}", msg); err.span_label(sp, &msg); - if let &[ref start @ .., ref end] = &variant_spans[..] { + if let [start @ .., end] = &*variant_spans { for variant_span in start { err.span_label(*variant_span, ""); } @@ -2372,23 +2372,14 @@ fn check_transparent(tcx: TyCtxt<'_>, sp: Span, def_id: DefId) { } let sp = tcx.sess.source_map().def_span(sp); - if adt.is_enum() { - if !tcx.features().transparent_enums { - feature_err( - &tcx.sess.parse_sess, - sym::transparent_enums, - sp, - "transparent enums are unstable", - ) - .emit(); - } - if adt.variants.len() != 1 { - bad_variant_count(tcx, adt, sp, def_id); - if adt.variants.is_empty() { - // Don't bother checking the fields. No variants (and thus no fields) exist. - return; - } - } + if adt.is_enum() && !tcx.features().transparent_enums { + feature_err( + &tcx.sess.parse_sess, + sym::transparent_enums, + sp, + "transparent enums are unstable", + ) + .emit(); } if adt.is_union() && !tcx.features().transparent_unions { @@ -2401,6 +2392,14 @@ fn check_transparent(tcx: TyCtxt<'_>, sp: Span, def_id: DefId) { .emit(); } + if adt.variants.len() != 1 { + bad_variant_count(tcx, adt, sp, def_id); + if adt.variants.is_empty() { + // Don't bother checking the fields. No variants (and thus no fields) exist. + return; + } + } + // For each field, figure out if it's known to be a ZST and align(1) let field_infos = adt.all_fields().map(|field| { let ty = field.ty(tcx, InternalSubsts::identity_for_item(tcx, field.did));