@@ -160,6 +160,9 @@ pub trait Callbacks {
160160 /// Called after parsing the crate root. Submodules are not yet parsed when
161161 /// this callback is called. Return value instructs the compiler whether to
162162 /// 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."]
163166 fn after_crate_root_parsing<' tcx>(
164167 & mut self ,
165168 _compiler: & interface:: Compiler ,
@@ -181,7 +184,7 @@ pub trait Callbacks {
181184 fn after_analysis<' tcx>(
182185 & mut self ,
183186 _compiler: & interface:: Compiler ,
184- _queries : & ' tcx Queries <' tcx>,
187+ _tcx : TyCtxt <' tcx>,
185188 ) -> Compilation {
186189 Compilation :: Continue
187190 }
@@ -335,19 +338,12 @@ fn run_compiler(
335338 expanded_args: args,
336339 } ;
337340
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) => {
341343 config. input = input;
342344 true // has input: normal compilation
343345 }
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
351347 } ;
352348
353349 drop( default_early_dcx) ;
@@ -405,10 +401,6 @@ fn run_compiler(
405401 queries. global_ctxt( ) ?. enter( |tcx| {
406402 tcx. ensure( ) . early_lint_checks( ( ) ) ;
407403 pretty:: print( sess, pp_mode, pretty:: PrintExtra :: NeedsAstMap { tcx } ) ;
408- Ok ( ( ) )
409- } ) ?;
410-
411- queries. global_ctxt( ) ?. enter( |tcx| {
412404 passes:: write_dep_info( tcx) ;
413405 } ) ;
414406 } else {
@@ -421,6 +413,7 @@ fn run_compiler(
421413 return early_exit( ) ;
422414 }
423415
416+ #[ allow( deprecated) ]
424417 if callbacks. after_crate_root_parsing( compiler, queries) == Compilation :: Stop {
425418 return early_exit( ) ;
426419 }
@@ -442,25 +435,23 @@ fn run_compiler(
442435
443436 queries. global_ctxt( ) ?. enter( |tcx| {
444437 passes:: write_dep_info( tcx) ;
445- } ) ;
446438
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+ }
452444
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+ }
456448
457- queries . global_ctxt ( ) ? . enter ( |tcx| tcx. analysis( ( ) ) ) ?;
449+ tcx. analysis( ( ) ) ?;
458450
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+ }
462454
463- queries. global_ctxt( ) ?. enter( |tcx| {
464455 Ok ( Some ( Linker :: codegen_and_build_linker( tcx, & * compiler. codegen_backend) ?) )
465456 } )
466457 } ) ?;
@@ -509,37 +500,40 @@ fn make_input(
509500 early_dcx: & EarlyDiagCtxt ,
510501 free_matches: & [ String ] ,
511502) -> 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+ }
528515
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 \
533520 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+ } ;
541528
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+ }
543537}
544538
545539/// Whether to stop or continue compilation.
0 commit comments