2
2
3
3
use crate :: helpers:: mod_path_to_ast;
4
4
use either:: Either ;
5
- use hir:: { AsAssocItem , HirDisplay , ImportPathConfig , ModuleDef , SemanticsScope } ;
5
+ use hir:: {
6
+ AsAssocItem , HirDisplay , HirFileId , ImportPathConfig , ModuleDef , SemanticsScope ,
7
+ prettify_macro_expansion,
8
+ } ;
6
9
use itertools:: Itertools ;
7
10
use rustc_hash:: FxHashMap ;
8
11
use span:: Edition ;
@@ -136,6 +139,25 @@ impl<'a> PathTransform<'a> {
136
139
}
137
140
}
138
141
142
+ fn prettify_target_node ( & self , node : SyntaxNode ) -> SyntaxNode {
143
+ match self . target_scope . file_id ( ) {
144
+ HirFileId :: FileId ( _) => node,
145
+ HirFileId :: MacroFile ( file_id) => {
146
+ let db = self . target_scope . db ;
147
+ prettify_macro_expansion (
148
+ db,
149
+ node,
150
+ & db. expansion_span_map ( file_id) ,
151
+ self . target_scope . module ( ) . krate ( ) . into ( ) ,
152
+ )
153
+ }
154
+ }
155
+ }
156
+
157
+ fn prettify_target_ast < N : AstNode > ( & self , node : N ) -> N {
158
+ N :: cast ( self . prettify_target_node ( node. syntax ( ) . clone ( ) ) ) . unwrap ( )
159
+ }
160
+
139
161
fn build_ctx ( & self ) -> Ctx < ' a > {
140
162
let db = self . source_scope . db ;
141
163
let target_module = self . target_scope . module ( ) ;
@@ -163,7 +185,7 @@ impl<'a> PathTransform<'a> {
163
185
. for_each ( |( k, v) | match ( k. split ( db) , v) {
164
186
( Either :: Right ( k) , Some ( TypeOrConst :: Either ( v) ) ) => {
165
187
if let Some ( ty) = v. ty ( ) {
166
- type_substs. insert ( k, ty ) ;
188
+ type_substs. insert ( k, self . prettify_target_ast ( ty ) ) ;
167
189
}
168
190
}
169
191
( Either :: Right ( k) , None ) => {
@@ -178,7 +200,7 @@ impl<'a> PathTransform<'a> {
178
200
}
179
201
( Either :: Left ( k) , Some ( TypeOrConst :: Either ( v) ) ) => {
180
202
if let Some ( ty) = v. ty ( ) {
181
- const_substs. insert ( k, ty. syntax ( ) . clone ( ) ) ;
203
+ const_substs. insert ( k, self . prettify_target_node ( ty. syntax ( ) . clone ( ) ) ) ;
182
204
}
183
205
}
184
206
( Either :: Left ( k) , Some ( TypeOrConst :: Const ( v) ) ) => {
@@ -189,7 +211,7 @@ impl<'a> PathTransform<'a> {
189
211
// and sometimes require slight modifications; see
190
212
// https://doc.rust-lang.org/reference/statements.html#expression-statements
191
213
// (default values in curly brackets can cause the same problem)
192
- const_substs. insert ( k, expr. syntax ( ) . clone ( ) ) ;
214
+ const_substs. insert ( k, self . prettify_target_node ( expr. syntax ( ) . clone ( ) ) ) ;
193
215
}
194
216
}
195
217
( Either :: Left ( k) , None ) => {
@@ -204,6 +226,7 @@ impl<'a> PathTransform<'a> {
204
226
}
205
227
_ => ( ) , // ignore mismatching params
206
228
} ) ;
229
+ // No need to prettify lifetimes, there's nothing to prettify.
207
230
let lifetime_substs: FxHashMap < _ , _ > = self
208
231
. generic_def
209
232
. into_iter ( )
0 commit comments