Skip to content

Commit bb9c204

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 acb90ee commit bb9c204

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
@@ -1324,34 +1324,39 @@ impl DiagCtxtInner {
13241324
self.future_breakage_diagnostics.push(diagnostic.clone());
13251325
}
13261326

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

0 commit comments

Comments
 (0)