diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2024-01-11 19:42:51 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-01-11 19:42:51 +0100 |
| commit | f5387a1c38822cb9c13686ed0cbc83069668ca3b (patch) | |
| tree | 11d202734fcb973c726c3c973b94d7860ef0fc7a /compiler/rustc_errors/src | |
| parent | 6beb676990641737a611cf538a98bb85a3894858 (diff) | |
| parent | 4fd1db1aa56fba038fd11f70aa6d5c56e0059930 (diff) | |
| download | rust-f5387a1c38822cb9c13686ed0cbc83069668ca3b.tar.gz rust-f5387a1c38822cb9c13686ed0cbc83069668ca3b.zip | |
Rollup merge of #119841 - nnethercote:rm-DiagnosticBuilder-buffer, r=oli-obk
Remove `DiagnosticBuilder::buffer` `DiagnosticBuilder::buffer` doesn't do much, and part of what it does (for `-Ztreat-err-as-bug`) it shouldn't. This PR strips it back, replaces its uses, and finally removes it, making a few cleanups in the vicinity along the way. r? ``@oli-obk``
Diffstat (limited to 'compiler/rustc_errors/src')
| -rw-r--r-- | compiler/rustc_errors/src/diagnostic_builder.rs | 30 | ||||
| -rw-r--r-- | compiler/rustc_errors/src/lib.rs | 27 |
2 files changed, 14 insertions, 43 deletions
diff --git a/compiler/rustc_errors/src/diagnostic_builder.rs b/compiler/rustc_errors/src/diagnostic_builder.rs index a02909f29c4..bd7c58d904e 100644 --- a/compiler/rustc_errors/src/diagnostic_builder.rs +++ b/compiler/rustc_errors/src/diagnostic_builder.rs @@ -255,35 +255,13 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> { /// Stashes diagnostic for possible later improvement in a different, /// later stage of the compiler. The diagnostic can be accessed with /// the provided `span` and `key` through [`DiagCtxt::steal_diagnostic()`]. - /// - /// As with `buffer`, this is unless the dcx has disabled such buffering. pub fn stash(self, span: Span, key: StashKey) { - if let Some((diag, dcx)) = self.into_diagnostic() { - dcx.stash_diagnostic(span, key, diag); - } - } - - /// Converts the builder to a `Diagnostic` for later emission, - /// unless dcx has disabled such buffering. - fn into_diagnostic(mut self) -> Option<(Diagnostic, &'a DiagCtxt)> { - if self.dcx.inner.lock().flags.treat_err_as_bug.is_some() { - self.emit(); - return None; - } - - let diag = self.take_diag(); - - // Logging here is useful to help track down where in logs an error was - // actually emitted. - debug!("buffer: diag={:?}", diag); - - Some((diag, self.dcx)) + self.dcx.stash_diagnostic(span, key, self.into_diagnostic()); } - /// Buffers the diagnostic for later emission, - /// unless dcx has disabled such buffering. - pub fn buffer(self, buffered_diagnostics: &mut Vec<Diagnostic>) { - buffered_diagnostics.extend(self.into_diagnostic().map(|(diag, _)| diag)); + /// Converts the builder to a `Diagnostic` for later emission. + pub fn into_diagnostic(mut self) -> Diagnostic { + self.take_diag() } /// Delay emission of this diagnostic as a bug. diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index 8fb539fc358..404c89ea01b 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -981,6 +981,10 @@ impl DiagCtxt { inner.emit_stashed_diagnostics(); + if inner.treat_err_as_bug() { + return; + } + let warnings = match inner.deduplicated_warn_count { 0 => Cow::from(""), 1 => Cow::from("1 warning emitted"), @@ -991,9 +995,6 @@ impl DiagCtxt { 1 => Cow::from("aborting due to 1 previous error"), count => Cow::from(format!("aborting due to {count} previous errors")), }; - if inner.treat_err_as_bug() { - return; - } match (errors.len(), warnings.len()) { (0, 0) => return, @@ -1168,7 +1169,8 @@ impl DiagCtxt { let mut inner = self.inner.borrow_mut(); if loud && lint_level.is_error() { - inner.bump_err_count(); + inner.err_count += 1; + inner.panic_if_treat_err_as_bug(); } inner.emitter.emit_unused_externs(lint_level, unused_externs) @@ -1255,7 +1257,7 @@ impl DiagCtxtInner { } fn emit_diagnostic(&mut self, mut diagnostic: Diagnostic) -> Option<ErrorGuaranteed> { - if matches!(diagnostic.level, Error | Fatal) && self.treat_err_as_bug() { + if matches!(diagnostic.level, Error | Fatal) && self.treat_next_err_as_bug() { diagnostic.level = Bug; } @@ -1353,10 +1355,11 @@ impl DiagCtxtInner { } if diagnostic.is_error() { if diagnostic.is_lint { - self.bump_lint_err_count(); + self.lint_err_count += 1; } else { - self.bump_err_count(); + self.err_count += 1; } + self.panic_if_treat_err_as_bug(); #[allow(deprecated)] { @@ -1447,16 +1450,6 @@ impl DiagCtxtInner { panic::panic_any(DelayedBugPanic); } - fn bump_lint_err_count(&mut self) { - self.lint_err_count += 1; - self.panic_if_treat_err_as_bug(); - } - - fn bump_err_count(&mut self) { - self.err_count += 1; - self.panic_if_treat_err_as_bug(); - } - fn panic_if_treat_err_as_bug(&self) { if self.treat_err_as_bug() { match ( |
