22
33use std:: fmt:: { self , Write } ;
44
5+ use span:: ErasedFileAstId ;
6+
57use crate :: {
68 generics:: { TypeOrConstParamData , WherePredicate , WherePredicateTypeTarget } ,
79 pretty:: { print_path, print_type_bounds, print_type_ref} ,
@@ -118,7 +120,11 @@ impl Printer<'_> {
118120 w ! ( self , "{{" ) ;
119121 self . indented ( |this| {
120122 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+ } ) ;
122128 this. print_attrs_of ( field, "\n " ) ;
123129 this. print_visibility ( * visibility) ;
124130 w ! ( this, "{}: " , name. display( self . db. upcast( ) ) ) ;
@@ -132,7 +138,11 @@ impl Printer<'_> {
132138 w ! ( self , "(" ) ;
133139 self . indented ( |this| {
134140 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+ } ) ;
136146 this. print_attrs_of ( field, "\n " ) ;
137147 this. print_visibility ( * visibility) ;
138148 w ! ( this, "{}: " , name. display( self . db. upcast( ) ) ) ;
@@ -200,14 +210,16 @@ impl Printer<'_> {
200210
201211 match item {
202212 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 ( ) ) ;
204215 self . print_visibility ( * visibility) ;
205216 w ! ( self , "use " ) ;
206217 self . print_use_tree ( use_tree) ;
207218 wln ! ( self , ";" ) ;
208219 }
209220 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 ( ) ) ;
211223 self . print_visibility ( * visibility) ;
212224 w ! ( self , "extern crate {}" , name. display( self . db. upcast( ) ) ) ;
213225 if let Some ( alias) = alias {
@@ -216,7 +228,8 @@ impl Printer<'_> {
216228 wln ! ( self , ";" ) ;
217229 }
218230 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 ( ) ) ;
220233 w ! ( self , "extern " ) ;
221234 if let Some ( abi) = abi {
222235 w ! ( self , "\" {}\" " , abi) ;
@@ -237,9 +250,10 @@ impl Printer<'_> {
237250 abi,
238251 params,
239252 ret_type,
240- ast_id : _ ,
253+ ast_id,
241254 flags,
242255 } = & self . tree [ it] ;
256+ self . print_ast_id ( ast_id. erase ( ) ) ;
243257 self . print_visibility ( * visibility) ;
244258 if flags. contains ( FnFlags :: HAS_DEFAULT_KW ) {
245259 w ! ( self , "default " ) ;
@@ -263,7 +277,12 @@ impl Printer<'_> {
263277 self . indented ( |this| {
264278 for param in params. clone ( ) {
265279 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 {
267286 Some ( ty) => {
268287 if flags. contains ( FnFlags :: HAS_SELF_PARAM ) {
269288 w ! ( this, "self: " ) ;
@@ -288,7 +307,8 @@ impl Printer<'_> {
288307 }
289308 }
290309 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 ( ) ) ;
292312 self . print_visibility ( * visibility) ;
293313 w ! ( self , "struct {}" , name. display( self . db. upcast( ) ) ) ;
294314 self . print_generic_params ( generic_params) ;
@@ -300,7 +320,8 @@ impl Printer<'_> {
300320 }
301321 }
302322 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 ( ) ) ;
304325 self . print_visibility ( * visibility) ;
305326 w ! ( self , "union {}" , name. display( self . db. upcast( ) ) ) ;
306327 self . print_generic_params ( generic_params) ;
@@ -312,14 +333,16 @@ impl Printer<'_> {
312333 }
313334 }
314335 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 ( ) ) ;
316338 self . print_visibility ( * visibility) ;
317339 w ! ( self , "enum {}" , name. display( self . db. upcast( ) ) ) ;
318340 self . print_generic_params ( generic_params) ;
319341 self . print_where_clause_and_opening_brace ( generic_params) ;
320342 self . indented ( |this| {
321343 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 ( ) ) ;
323346 this. print_attrs_of ( variant, "\n " ) ;
324347 w ! ( this, "{}" , name. display( self . db. upcast( ) ) ) ;
325348 this. print_fields ( fields) ;
@@ -329,7 +352,8 @@ impl Printer<'_> {
329352 wln ! ( self , "}}" ) ;
330353 }
331354 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 ( ) ) ;
333357 self . print_visibility ( * visibility) ;
334358 w ! ( self , "const " ) ;
335359 match name {
@@ -341,7 +365,8 @@ impl Printer<'_> {
341365 wln ! ( self , " = _;" ) ;
342366 }
343367 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 ( ) ) ;
345370 self . print_visibility ( * visibility) ;
346371 w ! ( self , "static " ) ;
347372 if * mutable {
@@ -353,15 +378,9 @@ impl Printer<'_> {
353378 wln ! ( self ) ;
354379 }
355380 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 ( ) ) ;
365384 self . print_visibility ( * visibility) ;
366385 if * is_unsafe {
367386 w ! ( self , "unsafe " ) ;
@@ -380,7 +399,8 @@ impl Printer<'_> {
380399 wln ! ( self , "}}" ) ;
381400 }
382401 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 ( ) ) ;
384404 self . print_visibility ( * visibility) ;
385405 w ! ( self , "trait {}" , name. display( self . db. upcast( ) ) ) ;
386406 self . print_generic_params ( generic_params) ;
@@ -397,8 +417,9 @@ impl Printer<'_> {
397417 is_unsafe,
398418 items,
399419 generic_params,
400- ast_id : _ ,
420+ ast_id,
401421 } = & self . tree [ it] ;
422+ self . print_ast_id ( ast_id. erase ( ) ) ;
402423 if * is_unsafe {
403424 w ! ( self , "unsafe" ) ;
404425 }
@@ -422,8 +443,9 @@ impl Printer<'_> {
422443 wln ! ( self , "}}" ) ;
423444 }
424445 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 } =
426447 & self . tree [ it] ;
448+ self . print_ast_id ( ast_id. erase ( ) ) ;
427449 self . print_visibility ( * visibility) ;
428450 w ! ( self , "type {}" , name. display( self . db. upcast( ) ) ) ;
429451 self . print_generic_params ( generic_params) ;
@@ -440,7 +462,8 @@ impl Printer<'_> {
440462 wln ! ( self ) ;
441463 }
442464 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 ( ) ) ;
444467 self . print_visibility ( * visibility) ;
445468 w ! ( self , "mod {}" , name. display( self . db. upcast( ) ) ) ;
446469 match kind {
@@ -459,15 +482,24 @@ impl Printer<'_> {
459482 }
460483 }
461484 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+ ) ;
463493 wln ! ( self , "{}!(...);" , path. display( self . db. upcast( ) ) ) ;
464494 }
465495 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 ( ) ) ;
467498 wln ! ( self , "macro_rules! {} {{ ... }}" , name. display( self . db. upcast( ) ) ) ;
468499 }
469500 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 ( ) ) ;
471503 self . print_visibility ( * visibility) ;
472504 wln ! ( self , "macro {} {{ ... }}" , name. display( self . db. upcast( ) ) ) ;
473505 }
@@ -583,6 +615,10 @@ impl Printer<'_> {
583615 } ) ;
584616 true
585617 }
618+
619+ fn print_ast_id ( & mut self , ast_id : ErasedFileAstId ) {
620+ wln ! ( self , "// AstId: {:?}" , ast_id. into_raw( ) ) ;
621+ }
586622}
587623
588624impl Write for Printer < ' _ > {
0 commit comments