diff options
| author | Wesley Wiser <wesleywiser@microsoft.com> | 2021-06-25 13:33:00 -0400 |
|---|---|---|
| committer | Wesley Wiser <wesleywiser@microsoft.com> | 2021-07-02 20:16:37 -0400 |
| commit | d94f087848ee05036769bd4dc78337ab3604a776 (patch) | |
| tree | edaa85b82e408ccead0f5c21696d18f388f85d48 | |
| parent | f24355896ba0986e4d27eff45084f704ec7e7948 (diff) | |
| download | rust-d94f087848ee05036769bd4dc78337ab3604a776.tar.gz rust-d94f087848ee05036769bd4dc78337ab3604a776.zip | |
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.
| -rw-r--r-- | compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs | 11 | ||||
| -rw-r--r-- | src/etc/natvis/intrinsic.natvis | 18 | ||||
| -rw-r--r-- | src/test/debuginfo/msvc-pretty-enums.rs | 8 |
4 files changed, 36 insertions, 3 deletions
diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs index 11fca11350d..78709a1abe7 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs @@ -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, diff --git a/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs b/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs index a97c6a6b442..e3348c6bf08 100644 --- a/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs +++ b/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs @@ -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); } } diff --git a/src/etc/natvis/intrinsic.natvis b/src/etc/natvis/intrinsic.natvis index a2bc8d13b49..52e5d37c83f 100644 --- a/src/etc/natvis/intrinsic.natvis +++ b/src/etc/natvis/intrinsic.natvis @@ -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" /> diff --git a/src/test/debuginfo/msvc-pretty-enums.rs b/src/test/debuginfo/msvc-pretty-enums.rs index 67a67863f34..00e910669b9 100644 --- a/src/test/debuginfo/msvc-pretty-enums.rs +++ b/src/test/debuginfo/msvc-pretty-enums.rs @@ -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 } |
