Skip to content

Commit 2fb3d87

Browse files
author
Jonas Schievink
committed
impl Debug for ImportMap
1 parent 8395396 commit 2fb3d87

File tree

1 file changed

+23
-19
lines changed

1 file changed

+23
-19
lines changed

crates/ra_hir_def/src/import_map.rs

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! A map of all publicly exported items in a crate.
22
3-
use std::{collections::hash_map::Entry, sync::Arc};
3+
use std::{collections::hash_map::Entry, fmt, sync::Arc};
44

55
use ra_db::CrateId;
66
use rustc_hash::FxHashMap;
@@ -21,7 +21,7 @@ use crate::{
2121
///
2222
/// Note that all paths are relative to the containing crate's root, so the crate name still needs
2323
/// to be prepended to the `ModPath` before the path is valid.
24-
#[derive(Debug, Eq, PartialEq)]
24+
#[derive(Eq, PartialEq)]
2525
pub struct ImportMap {
2626
map: FxHashMap<ItemInNs, ModPath>,
2727
}
@@ -95,6 +95,26 @@ impl ImportMap {
9595
}
9696
}
9797

98+
impl fmt::Debug for ImportMap {
99+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
100+
let mut importable_paths: Vec<_> = self
101+
.map
102+
.iter()
103+
.map(|(item, modpath)| {
104+
let ns = match item {
105+
ItemInNs::Types(_) => "t",
106+
ItemInNs::Values(_) => "v",
107+
ItemInNs::Macros(_) => "m",
108+
};
109+
format!("- {} ({})", modpath, ns)
110+
})
111+
.collect();
112+
113+
importable_paths.sort();
114+
f.write_str(&importable_paths.join("\n"))
115+
}
116+
}
117+
98118
#[cfg(test)]
99119
mod tests {
100120
use super::*;
@@ -115,23 +135,7 @@ mod tests {
115135

116136
let map = db.import_map(krate);
117137

118-
let mut importable_paths: Vec<_> = map
119-
.map
120-
.iter()
121-
.map(|(item, modpath)| {
122-
let ns = match item {
123-
ItemInNs::Types(_) => "t",
124-
ItemInNs::Values(_) => "v",
125-
ItemInNs::Macros(_) => "m",
126-
};
127-
format!("- {} ({})", modpath, ns)
128-
})
129-
.collect();
130-
131-
importable_paths.sort();
132-
let importable_paths = importable_paths.join("\n");
133-
134-
Some(format!("{}:\n{}", name, importable_paths))
138+
Some(format!("{}:\n{:?}", name, map))
135139
})
136140
.collect();
137141

0 commit comments

Comments
 (0)