]> git.lizzy.rs Git - rust.git/commitdiff
Split out ItemScope::dump from DefMap::dump
authorJonas Schievink <jonasschievink@gmail.com>
Wed, 3 Feb 2021 18:05:11 +0000 (19:05 +0100)
committerJonas Schievink <jonasschievink@gmail.com>
Wed, 3 Feb 2021 18:05:11 +0000 (19:05 +0100)
crates/hir_def/src/item_scope.rs
crates/hir_def/src/nameres.rs

index 2750e1c915d59dcb3174c7a6e89b180d4783b7fb..ee46c3330f53a8806fc4993a5311fffef22b1c8d 100644 (file)
@@ -8,6 +8,7 @@
 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 @@ pub(crate) fn censor_non_proc_macros(&mut self, this_module: ModuleId) {
             *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 {
index c858ea0c438de484f719c084f22f60b5efb2f67c..68998c121a29ccc6b62af8e11eadb2e94b85250b 100644 (file)
@@ -333,27 +333,7 @@ pub fn dump(&self) -> String {
         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);