@@ -725,78 +725,125 @@ impl MetadataBlob {
725725 LazyValue :: < CrateRoot > :: from_position ( NonZeroUsize :: new ( pos) . unwrap ( ) ) . decode ( self )
726726 }
727727
728- pub ( crate ) fn list_crate_metadata ( & self , out : & mut dyn io:: Write ) -> io:: Result < ( ) > {
728+ pub ( crate ) fn list_crate_metadata (
729+ & self ,
730+ out : & mut dyn io:: Write ,
731+ ls_kinds : & [ String ] ,
732+ ) -> io:: Result < ( ) > {
729733 let root = self . get_root ( ) ;
730- writeln ! ( out, "Crate info:" ) ?;
731- writeln ! ( out, "name {}{}" , root. name( ) , root. extra_filename) ?;
732- writeln ! ( out, "hash {} stable_crate_id {:?}" , root. hash( ) , root. stable_crate_id) ?;
733- writeln ! ( out, "proc_macro {:?}" , root. proc_macro_data. is_some( ) ) ?;
734- writeln ! ( out, "triple {}" , root. header. triple. triple( ) ) ?;
735- writeln ! ( out, "edition {}" , root. edition) ?;
736- writeln ! ( out, "symbol_mangling_version {:?}" , root. symbol_mangling_version) ?;
737- writeln ! (
738- out,
739- "required_panic_strategy {:?} panic_in_drop_strategy {:?}" ,
740- root. required_panic_strategy, root. panic_in_drop_strategy
741- ) ?;
742- writeln ! (
743- out,
744- "has_global_allocator {} has_alloc_error_handler {} has_panic_handler {} has_default_lib_allocator {}" ,
745- root. has_global_allocator,
746- root. has_alloc_error_handler,
747- root. has_panic_handler,
748- root. has_default_lib_allocator
749- ) ?;
750- writeln ! (
751- out,
752- "compiler_builtins {} needs_allocator {} needs_panic_runtime {} no_builtins {} panic_runtime {} profiler_runtime {}" ,
753- root. compiler_builtins,
754- root. needs_allocator,
755- root. needs_panic_runtime,
756- root. no_builtins,
757- root. panic_runtime,
758- root. profiler_runtime
759- ) ?;
760-
761- writeln ! ( out, "\n =External Dependencies=" ) ?;
762- let dylib_dependency_formats =
763- root. dylib_dependency_formats . decode ( self ) . collect :: < Vec < _ > > ( ) ;
764- for ( i, dep) in root. crate_deps . decode ( self ) . enumerate ( ) {
765- let CrateDep { name, extra_filename, hash, host_hash, kind, is_private } = dep;
766- let number = i + 1 ;
767-
768- writeln ! (
769- out,
770- "{number} {name}{extra_filename} hash {hash} host_hash {host_hash:?} kind {kind:?} {privacy}{linkage}" ,
771- privacy = if is_private { "private" } else { "public" } ,
772- linkage = if dylib_dependency_formats. is_empty( ) {
773- String :: new( )
774- } else {
775- format!( " linkage {:?}" , dylib_dependency_formats[ i] )
734+
735+ let all_ls_kinds = vec ! [ "root" . to_owned( ) , "lang_items" . to_owned( ) , "features" . to_owned( ) ] ;
736+ let ls_kinds = if ls_kinds. contains ( & "all" . to_owned ( ) ) {
737+ & all_ls_kinds
738+ } else {
739+ ls_kinds
740+ } ;
741+
742+ for kind in ls_kinds {
743+ match & * * kind {
744+ "root" => {
745+ writeln ! ( out, "Crate info:" ) ?;
746+ writeln ! ( out, "name {}{}" , root. name( ) , root. extra_filename) ?;
747+ writeln ! (
748+ out,
749+ "hash {} stable_crate_id {:?}" ,
750+ root. hash( ) ,
751+ root. stable_crate_id
752+ ) ?;
753+ writeln ! ( out, "proc_macro {:?}" , root. proc_macro_data. is_some( ) ) ?;
754+ writeln ! ( out, "triple {}" , root. header. triple. triple( ) ) ?;
755+ writeln ! ( out, "edition {}" , root. edition) ?;
756+ writeln ! ( out, "symbol_mangling_version {:?}" , root. symbol_mangling_version) ?;
757+ writeln ! (
758+ out,
759+ "required_panic_strategy {:?} panic_in_drop_strategy {:?}" ,
760+ root. required_panic_strategy, root. panic_in_drop_strategy
761+ ) ?;
762+ writeln ! (
763+ out,
764+ "has_global_allocator {} has_alloc_error_handler {} has_panic_handler {} has_default_lib_allocator {}" ,
765+ root. has_global_allocator,
766+ root. has_alloc_error_handler,
767+ root. has_panic_handler,
768+ root. has_default_lib_allocator
769+ ) ?;
770+ writeln ! (
771+ out,
772+ "compiler_builtins {} needs_allocator {} needs_panic_runtime {} no_builtins {} panic_runtime {} profiler_runtime {}" ,
773+ root. compiler_builtins,
774+ root. needs_allocator,
775+ root. needs_panic_runtime,
776+ root. no_builtins,
777+ root. panic_runtime,
778+ root. profiler_runtime
779+ ) ?;
780+
781+ writeln ! ( out, "\n =External Dependencies=" ) ?;
782+ let dylib_dependency_formats =
783+ root. dylib_dependency_formats . decode ( self ) . collect :: < Vec < _ > > ( ) ;
784+ for ( i, dep) in root. crate_deps . decode ( self ) . enumerate ( ) {
785+ let CrateDep { name, extra_filename, hash, host_hash, kind, is_private } =
786+ dep;
787+ let number = i + 1 ;
788+
789+ writeln ! (
790+ out,
791+ "{number} {name}{extra_filename} hash {hash} host_hash {host_hash:?} kind {kind:?} {privacy}{linkage}" ,
792+ privacy = if is_private { "private" } else { "public" } ,
793+ linkage = if dylib_dependency_formats. is_empty( ) {
794+ String :: new( )
795+ } else {
796+ format!( " linkage {:?}" , dylib_dependency_formats[ i] )
797+ }
798+ ) ?;
799+ }
800+ write ! ( out, "\n " ) ?;
776801 }
777- ) ?;
778- }
779- write ! ( out, "\n " ) ?;
780-
781- writeln ! ( out, "\n =Lang items=" ) ?;
782- for ( id, lang_item) in root. lang_items . decode ( self ) {
783- writeln ! (
784- out,
785- "{} = crate{}" ,
786- lang_item. name( ) ,
787- DefPath :: make( LOCAL_CRATE , id, |parent| root
788- . tables
789- . def_keys
790- . get( self , parent)
791- . unwrap( )
792- . decode( self ) )
793- . to_string_no_crate_verbose( )
794- ) ?;
795- }
796- for lang_item in root. lang_items_missing . decode ( self ) {
797- writeln ! ( out, "{} = <missing>" , lang_item. name( ) ) ?;
802+
803+ "lang_items" => {
804+ writeln ! ( out, "\n =Lang items=" ) ?;
805+ for ( id, lang_item) in root. lang_items . decode ( self ) {
806+ writeln ! (
807+ out,
808+ "{} = crate{}" ,
809+ lang_item. name( ) ,
810+ DefPath :: make( LOCAL_CRATE , id, |parent| root
811+ . tables
812+ . def_keys
813+ . get( self , parent)
814+ . unwrap( )
815+ . decode( self ) )
816+ . to_string_no_crate_verbose( )
817+ ) ?;
818+ }
819+ for lang_item in root. lang_items_missing . decode ( self ) {
820+ writeln ! ( out, "{} = <missing>" , lang_item. name( ) ) ?;
821+ }
822+ write ! ( out, "\n " ) ?;
823+ }
824+
825+ "features" => {
826+ writeln ! ( out, "\n =Lib features=" ) ?;
827+ for ( feature, since) in root. lib_features . decode ( self ) {
828+ writeln ! (
829+ out,
830+ "{}{}" ,
831+ feature,
832+ if let Some ( since) = since {
833+ format!( " since {since}" )
834+ } else {
835+ String :: new( )
836+ }
837+ ) ?;
838+ }
839+ write ! ( out, "\n " ) ?;
840+ }
841+
842+ _ => {
843+ writeln ! ( out, "unknown -Zls kind. allowed values are: no, all, root, lang_items, features" ) ?;
844+ }
845+ }
798846 }
799- write ! ( out, "\n " ) ?;
800847
801848 Ok ( ( ) )
802849 }
0 commit comments