about summary refs log tree commit diff
path: root/src/librustc_driver
diff options
context:
space:
mode:
authorIgor Matuszewski <Xanewok@gmail.com>2019-03-10 17:03:05 +0100
committerIgor Matuszewski <Xanewok@gmail.com>2019-03-10 17:03:05 +0100
commit1c86e475ca4ea7b2ed134d5d0bce66fde597d528 (patch)
treea044090fe24b33a2b485565d8584fe5cbe46f182 /src/librustc_driver
parent913ad6d1f092c70049934ba538d342d295d35997 (diff)
downloadrust-1c86e475ca4ea7b2ed134d5d0bce66fde597d528.tar.gz
rust-1c86e475ca4ea7b2ed134d5d0bce66fde597d528.zip
Drop expanded AST later if in save_analysis mode
Diffstat (limited to 'src/librustc_driver')
-rw-r--r--src/librustc_driver/lib.rs11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs
index 2b75a607f16..c7b6f37fe29 100644
--- a/src/librustc_driver/lib.rs
+++ b/src/librustc_driver/lib.rs
@@ -342,14 +342,12 @@ pub fn run_compiler(
         }
 
         if sess.opts.debugging_opts.save_analysis {
-            let expanded_crate = compiler.expansion()?.take().0;
-
+            let expanded_crate = &compiler.expansion()?.peek().0;
             let crate_name = compiler.crate_name()?.peek().clone();
             compiler.global_ctxt()?.peek_mut().enter(|tcx| {
                 let result = tcx.analysis(LOCAL_CRATE);
 
                 time(sess, "save analysis", || {
-                    // FIXME: Should this run even with analysis errors?
                     save::process_crate(
                         tcx,
                         &expanded_crate,
@@ -361,17 +359,24 @@ pub fn run_compiler(
                 });
 
                 result
+                // AST will be dropped *after* the `after_analysis` callback
+                // (needed by the RLS)
             })?;
         } else {
             // Drop AST after creating GlobalCtxt to free memory
             mem::drop(compiler.expansion()?.take());
         }
+
         compiler.global_ctxt()?.peek_mut().enter(|tcx| tcx.analysis(LOCAL_CRATE))?;
 
         if !callbacks.after_analysis(compiler) {
             return sess.compile_status();
         }
 
+        if sess.opts.debugging_opts.save_analysis {
+            mem::drop(compiler.expansion()?.take());
+        }
+
         compiler.ongoing_codegen()?;
 
         // Drop GlobalCtxt after starting codegen to free memory