Move DelayedBug handling into the match.

It results in a tiny bit of duplication (another
`self.treat_next_err_as_bug()` condition) but I think it's worth it to
get more code into the main `match`.
This commit is contained in:
Nicholas Nethercote 2024-02-13 13:08:24 +11:00
parent ecd3718bc0
commit 272e60bd3e

View File

@ -1377,35 +1377,40 @@ impl DiagCtxtInner {
self.future_breakage_diagnostics.push(diagnostic.clone()); self.future_breakage_diagnostics.push(diagnostic.clone());
} }
// Note that because this comes before the `match` below,
// `-Zeagerly-emit-delayed-bugs` continues to work even after we've
// issued an error and stopped recording new delayed bugs.
if diagnostic.level == DelayedBug && self.flags.eagerly_emit_delayed_bugs {
diagnostic.level = Error;
}
match diagnostic.level { match diagnostic.level {
// This must come after the possible promotion of `DelayedBug` to
// `Error` above.
Fatal | Error if self.treat_next_err_as_bug() => { Fatal | Error if self.treat_next_err_as_bug() => {
// `Fatal` and `Error` can be promoted to `Bug`.
diagnostic.level = Bug; diagnostic.level = Bug;
} }
DelayedBug => { DelayedBug => {
// If we have already emitted at least one error, we don't need // Note that because we check these conditions first,
// to record the delayed bug, because it'll never be used. // `-Zeagerly-emit-delayed-bugs` and `-Ztreat-err-as-bug`
return if let Some(guar) = self.has_errors() { // continue to work even after we've issued an error and
Some(guar) // stopped recording new delayed bugs.
if self.flags.eagerly_emit_delayed_bugs {
// `DelayedBug` can be promoted to `Error` or `Bug`.
if self.treat_next_err_as_bug() {
diagnostic.level = Bug;
} else {
diagnostic.level = Error;
}
} else { } else {
let backtrace = std::backtrace::Backtrace::capture(); // If we have already emitted at least one error, we don't need
// This `unchecked_error_guaranteed` is valid. It is where the // to record the delayed bug, because it'll never be used.
// `ErrorGuaranteed` for delayed bugs originates. See return if let Some(guar) = self.has_errors() {
// `DiagCtxtInner::drop`. Some(guar)
#[allow(deprecated)] } else {
let guar = ErrorGuaranteed::unchecked_error_guaranteed(); let backtrace = std::backtrace::Backtrace::capture();
self.delayed_bugs // This `unchecked_error_guaranteed` is valid. It is where the
.push((DelayedDiagInner::with_backtrace(diagnostic, backtrace), guar)); // `ErrorGuaranteed` for delayed bugs originates. See
Some(guar) // `DiagCtxtInner::drop`.
}; #[allow(deprecated)]
let guar = ErrorGuaranteed::unchecked_error_guaranteed();
self.delayed_bugs
.push((DelayedDiagInner::with_backtrace(diagnostic, backtrace), guar));
Some(guar)
};
}
} }
Warning if !self.flags.can_emit_warnings => { Warning if !self.flags.can_emit_warnings => {
if diagnostic.has_future_breakage() { if diagnostic.has_future_breakage() {