Show the variant name for univariant enums
Previously, only the fields would be displayed with no indication of the variant name. If you already knew the enum was univariant, this was ok but if the enum was univariant because of layout, for example, a `Result<T, !>` then it could be very confusing which variant was the active one.
This commit is contained in:
parent
f24355896b
commit
d94f087848
4 changed files with 36 additions and 3 deletions
|
@ -1517,7 +1517,7 @@ impl EnumMemberDescriptionFactory<'ll, 'tcx> {
|
|||
Some(&self.common_members),
|
||||
);
|
||||
vec![MemberDescription {
|
||||
name: if fallback { String::new() } else { variant_info.variant_name() },
|
||||
name: variant_info.variant_name(),
|
||||
type_metadata: variant_type_metadata,
|
||||
offset: Size::ZERO,
|
||||
size: self.layout.size,
|
||||
|
|
|
@ -397,6 +397,17 @@ pub fn push_debuginfo_type_name<'tcx>(
|
|||
output.push_str("enum$<");
|
||||
push_item_name(tcx, def.did, true, output);
|
||||
push_generic_params_internal(tcx, substs, output, visited);
|
||||
|
||||
if let Variants::Single { index: variant_idx } = &layout.variants {
|
||||
// Uninhabited enums can't be constructed and should never need to be visualized so
|
||||
// skip this step for them.
|
||||
if def.variants.len() != 0 {
|
||||
let variant = def.variants[*variant_idx].ident.as_str();
|
||||
|
||||
output.push_str(&format!(", {}", variant));
|
||||
}
|
||||
}
|
||||
|
||||
push_close_angle_bracket(tcx, output);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -149,6 +149,8 @@
|
|||
<Synthetic Name="[...]"><DisplayString>...</DisplayString></Synthetic>
|
||||
</Expand>
|
||||
</Type>
|
||||
|
||||
<!-- Directly tagged enums. $T1 is the type name -->
|
||||
<Type Name="enum$<*>">
|
||||
<Intrinsic Name="tag" Expression="discriminant" />
|
||||
<DisplayString Condition="tag() == 0">{tag(),en}</DisplayString>
|
||||
|
@ -191,8 +193,20 @@
|
|||
</Expand>
|
||||
</Type>
|
||||
|
||||
<!-- $T1 is the name of the enum, $T2 is the low value of the dataful variant tag,
|
||||
$T3 is the high value of the dataful variant tag, $T4 is the name of the dataful variant -->
|
||||
<!-- Single variant enums. $T1 is the name of the enum, $T2 is the name of the variant -->
|
||||
<Type Name="enum$<*, *>">
|
||||
<DisplayString>{"$T2",sb}</DisplayString>
|
||||
<Expand>
|
||||
<Synthetic Name="[variant]">
|
||||
<DisplayString>{"$T2",sb}</DisplayString>
|
||||
</Synthetic>
|
||||
<ExpandedItem>$T2</ExpandedItem>
|
||||
</Expand>
|
||||
</Type>
|
||||
|
||||
<!-- Niche-layout enums. $T1 is the name of the enum, $T2 is the low value of the dataful
|
||||
variant tag, $T3 is the high value of the dataful variant tag, $T4 is the name of
|
||||
the dataful variant -->
|
||||
<Type Name="enum$<*, *, *, *>">
|
||||
<Intrinsic Name="tag" Expression="discriminant" />
|
||||
<Intrinsic Name="is_dataful" Expression="tag() >= $T2 && tag() <= $T3" />
|
||||
|
|
|
@ -82,6 +82,11 @@
|
|||
// cdb-check: [+0x000] __0 [Type: alloc::string::String]
|
||||
// cdb-check: [+0x000] discriminant : 0x[...] [Type: enum$<core::option::Option<alloc::string::String>, 1, [...], Some>::Discriminant$]
|
||||
|
||||
// cdb-command: dx -r2 l,!
|
||||
// cdb-check:l,! : $T2 [Type: enum$<core::result::Result<u32, enum$<msvc_pretty_enums::Empty> >, Ok>]
|
||||
// cdb-check: [+0x000] Ok [Type: enum$<core::result::Result<u32, enum$<msvc_pretty_enums::Empty> >, Ok>::Ok]
|
||||
// cdb-check: [+0x000] __0 : 0x2a [Type: unsigned int]
|
||||
|
||||
pub enum CStyleEnum {
|
||||
Low = 2,
|
||||
High = 16,
|
||||
|
@ -93,6 +98,8 @@ pub enum NicheLayoutEnum {
|
|||
Tag2,
|
||||
}
|
||||
|
||||
pub enum Empty { }
|
||||
|
||||
fn main() {
|
||||
let a = Some(CStyleEnum::Low);
|
||||
let b = Option::<CStyleEnum>::None;
|
||||
|
@ -105,6 +112,7 @@ fn main() {
|
|||
let i = Option::<u32>::None;
|
||||
let j = CStyleEnum::High;
|
||||
let k = Some("IAMA optional string!".to_string());
|
||||
let l = Result::<u32, Empty>::Ok(42);
|
||||
|
||||
zzz(); // #break
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue