@@ -26,6 +26,7 @@ use rustc_errors::registry::{InvalidErrorCode, Registry};
2626use rustc_errors:: { ErrorGuaranteed , PResult } ;
2727use rustc_feature:: find_gated_cfg;
2828use rustc_hir:: def_id:: LOCAL_CRATE ;
29+ use rustc_interface:: interface:: CompilerIO ;
2930use rustc_interface:: util:: { self , collect_crate_types, get_codegen_backend} ;
3031use rustc_interface:: { interface, Queries } ;
3132use rustc_lint:: LintStore ;
@@ -262,10 +263,8 @@ fn run_compiler(
262263 let should_stop = print_crate_info (
263264 & * * * compiler. codegen_backend ( ) ,
264265 compiler. session ( ) ,
265- None ,
266- compiler. output_dir ( ) ,
267- compiler. output_file ( ) ,
268- compiler. temps_dir ( ) ,
266+ false ,
267+ compiler. io ( ) ,
269268 ) ;
270269
271270 if should_stop == Compilation :: Stop {
@@ -288,18 +287,16 @@ fn run_compiler(
288287
289288 interface:: run_compiler ( config, |compiler| {
290289 let sess = compiler. session ( ) ;
291- let should_stop = print_crate_info (
292- & * * * compiler. codegen_backend ( ) ,
293- sess,
294- Some ( compiler. input ( ) ) ,
295- compiler. output_dir ( ) ,
296- compiler. output_file ( ) ,
297- compiler. temps_dir ( ) ,
298- )
299- . and_then ( || {
300- list_metadata ( sess, & * compiler. codegen_backend ( ) . metadata_loader ( ) , compiler. input ( ) )
301- } )
302- . and_then ( || try_process_rlink ( sess, compiler) ) ;
290+ let should_stop =
291+ print_crate_info ( & * * * compiler. codegen_backend ( ) , sess, true , compiler. io ( ) )
292+ . and_then ( || {
293+ list_metadata (
294+ sess,
295+ & * compiler. codegen_backend ( ) . metadata_loader ( ) ,
296+ & compiler. io ( ) . input ,
297+ )
298+ } )
299+ . and_then ( || try_process_rlink ( sess, compiler) ) ;
303300
304301 if should_stop == Compilation :: Stop {
305302 return sess. compile_status ( ) ;
@@ -315,22 +312,15 @@ fn run_compiler(
315312 queries. global_ctxt ( ) ?. enter ( |tcx| {
316313 pretty:: print_after_hir_lowering (
317314 tcx,
318- compiler. input ( ) ,
315+ compiler. io ( ) ,
319316 & * expanded_crate,
320317 * ppm,
321- compiler. output_file ( ) . as_deref ( ) ,
322318 ) ;
323319 Ok ( ( ) )
324320 } ) ?;
325321 } else {
326322 let krate = queries. parse ( ) ?. steal ( ) ;
327- pretty:: print_after_parsing (
328- sess,
329- compiler. input ( ) ,
330- & krate,
331- * ppm,
332- compiler. output_file ( ) . as_deref ( ) ,
333- ) ;
323+ pretty:: print_after_parsing ( sess, compiler. io ( ) , & krate, * ppm) ;
334324 }
335325 trace ! ( "finished pretty-printing" ) ;
336326 return early_exit ( ) ;
@@ -380,9 +370,9 @@ fn run_compiler(
380370 save:: process_crate (
381371 tcx,
382372 crate_name,
383- compiler. input ( ) ,
373+ & compiler. io ( ) . input ,
384374 None ,
385- DumpHandler :: new ( compiler. output_dir ( ) . as_deref ( ) , crate_name) ,
375+ DumpHandler :: new ( compiler. io ( ) . output_dir . as_deref ( ) , crate_name) ,
386376 )
387377 } ) ;
388378 }
@@ -556,7 +546,7 @@ fn show_content_with_pager(content: &str) {
556546
557547pub fn try_process_rlink ( sess : & Session , compiler : & interface:: Compiler ) -> Compilation {
558548 if sess. opts . unstable_opts . link_only {
559- if let Input :: File ( file) = compiler. input ( ) {
549+ if let Input :: File ( file) = & compiler. io ( ) . input {
560550 // FIXME: #![crate_type] and #![crate_name] support not implemented yet
561551 sess. init_crate_types ( collect_crate_types ( sess, & [ ] ) ) ;
562552 let outputs = compiler. build_output_filenames ( sess, & [ ] ) ;
@@ -623,10 +613,8 @@ pub fn list_metadata(
623613fn print_crate_info (
624614 codegen_backend : & dyn CodegenBackend ,
625615 sess : & Session ,
626- input : Option < & Input > ,
627- odir : & Option < PathBuf > ,
628- ofile : & Option < PathBuf > ,
629- temps_dir : & Option < PathBuf > ,
616+ parse_attrs : bool ,
617+ io : & CompilerIO ,
630618) -> Compilation {
631619 use rustc_session:: config:: PrintRequest :: * ;
632620 // NativeStaticLibs and LinkArgs are special - printed during linking
@@ -635,18 +623,17 @@ fn print_crate_info(
635623 return Compilation :: Continue ;
636624 }
637625
638- let attrs = match input {
639- None => None ,
640- Some ( input) => {
641- let result = parse_crate_attrs ( sess, input) ;
642- match result {
643- Ok ( attrs) => Some ( attrs) ,
644- Err ( mut parse_error) => {
645- parse_error. emit ( ) ;
646- return Compilation :: Stop ;
647- }
626+ let attrs = if parse_attrs {
627+ let result = parse_crate_attrs ( sess, & io. input ) ;
628+ match result {
629+ Ok ( attrs) => Some ( attrs) ,
630+ Err ( mut parse_error) => {
631+ parse_error. emit ( ) ;
632+ return Compilation :: Stop ;
648633 }
649634 }
635+ } else {
636+ None
650637 } ;
651638 for req in & sess. opts . prints {
652639 match * req {
@@ -661,14 +648,9 @@ fn print_crate_info(
661648 println ! ( "{}" , serde_json:: to_string_pretty( & sess. target. to_json( ) ) . unwrap( ) ) ;
662649 }
663650 FileNames | CrateName => {
664- let input = input. unwrap_or_else ( || {
665- early_error ( ErrorOutputType :: default ( ) , "no input file provided" )
666- } ) ;
667651 let attrs = attrs. as_ref ( ) . unwrap ( ) ;
668- let t_outputs = rustc_interface:: util:: build_output_filenames (
669- input, odir, ofile, temps_dir, attrs, sess,
670- ) ;
671- let id = rustc_session:: output:: find_crate_name ( sess, attrs, input) ;
652+ let t_outputs = rustc_interface:: util:: build_output_filenames ( io, attrs, sess) ;
653+ let id = rustc_session:: output:: find_crate_name ( sess, attrs, & io. input ) ;
672654 if * req == PrintRequest :: CrateName {
673655 println ! ( "{id}" ) ;
674656 continue ;
0 commit comments