Skip to content

Commit fff19a0

Browse files
nnethercoteMark-Simulacrum
authored andcommitted
Fix a leak in DiagnosticBuilder::into_diagnostic.
Fixes #69600.
1 parent 4e1c5f0 commit fff19a0

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

src/librustc_errors/diagnostic_builder.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,11 @@ impl<'a> DiagnosticBuilder<'a> {
132132

133133
let handler = self.0.handler;
134134

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

0 commit comments

Comments
 (0)