@@ -160,6 +160,9 @@ pub trait Callbacks {
160
160
/// Called after parsing the crate root. Submodules are not yet parsed when
161
161
/// this callback is called. Return value instructs the compiler whether to
162
162
/// continue the compilation afterwards (defaults to `Compilation::Continue`)
163
+ #[ deprecated = "This callback will likely be removed or stop giving access \
164
+ to the TyCtxt in the future. Use either the after_expansion \
165
+ or the after_analysis callback instead."]
163
166
fn after_crate_root_parsing<' tcx>(
164
167
& mut self ,
165
168
_compiler: & interface:: Compiler ,
@@ -181,7 +184,7 @@ pub trait Callbacks {
181
184
fn after_analysis<' tcx>(
182
185
& mut self ,
183
186
_compiler: & interface:: Compiler ,
184
- _queries : & ' tcx Queries <' tcx>,
187
+ _tcx : TyCtxt <' tcx>,
185
188
) -> Compilation {
186
189
Compilation :: Continue
187
190
}
@@ -335,19 +338,12 @@ fn run_compiler(
335
338
expanded_args: args,
336
339
} ;
337
340
338
- let has_input = match make_input( & default_early_dcx, & matches. free) {
339
- Err ( reported) => return Err ( reported) ,
340
- Ok ( Some ( input) ) => {
341
+ let has_input = match make_input( & default_early_dcx, & matches. free) ? {
342
+ Some ( input) => {
341
343
config. input = input;
342
344
true // has input: normal compilation
343
345
}
344
- Ok ( None ) => match matches. free. as_slice( ) {
345
- [ ] => false , // no input: we will exit early
346
- [ _] => panic!( "make_input should have provided valid inputs" ) ,
347
- [ fst, snd, ..] => default_early_dcx. early_fatal( format!(
348
- "multiple input filenames provided (first two filenames are `{fst}` and `{snd}`)"
349
- ) ) ,
350
- } ,
346
+ None => false , // no input: we will exit early
351
347
} ;
352
348
353
349
drop( default_early_dcx) ;
@@ -405,10 +401,6 @@ fn run_compiler(
405
401
queries. global_ctxt( ) ?. enter( |tcx| {
406
402
tcx. ensure( ) . early_lint_checks( ( ) ) ;
407
403
pretty:: print( sess, pp_mode, pretty:: PrintExtra :: NeedsAstMap { tcx } ) ;
408
- Ok ( ( ) )
409
- } ) ?;
410
-
411
- queries. global_ctxt( ) ?. enter( |tcx| {
412
404
passes:: write_dep_info( tcx) ;
413
405
} ) ;
414
406
} else {
@@ -421,6 +413,7 @@ fn run_compiler(
421
413
return early_exit( ) ;
422
414
}
423
415
416
+ #[ allow( deprecated) ]
424
417
if callbacks. after_crate_root_parsing( compiler, queries) == Compilation :: Stop {
425
418
return early_exit( ) ;
426
419
}
@@ -442,25 +435,23 @@ fn run_compiler(
442
435
443
436
queries. global_ctxt( ) ?. enter( |tcx| {
444
437
passes:: write_dep_info( tcx) ;
445
- } ) ;
446
438
447
- if sess. opts. output_types. contains_key( & OutputType :: DepInfo )
448
- && sess. opts. output_types. len( ) == 1
449
- {
450
- return early_exit( ) ;
451
- }
439
+ if sess. opts. output_types. contains_key( & OutputType :: DepInfo )
440
+ && sess. opts. output_types. len( ) == 1
441
+ {
442
+ return early_exit( ) ;
443
+ }
452
444
453
- if sess. opts. unstable_opts. no_analysis {
454
- return early_exit( ) ;
455
- }
445
+ if sess. opts. unstable_opts. no_analysis {
446
+ return early_exit( ) ;
447
+ }
456
448
457
- queries . global_ctxt ( ) ? . enter ( |tcx| tcx. analysis( ( ) ) ) ?;
449
+ tcx. analysis( ( ) ) ?;
458
450
459
- if callbacks. after_analysis( compiler, queries ) == Compilation :: Stop {
460
- return early_exit( ) ;
461
- }
451
+ if callbacks. after_analysis( compiler, tcx ) == Compilation :: Stop {
452
+ return early_exit( ) ;
453
+ }
462
454
463
- queries. global_ctxt( ) ?. enter( |tcx| {
464
455
Ok ( Some ( Linker :: codegen_and_build_linker( tcx, & * compiler. codegen_backend) ?) )
465
456
} )
466
457
} ) ?;
@@ -509,37 +500,40 @@ fn make_input(
509
500
early_dcx: & EarlyDiagCtxt ,
510
501
free_matches: & [ String ] ,
511
502
) -> Result <Option <Input >, ErrorGuaranteed > {
512
- let [ input_file] = free_matches else { return Ok ( None ) } ;
513
-
514
- if input_file != "-" {
515
- // Normal `Input::File`
516
- return Ok ( Some ( Input :: File ( PathBuf :: from( input_file) ) ) ) ;
517
- }
518
-
519
- // read from stdin as `Input::Str`
520
- let mut input = String :: new( ) ;
521
- if io:: stdin( ) . read_to_string( & mut input) . is_err( ) {
522
- // Immediately stop compilation if there was an issue reading
523
- // the input (for example if the input stream is not UTF-8).
524
- let reported =
525
- early_dcx. early_err( "couldn't read from stdin, as it did not contain valid UTF-8" ) ;
526
- return Err ( reported) ;
527
- }
503
+ match free_matches {
504
+ [ ] => Ok ( None ) , // no input: we will exit early,
505
+ [ ifile] if ifile == "-" => {
506
+ // read from stdin as `Input::Str`
507
+ let mut input = String :: new( ) ;
508
+ if io:: stdin( ) . read_to_string( & mut input) . is_err( ) {
509
+ // Immediately stop compilation if there was an issue reading
510
+ // the input (for example if the input stream is not UTF-8).
511
+ let reported = early_dcx
512
+ . early_err( "couldn't read from stdin, as it did not contain valid UTF-8" ) ;
513
+ return Err ( reported) ;
514
+ }
528
515
529
- let name = match env:: var( "UNSTABLE_RUSTDOC_TEST_PATH" ) {
530
- Ok ( path) => {
531
- let line = env:: var( "UNSTABLE_RUSTDOC_TEST_LINE" ) . expect(
532
- "when UNSTABLE_RUSTDOC_TEST_PATH is set \
516
+ let name = match env:: var( "UNSTABLE_RUSTDOC_TEST_PATH" ) {
517
+ Ok ( path) => {
518
+ let line = env:: var( "UNSTABLE_RUSTDOC_TEST_LINE" ) . expect(
519
+ "when UNSTABLE_RUSTDOC_TEST_PATH is set \
533
520
UNSTABLE_RUSTDOC_TEST_LINE also needs to be set",
534
- ) ;
535
- let line = isize :: from_str_radix( & line, 10 )
536
- . expect( "UNSTABLE_RUSTDOC_TEST_LINE needs to be an number" ) ;
537
- FileName :: doc_test_source_code( PathBuf :: from( path) , line)
538
- }
539
- Err ( _) => FileName :: anon_source_code( & input) ,
540
- } ;
521
+ ) ;
522
+ let line = isize :: from_str_radix( & line, 10 )
523
+ . expect( "UNSTABLE_RUSTDOC_TEST_LINE needs to be an number" ) ;
524
+ FileName :: doc_test_source_code( PathBuf :: from( path) , line)
525
+ }
526
+ Err ( _) => FileName :: anon_source_code( & input) ,
527
+ } ;
541
528
542
- Ok ( Some ( Input :: Str { name, input } ) )
529
+ Ok ( Some ( Input :: Str { name, input } ) )
530
+ }
531
+ [ ifile] => Ok ( Some ( Input :: File ( PathBuf :: from( ifile) ) ) ) ,
532
+ [ ifile1, ifile2, ..] => early_dcx. early_fatal( format!(
533
+ "multiple input filenames provided (first two filenames are `{}` and `{}`)" ,
534
+ ifile1, ifile2
535
+ ) ) ,
536
+ }
543
537
}
544
538
545
539
/// Whether to stop or continue compilation.
0 commit comments