Skip to content

Commit

Permalink
Rollup merge of rust-lang#69628 - nnethercote:fix-DiagnosticBuilder-i…
Browse files Browse the repository at this point in the history
…nto_diagnostic-leak, r=Centril

Fix a leak in `DiagnosticBuilder::into_diagnostic`.

Fixes rust-lang#69600.

r? @Centril
  • Loading branch information
JohnTitor authored Mar 3, 2020
2 parents c9d421f + 99a595e commit ef311d5
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/librustc_errors/diagnostic_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,11 @@ impl<'a> DiagnosticBuilder<'a> {

let handler = self.0.handler;

// We need to use `ptr::read` because `DiagnosticBuilder` implements `Drop`.
let diagnostic;
unsafe {
diagnostic = std::ptr::read(&self.0.diagnostic);
std::mem::forget(self);
};
// We must use `Level::Cancelled` for `dummy` to avoid an ICE about an
// unused diagnostic.
let dummy = Diagnostic::new(Level::Cancelled, "");
let diagnostic = std::mem::replace(&mut self.0.diagnostic, dummy);

// Logging here is useful to help track down where in logs an error was
// actually emitted.
debug!("buffer: diagnostic={:?}", diagnostic);
Expand Down

0 comments on commit ef311d5

Please sign in to comment.