Skip to content

Commit bd12fa3

Browse files
committed
Tweak flush_delayed.
- Take a `Vec` instead of an iterator, because that's all that is needed. - 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 7226efb commit bd12fa3

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
@@ -1543,13 +1543,16 @@ impl DiagCtxtInner {
15431543

15441544
fn flush_delayed(
15451545
&mut self,
1546-
bugs: impl IntoIterator<Item = DelayedDiagnostic>,
1546+
bugs: Vec<DelayedDiagnostic>,
15471547
explanation: impl Into<DiagnosticMessage> + Copy,
15481548
) {
1549-
let mut no_bugs = true;
1549+
if bugs.is_empty() {
1550+
return;
1551+
}
1552+
15501553
// If backtraces are enabled, also print the query stack
15511554
let backtrace = std::env::var_os("RUST_BACKTRACE").map_or(true, |x| &x != "0");
1552-
for bug in bugs {
1555+
for (i, bug) in bugs.into_iter().enumerate() {
15531556
if let Some(file) = self.ice_file.as_ref()
15541557
&& let Ok(mut out) = std::fs::File::options().create(true).append(true).open(file)
15551558
{
@@ -1564,16 +1567,16 @@ impl DiagCtxtInner {
15641567
&bug.note
15651568
);
15661569
}
1567-
let mut bug =
1568-
if backtrace || self.ice_file.is_none() { bug.decorate() } else { bug.inner };
15691570

1570-
if no_bugs {
1571+
if i == 0 {
15711572
// Put the overall explanation before the `DelayedBug`s, to
15721573
// frame them better (e.g. separate warnings from them).
15731574
self.emit_diagnostic(Diagnostic::new(Bug, explanation));
1574-
no_bugs = false;
15751575
}
15761576

1577+
let mut bug =
1578+
if backtrace || self.ice_file.is_none() { bug.decorate() } else { bug.inner };
1579+
15771580
// "Undelay" the `DelayedBug`s (into plain `Bug`s).
15781581
if bug.level != Level::DelayedBug {
15791582
// NOTE(eddyb) not panicking here because we're already producing
@@ -1589,9 +1592,7 @@ impl DiagCtxtInner {
15891592
}
15901593

15911594
// Panic with `DelayedBugPanic` to avoid "unexpected panic" messages.
1592-
if !no_bugs {
1593-
panic::panic_any(DelayedBugPanic);
1594-
}
1595+
panic::panic_any(DelayedBugPanic);
15951596
}
15961597

15971598
fn bump_lint_err_count(&mut self) {

0 commit comments

Comments
 (0)