Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-ty/src/mir/pretty.rs')
| -rw-r--r-- | crates/hir-ty/src/mir/pretty.rs | 57 |
1 files changed, 24 insertions, 33 deletions
diff --git a/crates/hir-ty/src/mir/pretty.rs b/crates/hir-ty/src/mir/pretty.rs index 7d7d4106cb..f71e297897 100644 --- a/crates/hir-ty/src/mir/pretty.rs +++ b/crates/hir-ty/src/mir/pretty.rs @@ -7,14 +7,14 @@ use std::{ use either::Either; use hir_def::{expr_store::Body, hir::BindingId}; -use hir_expand::{name::Name, Lookup}; +use hir_expand::{Lookup, name::Name}; use la_arena::ArenaMap; use crate::{ + ClosureId, db::HirDatabase, display::{ClosureStyle, DisplayTarget, HirDisplay}, mir::{PlaceElem, ProjectionElem, StatementKind, TerminatorKind}, - ClosureId, }; use super::{ @@ -43,45 +43,38 @@ impl MirBody { let mut ctx = MirPrettyCtx::new(self, &hir_body, db, display_target); ctx.for_body(|this| match ctx.body.owner { hir_def::DefWithBodyId::FunctionId(id) => { - let data = db.function_data(id); - w!(this, "fn {}() ", data.name.display(db.upcast(), this.display_target.edition)); + let data = db.function_signature(id); + w!(this, "fn {}() ", data.name.display(db, this.display_target.edition)); } hir_def::DefWithBodyId::StaticId(id) => { - let data = db.static_data(id); - w!( - this, - "static {}: _ = ", - data.name.display(db.upcast(), this.display_target.edition) - ); + let data = db.static_signature(id); + w!(this, "static {}: _ = ", data.name.display(db, this.display_target.edition)); } hir_def::DefWithBodyId::ConstId(id) => { - let data = db.const_data(id); + let data = db.const_signature(id); w!( this, "const {}: _ = ", data.name .as_ref() .unwrap_or(&Name::missing()) - .display(db.upcast(), this.display_target.edition) + .display(db, this.display_target.edition) ); } hir_def::DefWithBodyId::VariantId(id) => { - let loc = id.lookup(db.upcast()); - let enum_loc = loc.parent.lookup(db.upcast()); + let loc = id.lookup(db); + let enum_loc = loc.parent.lookup(db); w!( this, "enum {}::{} = ", - enum_loc.id.item_tree(db.upcast())[enum_loc.id.value] + enum_loc.id.item_tree(db)[enum_loc.id.value] .name - .display(db.upcast(), this.display_target.edition), - loc.id.item_tree(db.upcast())[loc.id.value] + .display(db, this.display_target.edition), + loc.id.item_tree(db)[loc.id.value] .name - .display(db.upcast(), this.display_target.edition), + .display(db, this.display_target.edition), ) } - hir_def::DefWithBodyId::InTypeConstId(id) => { - w!(this, "in type const {id:?} = "); - } }); ctx.result } @@ -134,7 +127,7 @@ impl HirDisplay for LocalName { match self { LocalName::Unknown(l) => write!(f, "_{}", u32::from(l.into_raw())), LocalName::Binding(n, l) => { - write!(f, "{}_{}", n.display(f.db.upcast(), f.edition()), u32::from(l.into_raw())) + write!(f, "{}_{}", n.display(f.db, f.edition()), u32::from(l.into_raw())) } } } @@ -154,7 +147,7 @@ impl<'a> MirPrettyCtx<'a> { } fn for_closure(&mut self, closure: ClosureId) { - let body = match self.db.mir_body_for_closure(closure) { + let body = match self.db.mir_body_for_closure(closure.into()) { Ok(it) => it, Err(e) => { wln!(self, "// error in {closure:?}: {e:?}"); @@ -333,27 +326,25 @@ impl<'a> MirPrettyCtx<'a> { w!(this, ")"); } ProjectionElem::Field(Either::Left(field)) => { - let variant_data = field.parent.variant_data(this.db.upcast()); - let name = &variant_data.fields()[field.local_id].name; + let variant_fields = this.db.variant_fields(field.parent); + let name = &variant_fields.fields()[field.local_id].name; match field.parent { hir_def::VariantId::EnumVariantId(e) => { w!(this, "("); f(this, local, head); - let variant_name = &this.db.enum_variant_data(e).name; + let loc = e.lookup(this.db); w!( this, " as {}).{}", - variant_name.display(this.db.upcast(), this.display_target.edition), - name.display(this.db.upcast(), this.display_target.edition) + this.db.enum_variants(loc.parent).variants[loc.index as usize] + .1 + .display(this.db, this.display_target.edition), + name.display(this.db, this.display_target.edition) ); } hir_def::VariantId::StructId(_) | hir_def::VariantId::UnionId(_) => { f(this, local, head); - w!( - this, - ".{}", - name.display(this.db.upcast(), this.display_target.edition) - ); + w!(this, ".{}", name.display(this.db, this.display_target.edition)); } } } |