diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index f2da4ae71f5..4bea605125c 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -181,6 +181,7 @@ pub fn run_compiler( crate_name: None, lint_caps: Default::default(), register_lints: None, + override_queries: None, }; callbacks.config(&mut config); config @@ -259,6 +260,7 @@ pub fn run_compiler( crate_name: None, lint_caps: Default::default(), register_lints: None, + override_queries: None, }; callbacks.config(&mut config); diff --git a/src/librustc_interface/interface.rs b/src/librustc_interface/interface.rs index 02068b2ce38..fae4eb48c4a 100644 --- a/src/librustc_interface/interface.rs +++ b/src/librustc_interface/interface.rs @@ -12,6 +12,7 @@ use rustc_data_structures::OnDrop; use rustc_data_structures::sync::Lrc; use rustc_data_structures::fx::{FxHashSet, FxHashMap}; use rustc_parse::new_parser_from_source_str; +use rustc::ty; use std::path::PathBuf; use std::result; use std::sync::{Arc, Mutex}; @@ -38,6 +39,8 @@ pub struct Compiler { pub(crate) queries: Queries, pub(crate) crate_name: Option, pub(crate) register_lints: Option>, + pub(crate) override_queries: + Option, &mut ty::query::Providers<'_>)>, } impl Compiler { @@ -131,6 +134,13 @@ pub struct Config { /// Note that if you find a Some here you probably want to call that function in the new /// function being registered. pub register_lints: Option>, + + /// This is a callback from the driver that is called just after we have populated + /// the list of queries. + /// + /// The second parameter is local providers and the third parameter is external providers. + pub override_queries: + Option, &mut ty::query::Providers<'_>)>, } pub fn run_compiler_in_existing_thread_pool(config: Config, f: F) -> R @@ -157,6 +167,7 @@ where queries: Default::default(), crate_name: config.crate_name, register_lints: config.register_lints, + override_queries: config.override_queries, }; let _sess_abort_error = OnDrop(|| { diff --git a/src/librustc_interface/passes.rs b/src/librustc_interface/passes.rs index 453007c5642..c57622b8b8f 100644 --- a/src/librustc_interface/passes.rs +++ b/src/librustc_interface/passes.rs @@ -786,6 +786,7 @@ pub fn create_global_ctxt( let codegen_backend = compiler.codegen_backend().clone(); let crate_name = crate_name.to_string(); let defs = mem::take(&mut resolver_outputs.definitions); + let override_queries = compiler.override_queries; let ((), result) = BoxedGlobalCtxt::new(static move || { let sess = &*sess; @@ -810,6 +811,10 @@ pub fn create_global_ctxt( default_provide_extern(&mut extern_providers); codegen_backend.provide_extern(&mut extern_providers); + if let Some(callback) = override_queries { + callback(sess, &mut local_providers, &mut extern_providers); + } + let gcx = TyCtxt::create_global_ctxt( sess, lint_store, diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index b227f432a4e..3d8b7ece04b 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -335,6 +335,7 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt crate_name, lint_caps, register_lints: None, + override_queries: None, }; interface::run_compiler_in_existing_thread_pool(config, |compiler| { diff --git a/src/librustdoc/test.rs b/src/librustdoc/test.rs index 553ef6a9c47..04ee11dcf07 100644 --- a/src/librustdoc/test.rs +++ b/src/librustdoc/test.rs @@ -79,6 +79,7 @@ pub fn run(options: Options) -> i32 { crate_name: options.crate_name.clone(), lint_caps: Default::default(), register_lints: None, + override_queries: None, }; let mut test_args = options.test_args.clone(); diff --git a/src/test/run-make-fulldeps/issue-19371/foo.rs b/src/test/run-make-fulldeps/issue-19371/foo.rs index 9582137eae9..9f1850dfb4c 100644 --- a/src/test/run-make-fulldeps/issue-19371/foo.rs +++ b/src/test/run-make-fulldeps/issue-19371/foo.rs @@ -60,6 +60,7 @@ fn compile(code: String, output: PathBuf, sysroot: PathBuf) { crate_name: None, lint_caps: Default::default(), register_lints: None, + override_queries: None, }; interface::run_compiler(config, |compiler| {