Skip to content

Commit 261bbd7

Browse files
committed
Store the gctxt instead of fetching it twice.
1 parent 3ddb54f commit 261bbd7

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

compiler/rustc_driver/src/lib.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -327,12 +327,14 @@ fn run_compiler(
327327
}
328328
}
329329

330-
queries.global_ctxt()?;
330+
let mut gctxt = queries.global_ctxt()?;
331331
if callbacks.after_expansion(compiler, queries) == Compilation::Stop {
332332
return early_exit();
333333
}
334334

335-
queries.global_ctxt()?.enter(|tcx| tcx.output_filenames(()));
335+
// Make sure the `output_filenames` query is run for its side
336+
// effects of writing the dep-info and reporting errors.
337+
gctxt.enter(|tcx| tcx.output_filenames(()));
336338

337339
if sess.opts.output_types.contains_key(&OutputType::DepInfo)
338340
&& sess.opts.output_types.len() == 1
@@ -344,7 +346,7 @@ fn run_compiler(
344346
return early_exit();
345347
}
346348

347-
queries.global_ctxt()?.enter(|tcx| {
349+
gctxt.enter(|tcx| {
348350
let result = tcx.analysis(());
349351
if sess.opts.unstable_opts.save_analysis {
350352
let crate_name = tcx.crate_name(LOCAL_CRATE);
@@ -361,6 +363,8 @@ fn run_compiler(
361363
result
362364
})?;
363365

366+
drop(gctxt);
367+
364368
if callbacks.after_analysis(compiler, queries) == Compilation::Stop {
365369
return early_exit();
366370
}

compiler/rustc_interface/src/queries.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ impl<'a, T> std::ops::DerefMut for QueryResult<'a, T> {
6565
}
6666

6767
impl<'a, 'tcx> QueryResult<'a, QueryContext<'tcx>> {
68-
pub fn enter<T>(mut self, f: impl FnOnce(TyCtxt<'tcx>) -> T) -> T {
68+
pub fn enter<T>(&mut self, f: impl FnOnce(TyCtxt<'tcx>) -> T) -> T {
6969
(*self.0).get_mut().enter(f)
7070
}
7171
}

src/librustdoc/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -815,7 +815,7 @@ fn main_args(at_args: &[String]) -> MainResult {
815815
sess.fatal("Compilation failed, aborting rustdoc");
816816
}
817817

818-
let global_ctxt = abort_on_err(queries.global_ctxt(), sess);
818+
let mut global_ctxt = abort_on_err(queries.global_ctxt(), sess);
819819

820820
global_ctxt.enter(|tcx| {
821821
let (krate, render_opts, mut cache) = sess.time("run_global_ctxt", || {

0 commit comments

Comments
 (0)