]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_codegen_ssa/src/debuginfo/mod.rs
Rollup merge of #106323 - starkat99:stabilize-f16c_target_feature, r=petrochenkov
[rust.git] / compiler / rustc_codegen_ssa / src / debuginfo / mod.rs
1 use rustc_middle::ty::{self, layout::TyAndLayout};
2 use rustc_target::abi::Size;
3
4 // FIXME(eddyb) find a place for this (or a way to replace it).
5 pub mod type_names;
6
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.
9 ///
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(enum_type_and_layout: TyAndLayout<'_>) -> bool {
14     match enum_type_and_layout.ty.kind() {
15         ty::Adt(adt_def, _) => {
16             if !adt_def.is_enum() {
17                 return false;
18             }
19
20             match adt_def.variants().len() {
21                 0 => false,
22                 1 => {
23                     // Univariant enums unless they are zero-sized
24                     enum_type_and_layout.size != Size::ZERO && adt_def.all_fields().count() == 0
25                 }
26                 _ => {
27                     // Enums with more than one variant if they have no fields
28                     adt_def.all_fields().count() == 0
29                 }
30             }
31         }
32         _ => false,
33     }
34 }