@@ -51,8 +51,8 @@ use std::cmp::max;
5151use std:: collections:: BTreeMap ;
5252use std:: env;
5353use std:: ffi:: OsString ;
54- use std:: fmt;
55- use std:: fs:: { self , File } ;
54+ use std:: fmt:: Write as _ ;
55+ use std:: fs;
5656use std:: io:: { self , IsTerminal , Read , Write } ;
5757use std:: panic:: { self , catch_unwind} ;
5858use std:: path:: PathBuf ;
@@ -750,30 +750,12 @@ fn print_crate_info(
750750 None
751751 } ;
752752
753- let mut output_io: Box <dyn Write > = match & sess. io. output_file {
754- Some ( OutFileName :: Real ( output_file_path) ) => match File :: create( output_file_path) {
755- Ok ( output_file) => Box :: new( output_file) ,
756- Err ( err) => handler. early_error( format!(
757- "failed to create {}: {}" ,
758- output_file_path. display( ) ,
759- err,
760- ) ) ,
761- } ,
762- None | Some ( OutFileName :: Stdout ) => Box :: new( io:: stdout( ) ) ,
763- } ;
764-
765- fn write_output( output_io: & mut dyn Write , args: fmt:: Arguments <' _>) {
766- if let Err ( _) = output_io. write_fmt( args) {
767- rustc_errors:: FatalError . raise( ) ;
768- }
769- }
770-
771- macro_rules! println_info {
772- ( $( $arg: tt) * ) => {
773- write_output( & mut * output_io, format_args!( "{}\n " , format_args!( $( $arg) * ) ) )
774- } ;
753+ let mut crate_info = String :: new( ) ;
754+ macro println_info( $( $arg: tt) * ) {
755+ crate_info. write_fmt( format_args!( "{}\n " , format_args!( $( $arg) * ) ) ) . unwrap( )
775756 }
776757
758+ let mut how_to_proceed = Compilation :: Stop ;
777759 for req in & sess. opts. prints {
778760 match * req {
779761 TargetList => {
@@ -798,7 +780,8 @@ fn print_crate_info(
798780 FileNames | CrateName => {
799781 let Some ( attrs) = attrs. as_ref( ) else {
800782 // no crate attributes, print out an error and exit
801- return Compilation :: Continue ;
783+ how_to_proceed = Compilation :: Continue ;
784+ break ;
802785 } ;
803786 let t_outputs = rustc_interface:: util:: build_output_filenames( attrs, sess) ;
804787 let id = rustc_session:: output:: find_crate_name( sess, attrs) ;
@@ -888,7 +871,9 @@ fn print_crate_info(
888871 }
889872 }
890873 }
891- Compilation :: Stop
874+
875+ pretty:: write_or_print( & crate_info, sess) ;
876+ how_to_proceed
892877}
893878
894879/// Prints version information
0 commit comments