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 | 43 |
1 files changed, 38 insertions, 5 deletions
diff --git a/crates/hir-def/src/expr_store/pretty.rs b/crates/hir-def/src/expr_store/pretty.rs index 6a0b1e5197..1b3a1bb4dc 100644 --- a/crates/hir-def/src/expr_store/pretty.rs +++ b/crates/hir-def/src/expr_store/pretty.rs @@ -8,9 +8,10 @@ use span::Edition; use crate::{ hir::{ Array, BindingAnnotation, CaptureBy, ClosureKind, Literal, LiteralOrConst, Movability, - Statement, + Spread, 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 { @@ -385,10 +412,16 @@ impl Printer<'_> { p.print_expr(field.expr); wln!(p, ","); } - if let Some(spread) = spread { - w!(p, ".."); - p.print_expr(*spread); - wln!(p); + match spread { + Spread::No => {} + Spread::Yes => { + w!(p, ".."); + } + Spread::Base(expr) => { + w!(p, ".."); + p.print_expr(*expr); + wln!(p); + } } }); w!(self, "}}"); |