diff options
| author | bors <bors@rust-lang.org> | 2021-07-06 19:31:24 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-07-06 19:31:24 +0000 |
| commit | 885399992c4c1dde37b506b8507a7d69415646b9 (patch) | |
| tree | 5deed964fe74eee58a066e286008dbdb1bed8743 /compiler/rustc_codegen_ssa/src | |
| parent | 238fd72880776c5dbd3b067acb096562e6af5399 (diff) | |
| parent | 457165e1ed283a1c86db55ab926bc2166c4a8ee9 (diff) | |
| download | rust-885399992c4c1dde37b506b8507a7d69415646b9.tar.gz rust-885399992c4c1dde37b506b8507a7d69415646b9.zip | |
Auto merge of #86636 - wesleywiser:misc_enum_improvements, r=michaelwoerister
[msvc] Consistently show active variant and fix visualization for single variant enums Prior to this change, there were a few cases where inspecting an enum in either WinDbg or Visual Studio would not show the active variant name. After these changes, we now consistently show the active variant name as `[variant]` in the debugger. We also didn't handle single variant enums very well. That is now also resolved. Before:  After:  r? `@michaelwoerister`
Diffstat (limited to 'compiler/rustc_codegen_ssa/src')
| -rw-r--r-- | compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs b/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs index a97c6a6b442..b3c14d9072c 100644 --- a/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs +++ b/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs @@ -367,6 +367,10 @@ pub fn push_debuginfo_type_name<'tcx>( ) { let layout = tcx.layout_of(tcx.param_env(def.did).and(ty)).expect("layout error"); + output.push_str("enum$<"); + push_item_name(tcx, def.did, true, output); + push_generic_params_internal(tcx, substs, output, visited); + if let Variants::Multiple { tag_encoding: TagEncoding::Niche { dataful_variant, .. }, tag, @@ -386,19 +390,19 @@ pub fn push_debuginfo_type_name<'tcx>( let max = dataful_discriminant_range.end(); let max = tag.value.size(&tcx).truncate(*max); - output.push_str("enum$<"); - push_item_name(tcx, def.did, true, output); - push_generic_params_internal(tcx, substs, output, visited); - let dataful_variant_name = def.variants[*dataful_variant].ident.as_str(); - output.push_str(&format!(", {}, {}, {}>", min, max, dataful_variant_name)); - } else { - output.push_str("enum$<"); - push_item_name(tcx, def.did, true, output); - push_generic_params_internal(tcx, substs, output, visited); - push_close_angle_bracket(tcx, output); + output.push_str(&format!(", {}, {}, {}", min, max, dataful_variant_name)); + } else 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); } } |
