Skip to content

Commit 1c86e47

Browse files
committed
Drop expanded AST later if in save_analysis mode
1 parent 913ad6d commit 1c86e47

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/librustc_driver/lib.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -342,14 +342,12 @@ pub fn run_compiler(
342342
}
343343

344344
if sess.opts.debugging_opts.save_analysis {
345-
let expanded_crate = compiler.expansion()?.take().0;
346-
345+
let expanded_crate = &compiler.expansion()?.peek().0;
347346
let crate_name = compiler.crate_name()?.peek().clone();
348347
compiler.global_ctxt()?.peek_mut().enter(|tcx| {
349348
let result = tcx.analysis(LOCAL_CRATE);
350349

351350
time(sess, "save analysis", || {
352-
// FIXME: Should this run even with analysis errors?
353351
save::process_crate(
354352
tcx,
355353
&expanded_crate,
@@ -361,17 +359,24 @@ pub fn run_compiler(
361359
});
362360

363361
result
362+
// AST will be dropped *after* the `after_analysis` callback
363+
// (needed by the RLS)
364364
})?;
365365
} else {
366366
// Drop AST after creating GlobalCtxt to free memory
367367
mem::drop(compiler.expansion()?.take());
368368
}
369+
369370
compiler.global_ctxt()?.peek_mut().enter(|tcx| tcx.analysis(LOCAL_CRATE))?;
370371

371372
if !callbacks.after_analysis(compiler) {
372373
return sess.compile_status();
373374
}
374375

376+
if sess.opts.debugging_opts.save_analysis {
377+
mem::drop(compiler.expansion()?.take());
378+
}
379+
375380
compiler.ongoing_codegen()?;
376381

377382
// Drop GlobalCtxt after starting codegen to free memory

0 commit comments

Comments
 (0)