Skip to content

Commit 8ef7bc2

Browse files
committed
Make DefMap dumps nicer to read
1 parent ebf7fd1 commit 8ef7bc2

File tree

8 files changed

+664
-664
lines changed

8 files changed

+664
-664
lines changed

src/tools/rust-analyzer/crates/hir-def/src/expr_store/tests/body/block.rs

Lines changed: 118 additions & 118 deletions
Large diffs are not rendered by default.

src/tools/rust-analyzer/crates/hir-def/src/item_scope.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Describes items defined or visible (ie, imported) in a certain scope.
22
//! This is shared between modules and blocks.
33
4-
use std::sync::LazyLock;
4+
use std::{fmt, sync::LazyLock};
55

66
use base_db::Crate;
77
use hir_expand::{AstId, MacroCallId, attrs::AttrId, db::ExpandDatabase, name::Name};
@@ -740,35 +740,35 @@ impl ItemScope {
740740
entries.sort_by_key(|(name, _)| name.clone());
741741

742742
for (name, def) in entries {
743-
format_to!(
744-
buf,
745-
"{}:",
746-
name.map_or("_".to_owned(), |name| name.display(db, Edition::LATEST).to_string())
747-
);
743+
let display_name: &dyn fmt::Display = match &name {
744+
Some(name) => &name.display(db, Edition::LATEST),
745+
None => &"_",
746+
};
747+
format_to!(buf, "- {display_name} :");
748748

749749
if let Some(Item { import, .. }) = def.types {
750-
buf.push_str(" t");
750+
buf.push_str(" type");
751751
match import {
752-
Some(ImportOrExternCrate::Import(_)) => buf.push('i'),
753-
Some(ImportOrExternCrate::Glob(_)) => buf.push('g'),
754-
Some(ImportOrExternCrate::ExternCrate(_)) => buf.push('e'),
752+
Some(ImportOrExternCrate::Import(_)) => buf.push_str(" (import)"),
753+
Some(ImportOrExternCrate::Glob(_)) => buf.push_str(" (glob)"),
754+
Some(ImportOrExternCrate::ExternCrate(_)) => buf.push_str(" (extern)"),
755755
None => (),
756756
}
757757
}
758758
if let Some(Item { import, .. }) = def.values {
759-
buf.push_str(" v");
759+
buf.push_str(" value");
760760
match import {
761-
Some(ImportOrGlob::Import(_)) => buf.push('i'),
762-
Some(ImportOrGlob::Glob(_)) => buf.push('g'),
761+
Some(ImportOrGlob::Import(_)) => buf.push_str(" (import)"),
762+
Some(ImportOrGlob::Glob(_)) => buf.push_str(" (glob)"),
763763
None => (),
764764
}
765765
}
766766
if let Some(Item { import, .. }) = def.macros {
767-
buf.push_str(" m");
767+
buf.push_str(" macro");
768768
match import {
769-
Some(ImportOrExternCrate::Import(_)) => buf.push('i'),
770-
Some(ImportOrExternCrate::Glob(_)) => buf.push('g'),
771-
Some(ImportOrExternCrate::ExternCrate(_)) => buf.push('e'),
769+
Some(ImportOrExternCrate::Import(_)) => buf.push_str(" (import)"),
770+
Some(ImportOrExternCrate::Glob(_)) => buf.push_str(" (glob)"),
771+
Some(ImportOrExternCrate::ExternCrate(_)) => buf.push_str(" (extern)"),
772772
None => (),
773773
}
774774
}

src/tools/rust-analyzer/crates/hir-def/src/nameres.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ impl DefMap {
602602
let mut arc;
603603
let mut current_map = self;
604604
while let Some(block) = current_map.block {
605-
go(&mut buf, db, current_map, "block scope", Self::ROOT);
605+
go(&mut buf, db, current_map, "(block scope)", Self::ROOT);
606606
buf.push('\n');
607607
arc = block.parent.def_map(db, self.krate);
608608
current_map = arc;

0 commit comments

Comments
 (0)