Skip to content

Commit 017a682

Browse files
committed
Auto merge of #69628 - nnethercote:fix-DiagnosticBuilder-into_diagnostic-leak, r=<try>
Fix a leak in `DiagnosticBuilder::into_diagnostic`. Fixes #69600. r? @Centril
2 parents 9dc8dad + 99a595e commit 017a682

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

src/librustc_errors/diagnostic_builder.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,11 @@ impl<'a> DiagnosticBuilder<'a> {
136136

137137
let handler = self.0.handler;
138138

139-
// We need to use `ptr::read` because `DiagnosticBuilder` implements `Drop`.
140-
let diagnostic;
141-
unsafe {
142-
diagnostic = std::ptr::read(&self.0.diagnostic);
143-
std::mem::forget(self);
144-
};
139+
// We must use `Level::Cancelled` for `dummy` to avoid an ICE about an
140+
// unused diagnostic.
141+
let dummy = Diagnostic::new(Level::Cancelled, "");
142+
let diagnostic = std::mem::replace(&mut self.0.diagnostic, dummy);
143+
145144
// Logging here is useful to help track down where in logs an error was
146145
// actually emitted.
147146
debug!("buffer: diagnostic={:?}", diagnostic);

0 commit comments

Comments
 (0)