From 1a8ea81a791dbd72e67dfcc94a863d2af310bfdd Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Wed, 3 Feb 2021 19:05:11 +0100 Subject: Split out ItemScope::dump from DefMap::dump --- crates/hir_def/src/item_scope.rs | 25 +++++++++++++++++++++++++ crates/hir_def/src/nameres.rs | 22 +--------------------- 2 files changed, 26 insertions(+), 21 deletions(-) (limited to 'crates') diff --git a/crates/hir_def/src/item_scope.rs b/crates/hir_def/src/item_scope.rs index 2750e1c91..ee46c3330 100644 --- a/crates/hir_def/src/item_scope.rs +++ b/crates/hir_def/src/item_scope.rs @@ -8,6 +8,7 @@ use hir_expand::name::Name; use hir_expand::MacroDefKind; use once_cell::sync::Lazy; use rustc_hash::{FxHashMap, FxHashSet}; +use stdx::format_to; use test_utils::mark; use crate::{ @@ -292,6 +293,30 @@ impl ItemScope { *vis = Visibility::Module(this_module); } } + + pub(crate) fn dump(&self, buf: &mut String) { + let mut entries: Vec<_> = self.resolutions().collect(); + entries.sort_by_key(|(name, _)| name.clone()); + + for (name, def) in entries { + format_to!(buf, "{}:", name.map_or("_".to_string(), |name| name.to_string())); + + if def.types.is_some() { + buf.push_str(" t"); + } + if def.values.is_some() { + buf.push_str(" v"); + } + if def.macros.is_some() { + buf.push_str(" m"); + } + if def.is_none() { + buf.push_str(" _"); + } + + buf.push('\n'); + } + } } impl PerNs { diff --git a/crates/hir_def/src/nameres.rs b/crates/hir_def/src/nameres.rs index c858ea0c4..68998c121 100644 --- a/crates/hir_def/src/nameres.rs +++ b/crates/hir_def/src/nameres.rs @@ -333,27 +333,7 @@ impl DefMap { fn go(buf: &mut String, map: &DefMap, path: &str, module: LocalModuleId) { format_to!(buf, "{}\n", path); - let mut entries: Vec<_> = map.modules[module].scope.resolutions().collect(); - entries.sort_by_key(|(name, _)| name.clone()); - - for (name, def) in entries { - format_to!(buf, "{}:", name.map_or("_".to_string(), |name| name.to_string())); - - if def.types.is_some() { - buf.push_str(" t"); - } - if def.values.is_some() { - buf.push_str(" v"); - } - if def.macros.is_some() { - buf.push_str(" m"); - } - if def.is_none() { - buf.push_str(" _"); - } - - buf.push('\n'); - } + map.modules[module].scope.dump(buf); for (name, child) in map.modules[module].children.iter() { let path = format!("{}::{}", path, name); -- cgit v1.2.3