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