Skip to content

Commit c943ec2

Browse files
authored
Rollup merge of rust-lang#115730 - bjorn3:some_driver_refactors, r=compiler-errors
Some more small driver refactors To improve clarity and simplify some code.
2 parents 279e257 + 2eca717 commit c943ec2

File tree

5 files changed

+10
-11
lines changed

5 files changed

+10
-11
lines changed

compiler/rustc_driver_impl/src/lib.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,10 @@ pub fn abort_on_err<T>(result: Result<T, ErrorGuaranteed>, sess: &Session) -> T
162162
pub trait Callbacks {
163163
/// Called before creating the compiler instance
164164
fn config(&mut self, _config: &mut interface::Config) {}
165-
/// Called after parsing. Return value instructs the compiler whether to
165+
/// Called after parsing the crate root. Submodules are not yet parsed when
166+
/// this callback is called. Return value instructs the compiler whether to
166167
/// continue the compilation afterwards (defaults to `Compilation::Continue`)
167-
fn after_parsing<'tcx>(
168+
fn after_crate_root_parsing<'tcx>(
168169
&mut self,
169170
_compiler: &interface::Compiler,
170171
_queries: &'tcx Queries<'tcx>,
@@ -184,7 +185,6 @@ pub trait Callbacks {
184185
/// continue the compilation afterwards (defaults to `Compilation::Continue`)
185186
fn after_analysis<'tcx>(
186187
&mut self,
187-
_handler: &EarlyErrorHandler,
188188
_compiler: &interface::Compiler,
189189
_queries: &'tcx Queries<'tcx>,
190190
) -> Compilation {
@@ -407,7 +407,7 @@ fn run_compiler(
407407
return early_exit();
408408
}
409409

410-
if callbacks.after_parsing(compiler, queries) == Compilation::Stop {
410+
if callbacks.after_crate_root_parsing(compiler, queries) == Compilation::Stop {
411411
return early_exit();
412412
}
413413

@@ -445,7 +445,7 @@ fn run_compiler(
445445

446446
queries.global_ctxt()?.enter(|tcx| tcx.analysis(()))?;
447447

448-
if callbacks.after_analysis(&handler, compiler, queries) == Compilation::Stop {
448+
if callbacks.after_analysis(compiler, queries) == Compilation::Stop {
449449
return early_exit();
450450
}
451451

compiler/rustc_interface/src/queries.rs

+2
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ impl<'tcx> Queries<'tcx> {
114114
.compute(|| passes::parse(self.session()).map_err(|mut parse_error| parse_error.emit()))
115115
}
116116

117+
#[deprecated = "pre_configure may be made private in the future. If you need it please open an issue with your use case."]
117118
pub fn pre_configure(&self) -> Result<QueryResult<'_, (ast::Crate, ast::AttrVec)>> {
118119
self.pre_configure.compute(|| {
119120
let mut krate = self.parse()?.steal();
@@ -171,6 +172,7 @@ impl<'tcx> Queries<'tcx> {
171172
pub fn global_ctxt(&'tcx self) -> Result<QueryResult<'_, &'tcx GlobalCtxt<'tcx>>> {
172173
self.gcx.compute(|| {
173174
let sess = self.session();
175+
#[allow(deprecated)]
174176
let (krate, pre_configured_attrs) = self.pre_configure()?.steal();
175177

176178
// parse `#[crate_name]` even if `--crate-name` was passed, to make sure it matches.

compiler/rustc_smir/src/rustc_internal/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use rustc_driver::{Callbacks, Compilation, RunCompiler};
1616
use rustc_interface::{interface, Queries};
1717
use rustc_middle::mir::interpret::AllocId;
1818
use rustc_middle::ty::TyCtxt;
19-
use rustc_session::EarlyErrorHandler;
2019
pub use rustc_span::def_id::{CrateNum, DefId};
2120

2221
fn with_tables<R>(mut f: impl FnMut(&mut Tables<'_>) -> R) -> R {
@@ -233,7 +232,6 @@ where
233232
/// continue the compilation afterwards (defaults to `Compilation::Continue`)
234233
fn after_analysis<'tcx>(
235234
&mut self,
236-
_handler: &EarlyErrorHandler,
237235
_compiler: &interface::Compiler,
238236
queries: &'tcx Queries<'tcx>,
239237
) -> Compilation {

src/tools/miri/src/bin/miri.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ impl rustc_driver::Callbacks for MiriCompilerCalls {
5959

6060
fn after_analysis<'tcx>(
6161
&mut self,
62-
handler: &EarlyErrorHandler,
6362
_: &rustc_interface::interface::Compiler,
6463
queries: &'tcx rustc_interface::Queries<'tcx>,
6564
) -> Compilation {
@@ -68,7 +67,8 @@ impl rustc_driver::Callbacks for MiriCompilerCalls {
6867
tcx.sess.fatal("miri cannot be run on programs that fail compilation");
6968
}
7069

71-
init_late_loggers(handler, tcx);
70+
let handler = EarlyErrorHandler::new(tcx.sess.opts.error_format);
71+
init_late_loggers(&handler, tcx);
7272
if !tcx.crate_types().contains(&CrateType::Executable) {
7373
tcx.sess.fatal("miri only makes sense on bin crates");
7474
}

tests/run-make-fulldeps/obtain-borrowck/driver.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use rustc_interface::{Config, Queries};
2727
use rustc_middle::query::queries::mir_borrowck::ProvidedValue;
2828
use rustc_middle::query::{ExternProviders, Providers};
2929
use rustc_middle::ty::TyCtxt;
30-
use rustc_session::{Session, EarlyErrorHandler};
30+
use rustc_session::Session;
3131
use std::cell::RefCell;
3232
use std::collections::HashMap;
3333
use std::thread_local;
@@ -58,7 +58,6 @@ impl rustc_driver::Callbacks for CompilerCalls {
5858
// the result.
5959
fn after_analysis<'tcx>(
6060
&mut self,
61-
_handler: &EarlyErrorHandler,
6261
compiler: &Compiler,
6362
queries: &'tcx Queries<'tcx>,
6463
) -> Compilation {

0 commit comments

Comments
 (0)