diff --git a/src/librustc_driver/driver.rs b/src/librustc_driver/driver.rs index e059b6445c12..065ef9e0ce15 100644 --- a/src/librustc_driver/driver.rs +++ b/src/librustc_driver/driver.rs @@ -99,7 +99,7 @@ pub fn compile_input(sess: &Session, } }; - let krate = { + let (krate, registry) = { let mut compile_state = CompileState::state_after_parse(input, sess, outdir, @@ -111,14 +111,14 @@ pub fn compile_input(sess: &Session, compile_state, Ok(())); - compile_state.krate.unwrap() + (compile_state.krate.unwrap(), compile_state.registry) }; let outputs = build_output_filenames(input, outdir, output, &krate.attrs, sess); let crate_name = link::find_crate_name(Some(sess), &krate.attrs, input); let ExpansionResult { expanded_crate, defs, analysis, resolutions, mut hir_forest } = { phase_2_configure_and_expand( - sess, &cstore, krate, &crate_name, addl_plugins, control.make_glob_map, + sess, &cstore, krate, registry, &crate_name, addl_plugins, control.make_glob_map, |expanded_crate| { let mut state = CompileState::state_after_expand( 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 { pub input: &'a Input, pub session: &'ast Session, pub krate: Option, + pub registry: Option>, pub cstore: Option<&'a CStore>, pub crate_name: Option<&'a str>, pub output_filenames: Option<&'a OutputFilenames>, @@ -360,6 +361,7 @@ impl<'a, 'b, 'ast, 'tcx> CompileState<'a, 'b, 'ast, 'tcx> { out_file: None, arenas: None, krate: None, + registry: None, cstore: None, crate_name: None, output_filenames: None, @@ -382,6 +384,8 @@ impl<'a, 'b, 'ast, 'tcx> CompileState<'a, 'b, 'ast, 'tcx> { cstore: &'a CStore) -> CompileState<'a, 'b, 'ast, 'tcx> { CompileState { + // Initialize the registry before moving `krate` + registry: Some(Registry::new(&session, krate.span)), krate: Some(krate), cstore: Some(cstore), out_file: out_file.as_ref().map(|s| &**s), @@ -548,6 +552,7 @@ pub struct ExpansionResult<'a> { pub fn phase_2_configure_and_expand<'a, F>(sess: &Session, cstore: &CStore, mut krate: ast::Crate, + registry: Option, crate_name: &'a str, addl_plugins: Option>, make_glob_map: MakeGlobMap, @@ -595,7 +600,7 @@ pub fn phase_2_configure_and_expand<'a, F>(sess: &Session, addl_plugins.take().unwrap()) }); - let mut registry = Registry::new(sess, &krate); + let mut registry = registry.unwrap_or(Registry::new(sess, krate.span)); time(time_passes, "plugin registration", || { if sess.features.borrow().rustc_diagnostic_macros { diff --git a/src/librustc_driver/test.rs b/src/librustc_driver/test.rs index 9f5f82c144cc..8569ff64f910 100644 --- a/src/librustc_driver/test.rs +++ b/src/librustc_driver/test.rs @@ -115,7 +115,7 @@ fn test_env(source_string: &str, let krate = driver::phase_1_parse_input(&sess, krate_config, &input).unwrap(); let driver::ExpansionResult { defs, resolutions, mut hir_forest, .. } = { driver::phase_2_configure_and_expand( - &sess, &cstore, krate, "test", None, MakeGlobMap::No, |_| Ok(()), + &sess, &cstore, krate, None, "test", None, MakeGlobMap::No, |_| Ok(()), ).expect("phase 2 aborted") }; let _ignore = dep_graph.in_ignore(); diff --git a/src/librustc_plugin/registry.rs b/src/librustc_plugin/registry.rs index 6db821b2cd8d..435196d95618 100644 --- a/src/librustc_plugin/registry.rs +++ b/src/librustc_plugin/registry.rs @@ -69,11 +69,11 @@ pub struct Registry<'a> { impl<'a> Registry<'a> { #[doc(hidden)] - pub fn new(sess: &'a Session, krate: &ast::Crate) -> Registry<'a> { + pub fn new(sess: &'a Session, krate_span: Span) -> Registry<'a> { Registry { sess: sess, args_hidden: None, - krate_span: krate.span, + krate_span: krate_span, syntax_exts: vec!(), early_lint_passes: vec!(), late_lint_passes: vec!(), diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index 26f792a1fdf9..0c236434cc70 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -146,7 +146,7 @@ pub fn run_core(search_paths: SearchPaths, let driver::ExpansionResult { defs, analysis, resolutions, mut hir_forest, .. } = { driver::phase_2_configure_and_expand( - &sess, &cstore, krate, &name, None, resolve::MakeGlobMap::No, |_| Ok(()), + &sess, &cstore, krate, None, &name, None, resolve::MakeGlobMap::No, |_| Ok(()), ).expect("phase_2_configure_and_expand aborted in rustdoc!") }; diff --git a/src/librustdoc/test.rs b/src/librustdoc/test.rs index beed1dc9f9e7..e4dd41d7e4c3 100644 --- a/src/librustdoc/test.rs +++ b/src/librustdoc/test.rs @@ -94,7 +94,7 @@ pub fn run(input: &str, let krate = panictry!(driver::phase_1_parse_input(&sess, cfg, &input)); let driver::ExpansionResult { defs, mut hir_forest, .. } = { phase_2_configure_and_expand( - &sess, &cstore, krate, "rustdoc-test", None, MakeGlobMap::No, |_| Ok(()) + &sess, &cstore, krate, None, "rustdoc-test", None, MakeGlobMap::No, |_| Ok(()) ).expect("phase_2_configure_and_expand aborted in rustdoc!") };