11use std:: cell:: RefCell ;
22use std:: default:: Default ;
3+ use std:: fmt;
34use std:: hash:: Hash ;
45use std:: iter;
56use std:: lazy:: SyncOnceCell as OnceCell ;
@@ -355,7 +356,7 @@ crate enum ExternalLocation {
355356/// Anything with a source location and set of attributes and, optionally, a
356357/// name. That is, anything that can be documented. This doesn't correspond
357358/// directly to the AST's concept of an item; it's a strict superset.
358- #[ derive( Clone , Debug ) ]
359+ #[ derive( Clone ) ]
359360crate struct Item {
360361 /// The name of this item.
361362 /// Optional because not every item has a name, e.g. impls.
@@ -370,6 +371,27 @@ crate struct Item {
370371 crate cfg : Option < Arc < Cfg > > ,
371372}
372373
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+
373395// `Item` is used a lot. Make sure it doesn't unintentionally get bigger.
374396#[ cfg( all( target_arch = "x86_64" , target_pointer_width = "64" ) ) ]
375397rustc_data_structures:: static_assert_size!( Item , 56 ) ;
0 commit comments