Skip to content

Commit ca5dfd0

Browse files
committed
Allow CompilerControllers to access rustc_plugin::registry::Registry structure.
1 parent d128e6b commit ca5dfd0

File tree

5 files changed

+14
-9
lines changed

5 files changed

+14
-9
lines changed

src/librustc_driver/driver.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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> {
545549
pub 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 {

src/librustc_driver/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ fn test_env<F>(source_string: &str,
115115
let krate = driver::phase_1_parse_input(&sess, krate_config, &input).unwrap();
116116
let driver::ExpansionResult { defs, resolutions, mut hir_forest, .. } = {
117117
driver::phase_2_configure_and_expand(
118-
&sess, &cstore, krate, "test", None, MakeGlobMap::No, |_| Ok(()),
118+
&sess, &cstore, krate, None, "test", None, MakeGlobMap::No, |_| Ok(()),
119119
).expect("phase 2 aborted")
120120
};
121121
let _ignore = dep_graph.in_ignore();

src/librustc_plugin/registry.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@ pub struct Registry<'a> {
6969

7070
impl<'a> Registry<'a> {
7171
#[doc(hidden)]
72-
pub fn new(sess: &'a Session, krate: &ast::Crate) -> Registry<'a> {
72+
pub fn new(sess: &'a Session, krate_span: Span) -> Registry<'a> {
7373
Registry {
7474
sess: sess,
7575
args_hidden: None,
76-
krate_span: krate.span,
76+
krate_span: krate_span,
7777
syntax_exts: vec!(),
7878
early_lint_passes: vec!(),
7979
late_lint_passes: vec!(),

src/librustdoc/core.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ pub fn run_core(search_paths: SearchPaths,
146146

147147
let driver::ExpansionResult { defs, analysis, resolutions, mut hir_forest, .. } = {
148148
driver::phase_2_configure_and_expand(
149-
&sess, &cstore, krate, &name, None, resolve::MakeGlobMap::No, |_| Ok(()),
149+
&sess, &cstore, krate, None, &name, None, resolve::MakeGlobMap::No, |_| Ok(()),
150150
).expect("phase_2_configure_and_expand aborted in rustdoc!")
151151
};
152152

src/librustdoc/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ pub fn run(input: &str,
9494
let krate = panictry!(driver::phase_1_parse_input(&sess, cfg, &input));
9595
let driver::ExpansionResult { defs, mut hir_forest, .. } = {
9696
phase_2_configure_and_expand(
97-
&sess, &cstore, krate, "rustdoc-test", None, MakeGlobMap::No, |_| Ok(())
97+
&sess, &cstore, krate, None, "rustdoc-test", None, MakeGlobMap::No, |_| Ok(())
9898
).expect("phase_2_configure_and_expand aborted in rustdoc!")
9999
};
100100

0 commit comments

Comments
 (0)