mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
Rollup merge of #69628 - nnethercote:fix-DiagnosticBuilder-into_diagnostic-leak, r=Centril
Fix a leak in `DiagnosticBuilder::into_diagnostic`. Fixes #69600. r? @Centril
This commit is contained in:
@@ -136,12 +136,11 @@ pub fn into_diagnostic(mut self) -> Option<(Diagnostic, &'a Handler)> {
|
||||
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user