1 use rustc_middle::ty::{self, layout::TyAndLayout};
2 use rustc_target::abi::Size;
4 // FIXME(eddyb) find a place for this (or a way to replace it).
7 /// Returns true if we want to generate a DW_TAG_enumeration_type description for
8 /// this instead of a DW_TAG_struct_type with DW_TAG_variant_part.
10 /// NOTE: This is somewhat inconsistent right now: For empty enums and enums with a single
11 /// fieldless variant, we generate DW_TAG_struct_type, although a
12 /// DW_TAG_enumeration_type would be a better fit.
13 pub fn wants_c_like_enum_debuginfo<'tcx>(enum_type_and_layout: TyAndLayout<'tcx>) -> bool {
14 match enum_type_and_layout.ty.kind() {
15 ty::Adt(adt_def, _) => {
16 if !adt_def.is_enum() {
20 match adt_def.variants().len() {
23 // Univariant enums unless they are zero-sized
24 enum_type_and_layout.size != Size::ZERO && adt_def.all_fields().count() == 0
27 // Enums with more than one variant if they have no fields
28 adt_def.all_fields().count() == 0