@@ -393,13 +393,17 @@ fn run_compiler(
393
393
394
394
let linker = compiler. enter( |queries| {
395
395
let early_exit = || early_exit( ) . map( |_| None ) ;
396
+
397
+ // Parse the crate root source code (doesn't parse submodules yet)
398
+ // Everything else is parsed during macro expansion.
396
399
queries. parse( ) ?;
397
400
398
- if let Some ( ppm) = & sess. opts. pretty {
399
- if ppm. needs_ast_map( ) {
401
+ // If pretty printing is requested: Figure out the representation, print it and exit
402
+ if let Some ( pp_mode) = sess. opts. pretty {
403
+ if pp_mode. needs_ast_map( ) {
400
404
queries. global_ctxt( ) ?. enter( |tcx| {
401
405
tcx. ensure( ) . early_lint_checks( ( ) ) ;
402
- pretty:: print( sess, * ppm , pretty:: PrintExtra :: NeedsAstMap { tcx } ) ;
406
+ pretty:: print( sess, pp_mode , pretty:: PrintExtra :: NeedsAstMap { tcx } ) ;
403
407
Ok ( ( ) )
404
408
} ) ?;
405
409
@@ -410,7 +414,7 @@ fn run_compiler(
410
414
let krate = queries. parse( ) ?;
411
415
pretty:: print(
412
416
sess,
413
- * ppm ,
417
+ pp_mode ,
414
418
pretty:: PrintExtra :: AfterParsing { krate: & * krate. borrow( ) } ,
415
419
) ;
416
420
}
@@ -465,12 +469,8 @@ fn run_compiler(
465
469
linker. link( sess, codegen_backend) ?
466
470
}
467
471
468
- if sess. opts. unstable_opts. print_fuel. is_some( ) {
469
- eprintln!(
470
- "Fuel used by {}: {}" ,
471
- sess. opts. unstable_opts. print_fuel. as_ref( ) . unwrap( ) ,
472
- sess. print_fuel. load( Ordering :: SeqCst )
473
- ) ;
472
+ if let Some ( fuel) = sess. opts. unstable_opts. print_fuel. as_deref( ) {
473
+ eprintln!( "Fuel used by {}: {}" , fuel, sess. print_fuel. load( Ordering :: SeqCst ) ) ;
474
474
}
475
475
476
476
Ok ( ( ) )
@@ -487,36 +487,43 @@ fn make_output(matches: &getopts::Matches) -> (Option<PathBuf>, Option<OutFileNa
487
487
( odir, ofile)
488
488
}
489
489
490
- // Extract input (string or file and optional path) from matches.
490
+ /// Extract input (string or file and optional path) from matches.
491
+ /// This handles reading from stdin if `-` is provided.
491
492
fn make_input(
492
493
early_dcx: & EarlyDiagCtxt ,
493
494
free_matches: & [ String ] ,
494
495
) -> Result <Option <Input >, ErrorGuaranteed > {
495
- let [ ifile] = free_matches else { return Ok ( None ) } ;
496
- if ifile == "-" {
497
- let mut src = String :: new( ) ;
498
- if io:: stdin( ) . read_to_string( & mut src) . is_err( ) {
499
- // Immediately stop compilation if there was an issue reading
500
- // the input (for example if the input stream is not UTF-8).
501
- let reported =
502
- early_dcx. early_err( "couldn't read from stdin, as it did not contain valid UTF-8" ) ;
503
- return Err ( reported) ;
504
- }
505
- if let Ok ( path) = env:: var( "UNSTABLE_RUSTDOC_TEST_PATH" ) {
496
+ let [ input_file] = free_matches else { return Ok ( None ) } ;
497
+
498
+ if input_file != "-" {
499
+ // Normal `Input::File`
500
+ return Ok ( Some ( Input :: File ( PathBuf :: from( input_file) ) ) ) ;
501
+ }
502
+
503
+ // read from stdin as `Input::Str`
504
+ let mut input = String :: new( ) ;
505
+ if io:: stdin( ) . read_to_string( & mut input) . is_err( ) {
506
+ // Immediately stop compilation if there was an issue reading
507
+ // the input (for example if the input stream is not UTF-8).
508
+ let reported =
509
+ early_dcx. early_err( "couldn't read from stdin, as it did not contain valid UTF-8" ) ;
510
+ return Err ( reported) ;
511
+ }
512
+
513
+ let name = match env:: var( "UNSTABLE_RUSTDOC_TEST_PATH" ) {
514
+ Ok ( path) => {
506
515
let line = env:: var( "UNSTABLE_RUSTDOC_TEST_LINE" ) . expect(
507
516
"when UNSTABLE_RUSTDOC_TEST_PATH is set \
508
517
UNSTABLE_RUSTDOC_TEST_LINE also needs to be set",
509
518
) ;
510
519
let line = isize :: from_str_radix( & line, 10 )
511
520
. expect( "UNSTABLE_RUSTDOC_TEST_LINE needs to be an number" ) ;
512
- let file_name = FileName :: doc_test_source_code( PathBuf :: from( path) , line) ;
513
- Ok ( Some ( Input :: Str { name: file_name, input: src } ) )
514
- } else {
515
- Ok ( Some ( Input :: Str { name: FileName :: anon_source_code( & src) , input: src } ) )
521
+ FileName :: doc_test_source_code( PathBuf :: from( path) , line)
516
522
}
517
- } else {
518
- Ok ( Some ( Input :: File ( PathBuf :: from( ifile) ) ) )
519
- }
523
+ Err ( _) => FileName :: anon_source_code( & input) ,
524
+ } ;
525
+
526
+ Ok ( Some ( Input :: Str { name, input } ) )
520
527
}
521
528
522
529
/// Whether to stop or continue compilation.
0 commit comments