1
1
use std:: cell:: RefCell ;
2
2
use std:: default:: Default ;
3
+ use std:: fmt;
3
4
use std:: hash:: Hash ;
4
5
use std:: iter;
5
6
use std:: lazy:: SyncOnceCell as OnceCell ;
@@ -355,7 +356,7 @@ crate enum ExternalLocation {
355
356
/// Anything with a source location and set of attributes and, optionally, a
356
357
/// name. That is, anything that can be documented. This doesn't correspond
357
358
/// directly to the AST's concept of an item; it's a strict superset.
358
- #[ derive( Clone , Debug ) ]
359
+ #[ derive( Clone ) ]
359
360
crate struct Item {
360
361
/// The name of this item.
361
362
/// Optional because not every item has a name, e.g. impls.
@@ -370,6 +371,27 @@ crate struct Item {
370
371
crate cfg : Option < Arc < Cfg > > ,
371
372
}
372
373
374
+ /// NOTE: this does NOT unconditionally print every item, to avoid thousands of lines of logs.
375
+ /// If you want to see the debug output for attributes and the `kind` as well, use `{:#?}` instead of `{:?}`.
376
+ impl fmt:: Debug for Item {
377
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
378
+ let alternate = f. alternate ( ) ;
379
+ // hand-picked fields that don't bloat the logs too much
380
+ let mut fmt = f. debug_struct ( "Item" ) ;
381
+ fmt. field ( "name" , & self . name )
382
+ . field ( "visibility" , & self . visibility )
383
+ . field ( "def_id" , & self . def_id ) ;
384
+ // allow printing the full item if someone really wants to
385
+ if alternate {
386
+ fmt. field ( "attrs" , & self . attrs ) . field ( "kind" , & self . kind ) . field ( "cfg" , & self . cfg ) ;
387
+ } else {
388
+ fmt. field ( "kind" , & self . type_ ( ) ) ;
389
+ fmt. field ( "docs" , & self . doc_value ( ) ) ;
390
+ }
391
+ fmt. finish ( )
392
+ }
393
+ }
394
+
373
395
// `Item` is used a lot. Make sure it doesn't unintentionally get bigger.
374
396
#[ cfg( all( target_arch = "x86_64" , target_pointer_width = "64" ) ) ]
375
397
rustc_data_structures:: static_assert_size!( Item , 56 ) ;
0 commit comments