@@ -26,6 +26,7 @@ use rustc_errors::registry::{InvalidErrorCode, Registry};
26
26
use rustc_errors:: { ErrorGuaranteed , PResult } ;
27
27
use rustc_feature:: find_gated_cfg;
28
28
use rustc_hir:: def_id:: LOCAL_CRATE ;
29
+ use rustc_interface:: interface:: CompilerIO ;
29
30
use rustc_interface:: util:: { self , collect_crate_types, get_codegen_backend} ;
30
31
use rustc_interface:: { interface, Queries } ;
31
32
use rustc_lint:: LintStore ;
@@ -262,10 +263,8 @@ fn run_compiler(
262
263
let should_stop = print_crate_info (
263
264
& * * * compiler. codegen_backend ( ) ,
264
265
compiler. session ( ) ,
265
- None ,
266
- compiler. output_dir ( ) ,
267
- compiler. output_file ( ) ,
268
- compiler. temps_dir ( ) ,
266
+ false ,
267
+ compiler. io ( ) ,
269
268
) ;
270
269
271
270
if should_stop == Compilation :: Stop {
@@ -288,18 +287,16 @@ fn run_compiler(
288
287
289
288
interface:: run_compiler ( config, |compiler| {
290
289
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) ) ;
303
300
304
301
if should_stop == Compilation :: Stop {
305
302
return sess. compile_status ( ) ;
@@ -315,22 +312,15 @@ fn run_compiler(
315
312
queries. global_ctxt ( ) ?. enter ( |tcx| {
316
313
pretty:: print_after_hir_lowering (
317
314
tcx,
318
- compiler. input ( ) ,
315
+ compiler. io ( ) ,
319
316
& * expanded_crate,
320
317
* ppm,
321
- compiler. output_file ( ) . as_deref ( ) ,
322
318
) ;
323
319
Ok ( ( ) )
324
320
} ) ?;
325
321
} else {
326
322
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) ;
334
324
}
335
325
trace ! ( "finished pretty-printing" ) ;
336
326
return early_exit ( ) ;
@@ -380,9 +370,9 @@ fn run_compiler(
380
370
save:: process_crate (
381
371
tcx,
382
372
crate_name,
383
- compiler. input ( ) ,
373
+ & compiler. io ( ) . input ,
384
374
None ,
385
- DumpHandler :: new ( compiler. output_dir ( ) . as_deref ( ) , crate_name) ,
375
+ DumpHandler :: new ( compiler. io ( ) . output_dir . as_deref ( ) , crate_name) ,
386
376
)
387
377
} ) ;
388
378
}
@@ -556,7 +546,7 @@ fn show_content_with_pager(content: &str) {
556
546
557
547
pub fn try_process_rlink ( sess : & Session , compiler : & interface:: Compiler ) -> Compilation {
558
548
if sess. opts . unstable_opts . link_only {
559
- if let Input :: File ( file) = compiler. input ( ) {
549
+ if let Input :: File ( file) = & compiler. io ( ) . input {
560
550
// FIXME: #![crate_type] and #![crate_name] support not implemented yet
561
551
sess. init_crate_types ( collect_crate_types ( sess, & [ ] ) ) ;
562
552
let outputs = compiler. build_output_filenames ( sess, & [ ] ) ;
@@ -623,10 +613,8 @@ pub fn list_metadata(
623
613
fn print_crate_info (
624
614
codegen_backend : & dyn CodegenBackend ,
625
615
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 ,
630
618
) -> Compilation {
631
619
use rustc_session:: config:: PrintRequest :: * ;
632
620
// NativeStaticLibs and LinkArgs are special - printed during linking
@@ -635,18 +623,17 @@ fn print_crate_info(
635
623
return Compilation :: Continue ;
636
624
}
637
625
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 ;
648
633
}
649
634
}
635
+ } else {
636
+ None
650
637
} ;
651
638
for req in & sess. opts . prints {
652
639
match * req {
@@ -661,14 +648,9 @@ fn print_crate_info(
661
648
println ! ( "{}" , serde_json:: to_string_pretty( & sess. target. to_json( ) ) . unwrap( ) ) ;
662
649
}
663
650
FileNames | CrateName => {
664
- let input = input. unwrap_or_else ( || {
665
- early_error ( ErrorOutputType :: default ( ) , "no input file provided" )
666
- } ) ;
667
651
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 ) ;
672
654
if * req == PrintRequest :: CrateName {
673
655
println ! ( "{id}" ) ;
674
656
continue ;
0 commit comments