Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-def/src/expr_store/pretty.rs')
| -rw-r--r-- | crates/hir-def/src/expr_store/pretty.rs | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/crates/hir-def/src/expr_store/pretty.rs b/crates/hir-def/src/expr_store/pretty.rs index 6a0b1e5197..6ba0bbd61c 100644 --- a/crates/hir-def/src/expr_store/pretty.rs +++ b/crates/hir-def/src/expr_store/pretty.rs @@ -11,6 +11,7 @@ use crate::{ Statement, }, pretty::{print_generic_args, print_path, print_type_ref}, + VariantId, }; use super::*; @@ -56,6 +57,32 @@ pub(super) fn print_body_hir( loc.id.item_tree(db)[loc.id.value].name.display(db.upcast(), edition), ) } + DefWithBodyId::FieldId(it) => { + let parent_name: String = match it.parent { + VariantId::EnumVariantId(it) => { + let loc = it.lookup(db); + let enum_loc = loc.parent.lookup(db); + format!( + "{}::{}", + enum_loc.id.item_tree(db)[enum_loc.id.value] + .name + .display(db.upcast(), edition), + loc.id.item_tree(db)[loc.id.value].name.display(db.upcast(), edition), + ) + } + VariantId::StructId(it) => it + .lookup(db) + .id + .resolved(db, |it| it.name.display(db.upcast(), edition).to_string()), + VariantId::UnionId(it) => it + .lookup(db) + .id + .resolved(db, |it| it.name.display(db.upcast(), edition).to_string()), + }; + let variant_data = it.parent.variant_data(db); + let field_name = &variant_data.fields()[it.local_id].name; + format!("field {}.{}", parent_name, field_name.display(db.upcast(), edition),) + } }; let mut p = Printer { |