@@ -97,7 +97,7 @@ pub fn compile_input(sess: &Session,
9797 }
9898 } ;
9999
100- let krate = {
100+ let ( krate, registry ) = {
101101 let mut compile_state = CompileState :: state_after_parse ( input,
102102 sess,
103103 outdir,
@@ -109,14 +109,14 @@ pub fn compile_input(sess: &Session,
109109 compile_state,
110110 Ok ( ( ) ) ) ;
111111
112- compile_state. krate . unwrap ( )
112+ ( compile_state. krate . unwrap ( ) , compile_state . registry )
113113 } ;
114114
115115 let outputs = build_output_filenames ( input, outdir, output, & krate. attrs , sess) ;
116116 let crate_name = link:: find_crate_name ( Some ( sess) , & krate. attrs , input) ;
117117 let ExpansionResult { expanded_crate, defs, analysis, resolutions, mut hir_forest } = {
118118 phase_2_configure_and_expand (
119- sess, & cstore, krate, & crate_name, addl_plugins, control. make_glob_map ,
119+ sess, & cstore, krate, registry , & crate_name, addl_plugins, control. make_glob_map ,
120120 |expanded_crate| {
121121 let mut state = CompileState :: state_after_expand (
122122 input, sess, outdir, output, & cstore, expanded_crate, & crate_name,
@@ -329,6 +329,7 @@ pub struct CompileState<'a, 'b, 'ast: 'a, 'tcx: 'b> where 'ast: 'tcx {
329329 pub input : & ' a Input ,
330330 pub session : & ' ast Session ,
331331 pub krate : Option < ast:: Crate > ,
332+ pub registry : Option < Registry < ' a > > ,
332333 pub cstore : Option < & ' a CStore > ,
333334 pub crate_name : Option < & ' a str > ,
334335 pub output_filenames : Option < & ' a OutputFilenames > ,
@@ -357,6 +358,7 @@ impl<'a, 'b, 'ast, 'tcx> CompileState<'a, 'b, 'ast, 'tcx> {
357358 out_file : None ,
358359 arenas : None ,
359360 krate : None ,
361+ registry : None ,
360362 cstore : None ,
361363 crate_name : None ,
362364 output_filenames : None ,
@@ -379,6 +381,8 @@ impl<'a, 'b, 'ast, 'tcx> CompileState<'a, 'b, 'ast, 'tcx> {
379381 cstore : & ' a CStore )
380382 -> CompileState < ' a , ' b , ' ast , ' tcx > {
381383 CompileState {
384+ // Initialize the registry before moving `krate`
385+ registry : Some ( Registry :: new ( & session, krate. span ) ) ,
382386 krate : Some ( krate) ,
383387 cstore : Some ( cstore) ,
384388 out_file : out_file. as_ref ( ) . map ( |s| & * * s) ,
@@ -545,6 +549,7 @@ pub struct ExpansionResult<'a> {
545549pub fn phase_2_configure_and_expand < ' a , F > ( sess : & Session ,
546550 cstore : & CStore ,
547551 mut krate : ast:: Crate ,
552+ registry : Option < Registry > ,
548553 crate_name : & ' a str ,
549554 addl_plugins : Option < Vec < String > > ,
550555 make_glob_map : MakeGlobMap ,
@@ -592,7 +597,7 @@ pub fn phase_2_configure_and_expand<'a, F>(sess: &Session,
592597 addl_plugins. take ( ) . unwrap ( ) )
593598 } ) ;
594599
595- let mut registry = Registry :: new ( sess, & krate) ;
600+ let mut registry = registry . unwrap_or ( Registry :: new ( sess, krate. span ) ) ;
596601
597602 time ( time_passes, "plugin registration" , || {
598603 if sess. features . borrow ( ) . rustc_diagnostic_macros {
0 commit comments