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``
This commit is contained in:
commit
f5387a1c38
20 changed files with 119 additions and 159 deletions
|
@ -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);
|
||||
}
|
||||
self.dcx.stash_diagnostic(span, key, self.into_diagnostic());
|
||||
}
|
||||
|
||||
/// 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))
|
||||
}
|
||||
|
||||
/// 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.
|
||||
|
|
|
@ -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 (
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue