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