@@ -45,7 +45,7 @@ use rustc_errors::registry::Registry;
4545use  rustc_errors:: { ColorConfig ,  DiagCtxt ,  ErrCode ,  FatalError ,  PResult ,  markdown} ; 
4646use  rustc_feature:: find_gated_cfg; 
4747use  rustc_interface:: util:: { self ,  get_codegen_backend} ; 
48- use  rustc_interface:: { Linker ,  interface,  passes} ; 
48+ use  rustc_interface:: { Linker ,  create_and_enter_global_ctxt ,   interface,  passes} ; 
4949use  rustc_lint:: unerased_lint_store; 
5050use  rustc_metadata:: creader:: MetadataLoader ; 
5151use  rustc_metadata:: locator; 
@@ -387,76 +387,69 @@ fn run_compiler(
387387            return  early_exit( ) ; 
388388        } 
389389
390-         let  linker = compiler. enter( |queries| { 
390+         // Parse the crate root source code (doesn't parse submodules yet) 
391+         // Everything else is parsed during macro expansion. 
392+         let  krate = passes:: parse( sess) ; 
393+ 
394+         // If pretty printing is requested: Figure out the representation, print it and exit 
395+         if  let  Some ( pp_mode)  = sess. opts. pretty { 
396+             if  pp_mode. needs_ast_map( )  { 
397+                 create_and_enter_global_ctxt( compiler,  krate,  |tcx| { 
398+                     tcx. ensure( ) . early_lint_checks( ( ) ) ; 
399+                     pretty:: print( sess,  pp_mode,  pretty:: PrintExtra :: NeedsAstMap  {  tcx } ) ; 
400+                     passes:: write_dep_info( tcx) ; 
401+                 } ) ; 
402+             }  else { 
403+                 pretty:: print( sess,  pp_mode,  pretty:: PrintExtra :: AfterParsing  {  krate:  & krate } ) ; 
404+             } 
405+             trace!( "finished pretty-printing" ) ; 
406+             return  early_exit( ) ; 
407+         } 
408+ 
409+         if  callbacks. after_crate_root_parsing( compiler,  & krate)  == Compilation :: Stop  { 
410+             return  early_exit( ) ; 
411+         } 
412+ 
413+         if  sess. opts. unstable_opts. parse_crate_root_only { 
414+             return  early_exit( ) ; 
415+         } 
416+ 
417+         let  linker = create_and_enter_global_ctxt( compiler,  krate,  |tcx| { 
391418            let  early_exit = || { 
392419                sess. dcx( ) . abort_if_errors( ) ; 
393420                None 
394421            } ; 
395422
396-             // Parse the crate root source code (doesn't parse submodules yet) 
397-             // Everything else is parsed during macro expansion. 
398-             queries. parse( ) ; 
399- 
400-             // If pretty printing is requested: Figure out the representation, print it and exit 
401-             if  let  Some ( pp_mode)  = sess. opts. pretty { 
402-                 if  pp_mode. needs_ast_map( )  { 
403-                     queries. global_ctxt( ) . enter( |tcx| { 
404-                         tcx. ensure( ) . early_lint_checks( ( ) ) ; 
405-                         pretty:: print( sess,  pp_mode,  pretty:: PrintExtra :: NeedsAstMap  {  tcx } ) ; 
406-                         passes:: write_dep_info( tcx) ; 
407-                     } ) ; 
408-                 }  else { 
409-                     let  krate = queries. parse( ) ; 
410-                     pretty:: print( sess,  pp_mode,  pretty:: PrintExtra :: AfterParsing  { 
411-                         krate:  & * krate. borrow( ) , 
412-                     } ) ; 
413-                 } 
414-                 trace!( "finished pretty-printing" ) ; 
423+             // Make sure name resolution and macro expansion is run. 
424+             let  _ = tcx. resolver_for_lowering( ) ; 
425+ 
426+             if  let  Some ( metrics_dir)  = & sess. opts. unstable_opts. metrics_dir { 
427+                 dump_feature_usage_metrics( tcx,  metrics_dir) ; 
428+             } 
429+ 
430+             if  callbacks. after_expansion( compiler,  tcx)  == Compilation :: Stop  { 
415431                return  early_exit( ) ; 
416432            } 
417433
418-             if  callbacks. after_crate_root_parsing( compiler,  & * queries. parse( ) . borrow( ) ) 
419-                 == Compilation :: Stop 
434+             passes:: write_dep_info( tcx) ; 
435+ 
436+             if  sess. opts. output_types. contains_key( & OutputType :: DepInfo ) 
437+                 && sess. opts. output_types. len( )  == 1 
420438            { 
421439                return  early_exit( ) ; 
422440            } 
423441
424-             if  sess. opts. unstable_opts. parse_crate_root_only  { 
442+             if  sess. opts. unstable_opts. no_analysis  { 
425443                return  early_exit( ) ; 
426444            } 
427445
428-             queries. global_ctxt( ) . enter( |tcx| { 
429-                 // Make sure name resolution and macro expansion is run. 
430-                 let  _ = tcx. resolver_for_lowering( ) ; 
431- 
432-                 if  let  Some ( metrics_dir)  = & sess. opts. unstable_opts. metrics_dir { 
433-                     dump_feature_usage_metrics( tcx,  metrics_dir) ; 
434-                 } 
435- 
436-                 if  callbacks. after_expansion( compiler,  tcx)  == Compilation :: Stop  { 
437-                     return  early_exit( ) ; 
438-                 } 
439- 
440-                 passes:: write_dep_info( tcx) ; 
441- 
442-                 if  sess. opts. output_types. contains_key( & OutputType :: DepInfo ) 
443-                     && sess. opts. output_types. len( )  == 1 
444-                 { 
445-                     return  early_exit( ) ; 
446-                 } 
447- 
448-                 if  sess. opts. unstable_opts. no_analysis { 
449-                     return  early_exit( ) ; 
450-                 } 
446+             tcx. ensure( ) . analysis( ( ) ) ; 
451447
452-                 tcx. ensure( ) . analysis( ( ) ) ; 
453- 
454-                 if  callbacks. after_analysis( compiler,  tcx)  == Compilation :: Stop  { 
455-                     return  early_exit( ) ; 
456-                 } 
448+             if  callbacks. after_analysis( compiler,  tcx)  == Compilation :: Stop  { 
449+                 return  early_exit( ) ; 
450+             } 
457451
458-                 Some ( Linker :: codegen_and_build_linker( tcx,  & * compiler. codegen_backend) ) 
459-             } ) 
452+             Some ( Linker :: codegen_and_build_linker( tcx,  & * compiler. codegen_backend) ) 
460453        } ) ; 
461454
462455        // Linking is done outside the `compiler.enter()` so that the 
0 commit comments