about summary refs log tree commit diff
path: root/compiler/rustc_errors/src
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2024-01-22 07:56:43 +0100
committerGitHub <noreply@github.com>2024-01-22 07:56:43 +0100
commitbef2e85359ac1c826f2259ae8b93b15b7a0d032e (patch)
treed2e2ce6a28db2fad9979cbe3f5e63ea8a7c4e7bc /compiler/rustc_errors/src
parent6687e8e460683fa2242d8eca3da49097e39f859e (diff)
parent1f9fa2305a099cbbf9858e3eb777495a7246e84a (diff)
downloadrust-bef2e85359ac1c826f2259ae8b93b15b7a0d032e.tar.gz
rust-bef2e85359ac1c826f2259ae8b93b15b7a0d032e.zip
Rollup merge of #119986 - nnethercote:fix-error-counting, r=compiler-errors,oli-obk
Fix error counting

There is some messiness in how errors get counted. Here are some cleanups.

r? `@compiler-errors`
Diffstat (limited to 'compiler/rustc_errors/src')
-rw-r--r--compiler/rustc_errors/src/lib.rs40
1 files changed, 18 insertions, 22 deletions
diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs
index 141547b537d..9d80c456517 100644
--- a/compiler/rustc_errors/src/lib.rs
+++ b/compiler/rustc_errors/src/lib.rs
@@ -421,16 +421,16 @@ pub struct DiagCtxt {
 struct DiagCtxtInner {
     flags: DiagCtxtFlags,
 
-    /// The number of lint errors that have been emitted.
+    /// The number of lint errors that have been emitted, including duplicates.
     lint_err_count: usize,
-    /// The number of errors that have been emitted, including duplicates.
-    ///
-    /// This is not necessarily the count that's reported to the user once
-    /// compilation ends.
+    /// The number of non-lint errors that have been emitted, including duplicates.
     err_count: usize,
+
+    /// The error count shown to the user at the end.
     deduplicated_err_count: usize,
-    /// The warning count, used for a recap upon finishing
+    /// The warning count shown to the user at the end.
     deduplicated_warn_count: usize,
+
     /// Has this diagnostic context printed any diagnostics? (I.e. has
     /// `self.emitter.emit_diagnostic()` been called?
     has_printed: bool,
@@ -927,11 +927,13 @@ impl DiagCtxt {
         self.struct_bug(msg).emit()
     }
 
+    /// This excludes lint errors and delayed bugs.
     #[inline]
     pub fn err_count(&self) -> usize {
         self.inner.borrow().err_count
     }
 
+    /// This excludes lint errors and delayed bugs.
     pub fn has_errors(&self) -> Option<ErrorGuaranteed> {
         self.inner.borrow().has_errors().then(|| {
             #[allow(deprecated)]
@@ -939,30 +941,24 @@ impl DiagCtxt {
         })
     }
 
+    /// This excludes delayed bugs. Unless absolutely necessary, prefer
+    /// `has_errors` to this method.
     pub fn has_errors_or_lint_errors(&self) -> Option<ErrorGuaranteed> {
         let inner = self.inner.borrow();
-        let has_errors_or_lint_errors = inner.has_errors() || inner.lint_err_count > 0;
-        has_errors_or_lint_errors.then(|| {
-            #[allow(deprecated)]
-            ErrorGuaranteed::unchecked_claim_error_was_emitted()
-        })
-    }
-
-    pub fn has_errors_or_span_delayed_bugs(&self) -> Option<ErrorGuaranteed> {
-        let inner = self.inner.borrow();
-        let has_errors_or_span_delayed_bugs =
-            inner.has_errors() || !inner.span_delayed_bugs.is_empty();
-        has_errors_or_span_delayed_bugs.then(|| {
+        let result = inner.has_errors() || inner.lint_err_count > 0;
+        result.then(|| {
             #[allow(deprecated)]
             ErrorGuaranteed::unchecked_claim_error_was_emitted()
         })
     }
 
-    pub fn is_compilation_going_to_fail(&self) -> Option<ErrorGuaranteed> {
+    /// Unless absolutely necessary, prefer `has_errors` or
+    /// `has_errors_or_lint_errors` to this method.
+    pub fn has_errors_or_lint_errors_or_delayed_bugs(&self) -> Option<ErrorGuaranteed> {
         let inner = self.inner.borrow();
-        let will_fail =
+        let result =
             inner.has_errors() || inner.lint_err_count > 0 || !inner.span_delayed_bugs.is_empty();
-        will_fail.then(|| {
+        result.then(|| {
             #[allow(deprecated)]
             ErrorGuaranteed::unchecked_claim_error_was_emitted()
         })
@@ -1162,7 +1158,7 @@ impl DiagCtxt {
         let mut inner = self.inner.borrow_mut();
 
         if loud && lint_level.is_error() {
-            inner.err_count += 1;
+            inner.lint_err_count += 1;
             inner.panic_if_treat_err_as_bug();
         }