2
2
3
3
use std:: fmt:: { self , Write } ;
4
4
5
+ use span:: ErasedFileAstId ;
6
+
5
7
use crate :: {
6
8
generics:: { TypeOrConstParamData , WherePredicate , WherePredicateTypeTarget } ,
7
9
pretty:: { print_path, print_type_bounds, print_type_ref} ,
@@ -118,7 +120,11 @@ impl Printer<'_> {
118
120
w ! ( self , "{{" ) ;
119
121
self . indented ( |this| {
120
122
for field in fields. clone ( ) {
121
- let Field { visibility, name, type_ref, ast_id : _ } = & this. tree [ field] ;
123
+ let Field { visibility, name, type_ref, ast_id } = & this. tree [ field] ;
124
+ this. print_ast_id ( match ast_id {
125
+ FieldAstId :: Record ( it) => it. erase ( ) ,
126
+ FieldAstId :: Tuple ( it) => it. erase ( ) ,
127
+ } ) ;
122
128
this. print_attrs_of ( field, "\n " ) ;
123
129
this. print_visibility ( * visibility) ;
124
130
w ! ( this, "{}: " , name. display( self . db. upcast( ) ) ) ;
@@ -132,7 +138,11 @@ impl Printer<'_> {
132
138
w ! ( self , "(" ) ;
133
139
self . indented ( |this| {
134
140
for field in fields. clone ( ) {
135
- let Field { visibility, name, type_ref, ast_id : _ } = & this. tree [ field] ;
141
+ let Field { visibility, name, type_ref, ast_id } = & this. tree [ field] ;
142
+ this. print_ast_id ( match ast_id {
143
+ FieldAstId :: Record ( it) => it. erase ( ) ,
144
+ FieldAstId :: Tuple ( it) => it. erase ( ) ,
145
+ } ) ;
136
146
this. print_attrs_of ( field, "\n " ) ;
137
147
this. print_visibility ( * visibility) ;
138
148
w ! ( this, "{}: " , name. display( self . db. upcast( ) ) ) ;
@@ -200,14 +210,16 @@ impl Printer<'_> {
200
210
201
211
match item {
202
212
ModItem :: Use ( it) => {
203
- let Use { visibility, use_tree, ast_id : _ } = & self . tree [ it] ;
213
+ let Use { visibility, use_tree, ast_id } = & self . tree [ it] ;
214
+ self . print_ast_id ( ast_id. erase ( ) ) ;
204
215
self . print_visibility ( * visibility) ;
205
216
w ! ( self , "use " ) ;
206
217
self . print_use_tree ( use_tree) ;
207
218
wln ! ( self , ";" ) ;
208
219
}
209
220
ModItem :: ExternCrate ( it) => {
210
- let ExternCrate { name, alias, visibility, ast_id : _ } = & self . tree [ it] ;
221
+ let ExternCrate { name, alias, visibility, ast_id } = & self . tree [ it] ;
222
+ self . print_ast_id ( ast_id. erase ( ) ) ;
211
223
self . print_visibility ( * visibility) ;
212
224
w ! ( self , "extern crate {}" , name. display( self . db. upcast( ) ) ) ;
213
225
if let Some ( alias) = alias {
@@ -216,7 +228,8 @@ impl Printer<'_> {
216
228
wln ! ( self , ";" ) ;
217
229
}
218
230
ModItem :: ExternBlock ( it) => {
219
- let ExternBlock { abi, ast_id : _, children } = & self . tree [ it] ;
231
+ let ExternBlock { abi, ast_id, children } = & self . tree [ it] ;
232
+ self . print_ast_id ( ast_id. erase ( ) ) ;
220
233
w ! ( self , "extern " ) ;
221
234
if let Some ( abi) = abi {
222
235
w ! ( self , "\" {}\" " , abi) ;
@@ -237,9 +250,10 @@ impl Printer<'_> {
237
250
abi,
238
251
params,
239
252
ret_type,
240
- ast_id : _ ,
253
+ ast_id,
241
254
flags,
242
255
} = & self . tree [ it] ;
256
+ self . print_ast_id ( ast_id. erase ( ) ) ;
243
257
self . print_visibility ( * visibility) ;
244
258
if flags. contains ( FnFlags :: HAS_DEFAULT_KW ) {
245
259
w ! ( self , "default " ) ;
@@ -263,7 +277,12 @@ impl Printer<'_> {
263
277
self . indented ( |this| {
264
278
for param in params. clone ( ) {
265
279
this. print_attrs_of ( param, "\n " ) ;
266
- match & this. tree [ param] . type_ref {
280
+ let Param { type_ref, ast_id } = & this. tree [ param] ;
281
+ this. print_ast_id ( match ast_id {
282
+ ParamAstId :: Param ( it) => it. erase ( ) ,
283
+ ParamAstId :: SelfParam ( it) => it. erase ( ) ,
284
+ } ) ;
285
+ match type_ref {
267
286
Some ( ty) => {
268
287
if flags. contains ( FnFlags :: HAS_SELF_PARAM ) {
269
288
w ! ( this, "self: " ) ;
@@ -288,7 +307,8 @@ impl Printer<'_> {
288
307
}
289
308
}
290
309
ModItem :: Struct ( it) => {
291
- let Struct { visibility, name, fields, generic_params, ast_id : _ } = & self . tree [ it] ;
310
+ let Struct { visibility, name, fields, generic_params, ast_id } = & self . tree [ it] ;
311
+ self . print_ast_id ( ast_id. erase ( ) ) ;
292
312
self . print_visibility ( * visibility) ;
293
313
w ! ( self , "struct {}" , name. display( self . db. upcast( ) ) ) ;
294
314
self . print_generic_params ( generic_params) ;
@@ -300,7 +320,8 @@ impl Printer<'_> {
300
320
}
301
321
}
302
322
ModItem :: Union ( it) => {
303
- let Union { name, visibility, fields, generic_params, ast_id : _ } = & self . tree [ it] ;
323
+ let Union { name, visibility, fields, generic_params, ast_id } = & self . tree [ it] ;
324
+ self . print_ast_id ( ast_id. erase ( ) ) ;
304
325
self . print_visibility ( * visibility) ;
305
326
w ! ( self , "union {}" , name. display( self . db. upcast( ) ) ) ;
306
327
self . print_generic_params ( generic_params) ;
@@ -312,14 +333,16 @@ impl Printer<'_> {
312
333
}
313
334
}
314
335
ModItem :: Enum ( it) => {
315
- let Enum { name, visibility, variants, generic_params, ast_id : _ } = & self . tree [ it] ;
336
+ let Enum { name, visibility, variants, generic_params, ast_id } = & self . tree [ it] ;
337
+ self . print_ast_id ( ast_id. erase ( ) ) ;
316
338
self . print_visibility ( * visibility) ;
317
339
w ! ( self , "enum {}" , name. display( self . db. upcast( ) ) ) ;
318
340
self . print_generic_params ( generic_params) ;
319
341
self . print_where_clause_and_opening_brace ( generic_params) ;
320
342
self . indented ( |this| {
321
343
for variant in FileItemTreeId :: range_iter ( variants. clone ( ) ) {
322
- let Variant { name, fields, ast_id : _ } = & this. tree [ variant] ;
344
+ let Variant { name, fields, ast_id } = & this. tree [ variant] ;
345
+ this. print_ast_id ( ast_id. erase ( ) ) ;
323
346
this. print_attrs_of ( variant, "\n " ) ;
324
347
w ! ( this, "{}" , name. display( self . db. upcast( ) ) ) ;
325
348
this. print_fields ( fields) ;
@@ -329,7 +352,8 @@ impl Printer<'_> {
329
352
wln ! ( self , "}}" ) ;
330
353
}
331
354
ModItem :: Const ( it) => {
332
- let Const { name, visibility, type_ref, ast_id : _ } = & self . tree [ it] ;
355
+ let Const { name, visibility, type_ref, ast_id } = & self . tree [ it] ;
356
+ self . print_ast_id ( ast_id. erase ( ) ) ;
333
357
self . print_visibility ( * visibility) ;
334
358
w ! ( self , "const " ) ;
335
359
match name {
@@ -341,7 +365,8 @@ impl Printer<'_> {
341
365
wln ! ( self , " = _;" ) ;
342
366
}
343
367
ModItem :: Static ( it) => {
344
- let Static { name, visibility, mutable, type_ref, ast_id : _ } = & self . tree [ it] ;
368
+ let Static { name, visibility, mutable, type_ref, ast_id } = & self . tree [ it] ;
369
+ self . print_ast_id ( ast_id. erase ( ) ) ;
345
370
self . print_visibility ( * visibility) ;
346
371
w ! ( self , "static " ) ;
347
372
if * mutable {
@@ -353,15 +378,9 @@ impl Printer<'_> {
353
378
wln ! ( self ) ;
354
379
}
355
380
ModItem :: Trait ( it) => {
356
- let Trait {
357
- name,
358
- visibility,
359
- is_auto,
360
- is_unsafe,
361
- items,
362
- generic_params,
363
- ast_id : _,
364
- } = & self . tree [ it] ;
381
+ let Trait { name, visibility, is_auto, is_unsafe, items, generic_params, ast_id } =
382
+ & self . tree [ it] ;
383
+ self . print_ast_id ( ast_id. erase ( ) ) ;
365
384
self . print_visibility ( * visibility) ;
366
385
if * is_unsafe {
367
386
w ! ( self , "unsafe " ) ;
@@ -380,7 +399,8 @@ impl Printer<'_> {
380
399
wln ! ( self , "}}" ) ;
381
400
}
382
401
ModItem :: TraitAlias ( it) => {
383
- let TraitAlias { name, visibility, generic_params, ast_id : _ } = & self . tree [ it] ;
402
+ let TraitAlias { name, visibility, generic_params, ast_id } = & self . tree [ it] ;
403
+ self . print_ast_id ( ast_id. erase ( ) ) ;
384
404
self . print_visibility ( * visibility) ;
385
405
w ! ( self , "trait {}" , name. display( self . db. upcast( ) ) ) ;
386
406
self . print_generic_params ( generic_params) ;
@@ -397,8 +417,9 @@ impl Printer<'_> {
397
417
is_unsafe,
398
418
items,
399
419
generic_params,
400
- ast_id : _ ,
420
+ ast_id,
401
421
} = & self . tree [ it] ;
422
+ self . print_ast_id ( ast_id. erase ( ) ) ;
402
423
if * is_unsafe {
403
424
w ! ( self , "unsafe" ) ;
404
425
}
@@ -422,8 +443,9 @@ impl Printer<'_> {
422
443
wln ! ( self , "}}" ) ;
423
444
}
424
445
ModItem :: TypeAlias ( it) => {
425
- let TypeAlias { name, visibility, bounds, type_ref, generic_params, ast_id : _ } =
446
+ let TypeAlias { name, visibility, bounds, type_ref, generic_params, ast_id } =
426
447
& self . tree [ it] ;
448
+ self . print_ast_id ( ast_id. erase ( ) ) ;
427
449
self . print_visibility ( * visibility) ;
428
450
w ! ( self , "type {}" , name. display( self . db. upcast( ) ) ) ;
429
451
self . print_generic_params ( generic_params) ;
@@ -440,7 +462,8 @@ impl Printer<'_> {
440
462
wln ! ( self ) ;
441
463
}
442
464
ModItem :: Mod ( it) => {
443
- let Mod { name, visibility, kind, ast_id : _ } = & self . tree [ it] ;
465
+ let Mod { name, visibility, kind, ast_id } = & self . tree [ it] ;
466
+ self . print_ast_id ( ast_id. erase ( ) ) ;
444
467
self . print_visibility ( * visibility) ;
445
468
w ! ( self , "mod {}" , name. display( self . db. upcast( ) ) ) ;
446
469
match kind {
@@ -459,15 +482,24 @@ impl Printer<'_> {
459
482
}
460
483
}
461
484
ModItem :: MacroCall ( it) => {
462
- let MacroCall { path, ast_id : _, expand_to : _, call_site : _ } = & self . tree [ it] ;
485
+ let MacroCall { path, ast_id, expand_to, call_site } = & self . tree [ it] ;
486
+ let _ = writeln ! (
487
+ self ,
488
+ "// AstId: {:?}, Span: {}, ExpandTo: {:?}" ,
489
+ ast_id. erase( ) . into_raw( ) ,
490
+ call_site,
491
+ expand_to
492
+ ) ;
463
493
wln ! ( self , "{}!(...);" , path. display( self . db. upcast( ) ) ) ;
464
494
}
465
495
ModItem :: MacroRules ( it) => {
466
- let MacroRules { name, ast_id : _ } = & self . tree [ it] ;
496
+ let MacroRules { name, ast_id } = & self . tree [ it] ;
497
+ self . print_ast_id ( ast_id. erase ( ) ) ;
467
498
wln ! ( self , "macro_rules! {} {{ ... }}" , name. display( self . db. upcast( ) ) ) ;
468
499
}
469
500
ModItem :: Macro2 ( it) => {
470
- let Macro2 { name, visibility, ast_id : _ } = & self . tree [ it] ;
501
+ let Macro2 { name, visibility, ast_id } = & self . tree [ it] ;
502
+ self . print_ast_id ( ast_id. erase ( ) ) ;
471
503
self . print_visibility ( * visibility) ;
472
504
wln ! ( self , "macro {} {{ ... }}" , name. display( self . db. upcast( ) ) ) ;
473
505
}
@@ -583,6 +615,10 @@ impl Printer<'_> {
583
615
} ) ;
584
616
true
585
617
}
618
+
619
+ fn print_ast_id ( & mut self , ast_id : ErasedFileAstId ) {
620
+ wln ! ( self , "// AstId: {:?}" , ast_id. into_raw( ) ) ;
621
+ }
586
622
}
587
623
588
624
impl Write for Printer < ' _ > {
0 commit comments