@@ -99,7 +99,7 @@ pub fn compile_input(sess: &Session,
9999 }
100100 } ;
101101
102- let krate = {
102+ let ( krate, registry ) = {
103103 let mut compile_state = CompileState :: state_after_parse ( input,
104104 sess,
105105 outdir,
@@ -111,14 +111,14 @@ pub fn compile_input(sess: &Session,
111111 compile_state,
112112 Ok ( ( ) ) ) ;
113113
114- compile_state. krate . unwrap ( )
114+ ( compile_state. krate . unwrap ( ) , compile_state . registry )
115115 } ;
116116
117117 let outputs = build_output_filenames ( input, outdir, output, & krate. attrs , sess) ;
118118 let crate_name = link:: find_crate_name ( Some ( sess) , & krate. attrs , input) ;
119119 let ExpansionResult { expanded_crate, defs, analysis, resolutions, mut hir_forest } = {
120120 phase_2_configure_and_expand (
121- sess, & cstore, krate, & crate_name, addl_plugins, control. make_glob_map ,
121+ sess, & cstore, krate, registry , & crate_name, addl_plugins, control. make_glob_map ,
122122 |expanded_crate| {
123123 let mut state = CompileState :: state_after_expand (
124124 input, sess, outdir, output, & cstore, expanded_crate, & crate_name,
@@ -332,6 +332,7 @@ pub struct CompileState<'a, 'b, 'ast: 'a, 'tcx: 'b> where 'ast: 'tcx {
332332 pub input : & ' a Input ,
333333 pub session : & ' ast Session ,
334334 pub krate : Option < ast:: Crate > ,
335+ pub registry : Option < Registry < ' a > > ,
335336 pub cstore : Option < & ' a CStore > ,
336337 pub crate_name : Option < & ' a str > ,
337338 pub output_filenames : Option < & ' a OutputFilenames > ,
@@ -360,6 +361,7 @@ impl<'a, 'b, 'ast, 'tcx> CompileState<'a, 'b, 'ast, 'tcx> {
360361 out_file : None ,
361362 arenas : None ,
362363 krate : None ,
364+ registry : None ,
363365 cstore : None ,
364366 crate_name : None ,
365367 output_filenames : None ,
@@ -382,6 +384,8 @@ impl<'a, 'b, 'ast, 'tcx> CompileState<'a, 'b, 'ast, 'tcx> {
382384 cstore : & ' a CStore )
383385 -> CompileState < ' a , ' b , ' ast , ' tcx > {
384386 CompileState {
387+ // Initialize the registry before moving `krate`
388+ registry : Some ( Registry :: new ( & session, krate. span ) ) ,
385389 krate : Some ( krate) ,
386390 cstore : Some ( cstore) ,
387391 out_file : out_file. as_ref ( ) . map ( |s| & * * s) ,
@@ -548,6 +552,7 @@ pub struct ExpansionResult<'a> {
548552pub fn phase_2_configure_and_expand < ' a , F > ( sess : & Session ,
549553 cstore : & CStore ,
550554 mut krate : ast:: Crate ,
555+ registry : Option < Registry > ,
551556 crate_name : & ' a str ,
552557 addl_plugins : Option < Vec < String > > ,
553558 make_glob_map : MakeGlobMap ,
@@ -595,7 +600,7 @@ pub fn phase_2_configure_and_expand<'a, F>(sess: &Session,
595600 addl_plugins. take ( ) . unwrap ( ) )
596601 } ) ;
597602
598- let mut registry = Registry :: new ( sess, & krate) ;
603+ let mut registry = registry . unwrap_or ( Registry :: new ( sess, krate. span ) ) ;
599604
600605 time ( time_passes, "plugin registration" , || {
601606 if sess. features . borrow ( ) . rustc_diagnostic_macros {
0 commit comments