diff --git a/src/librustc_driver/driver.rs b/src/librustc_driver/driver.rs index 94092be4922..35284a88bd3 100644 --- a/src/librustc_driver/driver.rs +++ b/src/librustc_driver/driver.rs @@ -97,7 +97,7 @@ macro_rules! controller_entry_point { } }; - let krate = { + let (krate, registry) = { let mut compile_state = CompileState::state_after_parse(input, sess, outdir, @@ -109,14 +109,14 @@ macro_rules! controller_entry_point { 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, @@ -329,6 +329,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>, @@ -357,6 +358,7 @@ fn empty(input: &'a Input, out_file: None, arenas: None, krate: None, + registry: None, cstore: None, crate_name: None, output_filenames: None, @@ -379,6 +381,8 @@ fn state_after_parse(input: &'a Input, 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), @@ -545,6 +549,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, @@ -592,7 +597,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 460a6e68a5c..2d04b8d1362 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 5ae6584aed4..6fa42e7bcd7 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 26f792a1fdf..0c236434cc7 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 beed1dc9f9e..e4dd41d7e4c 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!") };