Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a leak in DiagnosticBuilder::into_diagnostic. #69628

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
nnethercote marked this conversation as resolved.
Show resolved Hide resolved

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