From 230e40644b5c112228a0b43d07fda552133f00b8 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Fri, 24 Apr 2020 01:03:20 -0300 Subject: [PATCH] Fix off by one error for delay_span_bug delay_span_bug bumps error_count after checking treat_err_as_bug --- src/librustc_errors/lib.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/librustc_errors/lib.rs b/src/librustc_errors/lib.rs index 151241fdb0b5f..e4a560e434aaa 100644 --- a/src/librustc_errors/lib.rs +++ b/src/librustc_errors/lib.rs @@ -869,7 +869,10 @@ impl HandlerInner { } fn delay_span_bug(&mut self, sp: impl Into, msg: &str) { - if self.treat_err_as_bug() { + // This is technically `self.treat_err_as_bug()` but `delay_span_bug` is called before + // incrementing `err_count` by one, so we need to +1 the comparing. + // FIXME: Would be nice to increment err_count in a more coherent way. + if self.flags.treat_err_as_bug.map(|c| self.err_count() + 1 >= c).unwrap_or(false) { // FIXME: don't abort here if report_delayed_bugs is off self.span_bug(sp, msg); }