Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-def/src/body/pretty.rs')
-rw-r--r--crates/hir-def/src/body/pretty.rs46
1 files changed, 20 insertions, 26 deletions
diff --git a/crates/hir-def/src/body/pretty.rs b/crates/hir-def/src/body/pretty.rs
index 02b19ade44..0f2b279670 100644
--- a/crates/hir-def/src/body/pretty.rs
+++ b/crates/hir-def/src/body/pretty.rs
@@ -3,7 +3,6 @@
use std::fmt::{self, Write};
use itertools::Itertools;
-use syntax::ast::HasName;
use crate::{
hir::{
@@ -19,35 +18,30 @@ use super::*;
pub(super) fn print_body_hir(db: &dyn DefDatabase, body: &Body, owner: DefWithBodyId) -> String {
let header = match owner {
DefWithBodyId::FunctionId(it) => {
- let item_tree_id = it.lookup(db).id;
- format!(
- "fn {}",
- item_tree_id.item_tree(db)[item_tree_id.value].name.display(db.upcast())
- )
+ it.lookup(db).id.resolved(db, |it| format!("fn {}", it.name.display(db.upcast())))
}
- DefWithBodyId::StaticId(it) => {
- let item_tree_id = it.lookup(db).id;
+ DefWithBodyId::StaticId(it) => it
+ .lookup(db)
+ .id
+ .resolved(db, |it| format!("static {} = ", it.name.display(db.upcast()))),
+ DefWithBodyId::ConstId(it) => it.lookup(db).id.resolved(db, |it| {
format!(
- "static {} = ",
- item_tree_id.item_tree(db)[item_tree_id.value].name.display(db.upcast())
+ "const {} = ",
+ match &it.name {
+ Some(name) => name.display(db.upcast()).to_string(),
+ None => "_".to_string(),
+ }
)
- }
- DefWithBodyId::ConstId(it) => {
- let item_tree_id = it.lookup(db).id;
- let name = match &item_tree_id.item_tree(db)[item_tree_id.value].name {
- Some(name) => name.display(db.upcast()).to_string(),
- None => "_".to_string(),
- };
- format!("const {name} = ")
- }
+ }),
DefWithBodyId::InTypeConstId(_) => format!("In type const = "),
DefWithBodyId::VariantId(it) => {
- let src = it.parent.child_source(db);
- let variant = &src.value[it.local_id];
- match &variant.name() {
- Some(name) => name.to_string(),
- None => "_".to_string(),
- }
+ let loc = it.lookup(db);
+ let enum_loc = loc.parent.lookup(db);
+ format!(
+ "enum {}::{}",
+ enum_loc.id.item_tree(db)[enum_loc.id.value].name.display(db.upcast()),
+ loc.id.item_tree(db)[loc.id.value].name.display(db.upcast()),
+ )
}
};
@@ -384,7 +378,7 @@ impl Printer<'_> {
}
Expr::Closure { args, arg_types, ret_type, body, closure_kind, capture_by } => {
match closure_kind {
- ClosureKind::Generator(Movability::Static) => {
+ ClosureKind::Coroutine(Movability::Static) => {
w!(self, "static ");
}
ClosureKind::Async => {