about summary refs log tree commit diff
diff options
context:
space:
mode:
authorYuki Okushi <jtitor@2k36.org>2021-08-07 01:46:32 +0900
committerGitHub <noreply@github.com>2021-08-07 01:46:32 +0900
commit3b0e797ee6678175d1df9a01e944312b348d05b0 (patch)
treeab80020ed98ac5e68b40ab64927126b943b4ccab
parent352ad622656ee3a8d8362cb92f5b608a13bc14f5 (diff)
parent5ff06fb77f906b65b6a5301e84acc82a246af2b0 (diff)
downloadrust-3b0e797ee6678175d1df9a01e944312b348d05b0.tar.gz
rust-3b0e797ee6678175d1df9a01e944312b348d05b0.zip
Rollup merge of #87761 - rusticstuff:rustc_error_overflow, r=Mark-Simulacrum
Fix overflow in rustc happening if the `err_count()` is reduced in a stage.

This can happen if stashed diagnostics are removed or replaced with fewer errors. The semantics stay the same if built without overflow checks. Fixes #84219.

Background: I came across this independently by running `RUSTFLAGS="-C overflow-checks=on" ./x.py test`. Fixing this will allow us to move on and find further overflow errors with testing or fuzzing.
-rw-r--r--compiler/rustc_session/src/session.rs3
1 files changed, 1 insertions, 2 deletions
diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs
index fe87867d299..d5c759623e3 100644
--- a/compiler/rustc_session/src/session.rs
+++ b/compiler/rustc_session/src/session.rs
@@ -450,8 +450,7 @@ impl Session {
     {
         let old_count = self.err_count();
         let result = f();
-        let errors = self.err_count() - old_count;
-        if errors == 0 { Ok(result) } else { Err(ErrorReported) }
+        if self.err_count() == old_count { Ok(result) } else { Err(ErrorReported) }
     }
     pub fn span_warn<S: Into<MultiSpan>>(&self, sp: S, msg: &str) {
         self.diagnostic().span_warn(sp, msg)