1+ use core:: fmt;
12use std:: cell:: RefCell ;
23use std:: default:: Default ;
34use std:: hash:: Hash ;
@@ -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+ impl fmt:: Debug for Item {
371+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
372+ let alternate = f. alternate ( ) ;
373+ // hand-picked fields that don't bloat the logs too much
374+ let mut fmt = f. debug_struct ( "Item" ) ;
375+ fmt. field ( "name" , & self . name )
376+ . field ( "visibility" , & self . visibility )
377+ . field ( "def_id" , & self . def_id ) ;
378+ // allow printing the full item if someone really wants to
379+ if alternate {
380+ fmt. field ( "attrs" , & self . attrs ) . field ( "kind" , & self . kind ) . field ( "cfg" , & self . cfg ) ;
381+ } else {
382+ fmt. field ( "kind" , & self . type_ ( ) ) ;
383+ if let Some ( docs) = self . doc_value ( ) {
384+ fmt. field ( "docs" , & docs) ;
385+ }
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