make transparent enums more ordinary
This commit is contained in:
parent
a605441e04
commit
5d73af2d4c
@ -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));
|
||||
|
Loading…
Reference in New Issue
Block a user