Skip to content

Commit eed398c

Browse files
committed
Tweak flush_delayed.
- Do an early return for the "no bugs" case. - Use `enumerate` and an `i == 0` test to identify the first bug. Those changes mean the `no_bug` variable can be removed, which I found hard to read.
1 parent be3fa9c commit eed398c

File tree

1 file changed

+11
-10
lines changed
  • compiler/rustc_errors/src

1 file changed

+11
-10
lines changed

compiler/rustc_errors/src/lib.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1530,13 +1530,16 @@ impl DiagCtxtInner {
15301530

15311531
fn flush_delayed(
15321532
&mut self,
1533-
bugs: impl IntoIterator<Item = DelayedDiagnostic>,
1533+
bugs: Vec<DelayedDiagnostic>,
15341534
explanation: impl Into<DiagnosticMessage> + Copy,
15351535
) {
1536-
let mut no_bugs = true;
1536+
if bugs.is_empty() {
1537+
return;
1538+
}
1539+
15371540
// If backtraces are enabled, also print the query stack
15381541
let backtrace = std::env::var_os("RUST_BACKTRACE").map_or(true, |x| &x != "0");
1539-
for bug in bugs {
1542+
for (i, bug) in bugs.into_iter().enumerate() {
15401543
if let Some(file) = self.ice_file.as_ref()
15411544
&& let Ok(mut out) = std::fs::File::options().create(true).append(true).open(file)
15421545
{
@@ -1551,16 +1554,16 @@ impl DiagCtxtInner {
15511554
&bug.note
15521555
);
15531556
}
1554-
let mut bug =
1555-
if backtrace || self.ice_file.is_none() { bug.decorate() } else { bug.inner };
15561557

1557-
if no_bugs {
1558+
if i == 0 {
15581559
// Put the overall explanation before the `DelayedBug`s, to
15591560
// frame them better (e.g. separate warnings from them).
15601561
self.emit_diagnostic(Diagnostic::new(Bug, explanation));
1561-
no_bugs = false;
15621562
}
15631563

1564+
let mut bug =
1565+
if backtrace || self.ice_file.is_none() { bug.decorate() } else { bug.inner };
1566+
15641567
// "Undelay" the `DelayedBug`s (into plain `Bug`s).
15651568
if bug.level != Level::DelayedBug {
15661569
// NOTE(eddyb) not panicking here because we're already producing
@@ -1576,9 +1579,7 @@ impl DiagCtxtInner {
15761579
}
15771580

15781581
// Panic with `DelayedBugPanic` to avoid "unexpected panic" messages.
1579-
if !no_bugs {
1580-
panic::panic_any(DelayedBugPanic);
1581-
}
1582+
panic::panic_any(DelayedBugPanic);
15821583
}
15831584

15841585
fn bump_lint_err_count(&mut self) {

0 commit comments

Comments
 (0)