]> git.lizzy.rs Git - rust.git/commitdiff
Store the gctxt instead of fetching it twice.
authorOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>
Thu, 19 Jan 2023 14:12:29 +0000 (14:12 +0000)
committerOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>
Mon, 23 Jan 2023 10:35:21 +0000 (10:35 +0000)
compiler/rustc_driver/src/lib.rs
compiler/rustc_interface/src/queries.rs
src/librustdoc/lib.rs

index 862931da00998295113ae80ba1ecc0c7a845eed7..ccefd6adaf14b6012a614e96368d46b83919a3ad 100644 (file)
@@ -327,12 +327,14 @@ fn run_compiler(
                 }
             }
 
-            queries.global_ctxt()?;
+            let mut gctxt = queries.global_ctxt()?;
             if callbacks.after_expansion(compiler, queries) == Compilation::Stop {
                 return early_exit();
             }
 
-            queries.global_ctxt()?.enter(|tcx| tcx.output_filenames(()));
+            // Make sure the `output_filenames` query is run for its side
+            // effects of writing the dep-info and reporting errors.
+            gctxt.enter(|tcx| tcx.output_filenames(()));
 
             if sess.opts.output_types.contains_key(&OutputType::DepInfo)
                 && sess.opts.output_types.len() == 1
@@ -344,7 +346,7 @@ fn run_compiler(
                 return early_exit();
             }
 
-            queries.global_ctxt()?.enter(|tcx| {
+            gctxt.enter(|tcx| {
                 let result = tcx.analysis(());
                 if sess.opts.unstable_opts.save_analysis {
                     let crate_name = tcx.crate_name(LOCAL_CRATE);
@@ -361,6 +363,8 @@ fn run_compiler(
                 result
             })?;
 
+            drop(gctxt);
+
             if callbacks.after_analysis(compiler, queries) == Compilation::Stop {
                 return early_exit();
             }
index 96cd3b06321ea94d406ed8142abd6f043a6707f7..4b0180741c19df0af11d84b6c6d388bc5b1ffc42 100644 (file)
@@ -65,7 +65,7 @@ fn deref_mut(&mut self) -> &mut Self::Target {
 }
 
 impl<'a, 'tcx> QueryResult<'a, QueryContext<'tcx>> {
-    pub fn enter<T>(mut self, f: impl FnOnce(TyCtxt<'tcx>) -> T) -> T {
+    pub fn enter<T>(&mut self, f: impl FnOnce(TyCtxt<'tcx>) -> T) -> T {
         (*self.0).get_mut().enter(f)
     }
 }
index 86454e1f2eb7316d239d4544c3adeec49e917e89..a689b502f0fccb1d3fe8fd81059c9dcecba64b90 100644 (file)
@@ -815,7 +815,7 @@ fn main_args(at_args: &[String]) -> MainResult {
                 sess.fatal("Compilation failed, aborting rustdoc");
             }
 
-            let global_ctxt = abort_on_err(queries.global_ctxt(), sess);
+            let mut global_ctxt = abort_on_err(queries.global_ctxt(), sess);
 
             global_ctxt.enter(|tcx| {
                 let (krate, render_opts, mut cache) = sess.time("run_global_ctxt", || {