1
1
//! A map of all publicly exported items in a crate.
2
2
3
- use std:: { collections:: hash_map:: Entry , sync:: Arc } ;
3
+ use std:: { collections:: hash_map:: Entry , fmt , sync:: Arc } ;
4
4
5
5
use ra_db:: CrateId ;
6
6
use rustc_hash:: FxHashMap ;
@@ -21,7 +21,7 @@ use crate::{
21
21
///
22
22
/// Note that all paths are relative to the containing crate's root, so the crate name still needs
23
23
/// to be prepended to the `ModPath` before the path is valid.
24
- #[ derive( Debug , Eq , PartialEq ) ]
24
+ #[ derive( Eq , PartialEq ) ]
25
25
pub struct ImportMap {
26
26
map : FxHashMap < ItemInNs , ModPath > ,
27
27
}
@@ -95,6 +95,26 @@ impl ImportMap {
95
95
}
96
96
}
97
97
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
+
98
118
#[ cfg( test) ]
99
119
mod tests {
100
120
use super :: * ;
@@ -115,23 +135,7 @@ mod tests {
115
135
116
136
let map = db. import_map ( krate) ;
117
137
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) )
135
139
} )
136
140
. collect ( ) ;
137
141
0 commit comments