Skip to content

Commit 6d37bb6

Browse files
committed
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`.
1 parent 78b328d commit 6d37bb6

File tree

1 file changed

+27
-22
lines changed
  • compiler/rustc_errors/src

1 file changed

+27
-22
lines changed

compiler/rustc_errors/src/lib.rs

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,34 +1321,39 @@ impl DiagCtxtInner {
13211321
self.future_breakage_diagnostics.push(diagnostic.clone());
13221322
}
13231323

1324-
// Note that because this comes before the `match` below,
1325-
// `-Zeagerly-emit-delayed-bugs` continues to work even after we've
1326-
// issued an error and stopped recording new delayed bugs.
1327-
if diagnostic.level == DelayedBug && self.flags.eagerly_emit_delayed_bugs {
1328-
diagnostic.level = Error;
1329-
}
1330-
13311324
match diagnostic.level {
1332-
// This must come after the possible promotion of `DelayedBug` to
1333-
// `Error` above.
13341325
Fatal | Error if self.treat_next_err_as_bug() => {
1326+
// `Fatal` and `Error` can be promoted to `Bug`.
13351327
diagnostic.level = Bug;
13361328
}
13371329
DelayedBug => {
1338-
// If we have already emitted at least one error, we don't need
1339-
// to record the delayed bug, because it'll never be used.
1340-
return if let Some(guar) = self.has_errors_or_lint_errors() {
1341-
Some(guar)
1330+
// Note that because we check these conditions first,
1331+
// `-Zeagerly-emit-delayed-bugs` and `-Ztreat-err-as-bug`
1332+
// continue to work even after we've issued an error and
1333+
// stopped recording new delayed bugs.
1334+
if self.flags.eagerly_emit_delayed_bugs {
1335+
// `DelayedBug` can be promoted to `Error` or `Bug`.
1336+
if self.treat_next_err_as_bug() {
1337+
diagnostic.level = Bug;
1338+
} else {
1339+
diagnostic.level = Error;
1340+
}
13421341
} else {
1343-
let backtrace = std::backtrace::Backtrace::capture();
1344-
// This `unchecked_error_guaranteed` is valid. It is where the
1345-
// `ErrorGuaranteed` for delayed bugs originates.
1346-
#[allow(deprecated)]
1347-
let guar = ErrorGuaranteed::unchecked_error_guaranteed();
1348-
self.delayed_bugs
1349-
.push((DelayedDiagnostic::with_backtrace(diagnostic, backtrace), guar));
1350-
Some(guar)
1351-
};
1342+
// If we have already emitted at least one error, we don't need
1343+
// to record the delayed bug, because it'll never be used.
1344+
return if let Some(guar) = self.has_errors_or_lint_errors() {
1345+
Some(guar)
1346+
} else {
1347+
let backtrace = std::backtrace::Backtrace::capture();
1348+
// This `unchecked_error_guaranteed` is valid. It is where the
1349+
// `ErrorGuaranteed` for delayed bugs originates.
1350+
#[allow(deprecated)]
1351+
let guar = ErrorGuaranteed::unchecked_error_guaranteed();
1352+
self.delayed_bugs
1353+
.push((DelayedDiagnostic::with_backtrace(diagnostic, backtrace), guar));
1354+
Some(guar)
1355+
};
1356+
}
13521357
}
13531358
Warning if !self.flags.can_emit_warnings => {
13541359
if diagnostic.has_future_breakage() {

0 commit comments

Comments
 (0)