use super::{
BugAbort, Diag, DiagBuilder, DiagMsg, DynEmitter, EmissionGuarantee, EmittedDiagnostics,
ErrorGuaranteed, FatalAbort, HumanBufferEmitter, Level, MultiSpan, SilentEmitter,
emitter::HumanEmitter,
};
use crate::{Result, SourceMap, Span};
use anstream::ColorChoice;
use rayon::prelude::*;
use solar_config::{CompileOpts, ErrorFormat};
use solar_data_structures::{map::FxHashSet, sync::Mutex};
#[cfg(debug_assertions)]
use std::sync::atomic::{AtomicUsize, Ordering};
use std::{
borrow::Cow,
cell::RefCell,
fmt,
hash::BuildHasher,
mem,
num::NonZeroUsize,
sync::{Arc, Weak},
time::Duration,
};
thread_local! {
static DEFERRED: RefCell<Option<Deferral>> = const { RefCell::new(None) };
}
#[cfg(debug_assertions)]
thread_local! {
static DEFERRING: RefCell<Vec<*const DiagCtxt>> = const { RefCell::new(Vec::new()) };
}
static WITHHOLDING: Mutex<Vec<Weak<Mutex<DiagCtxtInner>>>> = Mutex::new(Vec::new());
struct Deferral {
dcx: *const DiagCtxt,
batch: Option<Arc<Batch>>,
}
type Withholding<'a> = (&'a Arc<Mutex<DiagCtxtInner>>, &'a mut Option<Arc<Batch>>);
struct Batch {
dcx: Arc<Mutex<DiagCtxtInner>>,
diagnostics: Mutex<Vec<Diag>>,
}
impl Drop for Batch {
fn drop(&mut self) {
let diagnostics = mem::take(self.diagnostics.get_mut());
if !diagnostics.is_empty() {
let mut inner = self.dcx.lock();
for mut diagnostic in diagnostics {
inner.deliver_diagnostic(&mut diagnostic);
}
}
}
}
#[derive(Default)]
#[must_use = "pass deferred diagnostics to `DiagCtxt::emit_deferred`"]
pub struct DeferredDiagnostics(Vec<Arc<Batch>>);
impl fmt::Debug for DeferredDiagnostics {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_tuple("DeferredDiagnostics").field(&self.0.len()).finish()
}
}
impl DeferredDiagnostics {
pub fn append(&mut self, mut other: Self) {
self.0.append(&mut other.0);
}
pub fn is_empty(&self) -> bool {
self.0.iter().all(|batch| batch.diagnostics.lock().is_empty())
}
pub fn sort_by_cached_key<K: Ord>(&mut self, f: impl FnMut(&Diag) -> K) {
let mut diagnostics = self.take_diagnostics();
diagnostics.sort_by_cached_key(f);
if let Some(batch) = self.0.first() {
batch.diagnostics.lock().extend(diagnostics);
self.0.truncate(1);
}
}
fn take_diagnostics(&self) -> Vec<Diag> {
let mut diagnostics = Vec::new();
for batch in &self.0 {
diagnostics.append(&mut batch.diagnostics.lock());
}
diagnostics
}
}
fn flush_inner(inner: &Mutex<DiagCtxtInner>) {
if let Some(mut inner) = inner.try_lock_for(Duration::from_millis(500)) {
inner.flush_withheld();
}
}
pub fn flush_withheld() {
let contexts = WITHHOLDING.lock().clone();
for context in contexts {
if let Some(context) = context.upgrade() {
flush_inner(&context);
}
}
}
#[derive(Clone, Copy, Debug)]
pub struct DiagCtxtFlags {
pub can_emit_warnings: bool,
pub treat_err_as_bug: Option<NonZeroUsize>,
pub deduplicate_diagnostics: bool,
pub track_diagnostics: bool,
}
impl Default for DiagCtxtFlags {
fn default() -> Self {
Self {
can_emit_warnings: true,
treat_err_as_bug: None,
deduplicate_diagnostics: true,
track_diagnostics: cfg!(debug_assertions),
}
}
}
impl DiagCtxtFlags {
pub fn update_from_opts(&mut self, opts: &CompileOpts) {
self.deduplicate_diagnostics &= !opts.unstable.ui_testing;
self.track_diagnostics &= !opts.unstable.ui_testing;
self.track_diagnostics |= opts.unstable.track_diagnostics;
self.can_emit_warnings &= !opts.no_warnings;
}
}
pub struct DiagCtxt {
inner: Arc<Mutex<DiagCtxtInner>>,
#[cfg(debug_assertions)]
defers: AtomicUsize,
}
impl fmt::Debug for DiagCtxt {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let mut s = f.debug_struct("DiagCtxt");
if let Some(inner) = self.inner.try_lock() {
s.field("flags", &inner.flags)
.field("err_count", &inner.err_count)
.field("warn_count", &inner.warn_count)
.field("note_count", &inner.note_count);
} else {
s.field("inner", &format_args!("<locked>"));
}
s.finish_non_exhaustive()
}
}
struct DiagCtxtInner {
emitter: Box<DynEmitter>,
flags: DiagCtxtFlags,
allowed_diagnostic_codes: FxHashSet<String>,
err_count: usize,
deduplicated_err_count: usize,
warn_count: usize,
deduplicated_warn_count: usize,
note_count: usize,
deduplicated_note_count: usize,
emitted_diagnostics: FxHashSet<u64>,
withheld: Vec<Weak<Batch>>,
prune_withheld_at: usize,
registered: bool,
}
impl DiagCtxt {
pub fn new(emitter: Box<DynEmitter>) -> Self {
Self {
#[cfg(debug_assertions)]
defers: AtomicUsize::new(0),
inner: Arc::new(Mutex::new(DiagCtxtInner {
emitter,
flags: DiagCtxtFlags::default(),
allowed_diagnostic_codes: FxHashSet::default(),
err_count: 0,
deduplicated_err_count: 0,
warn_count: 0,
deduplicated_warn_count: 0,
note_count: 0,
deduplicated_note_count: 0,
emitted_diagnostics: FxHashSet::default(),
withheld: Vec::new(),
prune_withheld_at: 64,
registered: false,
})),
}
}
pub fn new_early() -> Self {
Self::with_stderr_emitter(None).with_flags(|flags| flags.track_diagnostics = false)
}
pub fn with_test_emitter(source_map: Option<Arc<SourceMap>>) -> Self {
Self::new(Box::new(HumanEmitter::test().source_map(source_map)))
}
pub fn with_stderr_emitter(source_map: Option<Arc<SourceMap>>) -> Self {
Self::with_stderr_emitter_and_color(source_map, ColorChoice::Auto)
}
pub fn with_stderr_emitter_and_color(
source_map: Option<Arc<SourceMap>>,
color_choice: ColorChoice,
) -> Self {
Self::new(Box::new(HumanEmitter::stderr(color_choice).source_map(source_map)))
}
pub fn with_silent_emitter(fatal_note: Option<String>) -> Self {
let fatal_emitter = HumanEmitter::stderr(Default::default());
Self::new(Box::new(SilentEmitter::new(fatal_emitter).with_note(fatal_note)))
.disable_warnings()
}
pub fn with_buffer_emitter(
source_map: Option<Arc<SourceMap>>,
color_choice: ColorChoice,
) -> Self {
Self::new(Box::new(HumanBufferEmitter::new(color_choice).source_map(source_map)))
}
pub fn from_opts(opts: &solar_config::CompileOpts) -> Self {
let source_map = Arc::new(SourceMap::empty());
let emitter: Box<DynEmitter> = match opts.error_format {
ErrorFormat::Human => {
let human = HumanEmitter::stderr(opts.color)
.source_map(Some(source_map))
.ui_testing(opts.unstable.ui_testing)
.human_kind(opts.error_format_human)
.terminal_width(opts.diagnostic_width);
Box::new(human)
}
#[cfg(feature = "json")]
ErrorFormat::Json | ErrorFormat::RustcJson => {
let writer = Box::new(std::io::BufWriter::new(std::io::stderr()));
let json = crate::diagnostics::JsonEmitter::new(writer, source_map, opts.color)
.pretty(opts.pretty_json_err)
.rustc_like(matches!(opts.error_format, ErrorFormat::RustcJson))
.ui_testing(opts.unstable.ui_testing)
.human_kind(opts.error_format_human)
.terminal_width(opts.diagnostic_width);
Box::new(json)
}
format => unimplemented!("{format:?}"),
};
Self::new(emitter)
.with_flags(|flags| flags.update_from_opts(opts))
.with_allowed_diagnostic_codes(opts.allow.iter().cloned())
}
pub fn with_allowed_diagnostic_codes(
mut self,
codes: impl IntoIterator<Item = String>,
) -> Self {
self.set_allowed_diagnostic_codes_mut(codes);
self
}
pub fn make_silent(&self, fatal_note: Option<String>, emit_fatal: bool) {
self.wrap_emitter(|prev| {
Box::new(SilentEmitter::new_boxed(emit_fatal.then_some(prev)).with_note(fatal_note))
});
}
pub fn set_emitter(&self, emitter: Box<DynEmitter>) -> Box<DynEmitter> {
std::mem::replace(&mut self.inner.lock().emitter, emitter)
}
pub fn wrap_emitter(&self, f: impl FnOnce(Box<DynEmitter>) -> Box<DynEmitter>) {
struct FakeEmitter;
impl crate::diagnostics::Emitter for FakeEmitter {
fn emit_diagnostic(&mut self, _diagnostic: &mut Diag) {}
}
let mut inner = self.inner.lock();
let prev = std::mem::replace(&mut inner.emitter, Box::new(FakeEmitter));
inner.emitter = f(prev);
}
pub fn source_map(&self) -> Option<Arc<SourceMap>> {
self.inner.lock().emitter.source_map().cloned()
}
pub fn with_flags(mut self, f: impl FnOnce(&mut DiagCtxtFlags)) -> Self {
self.set_flags_mut(f);
self
}
pub fn set_flags(&self, f: impl FnOnce(&mut DiagCtxtFlags)) {
f(&mut self.inner.lock().flags);
}
pub fn set_flags_mut(&mut self, f: impl FnOnce(&mut DiagCtxtFlags)) {
f(&mut self.inner.lock().flags);
}
pub fn set_allowed_diagnostic_codes(&self, codes: impl IntoIterator<Item = String>) {
self.inner.lock().allowed_diagnostic_codes.extend(codes);
}
pub fn set_allowed_diagnostic_codes_mut(&mut self, codes: impl IntoIterator<Item = String>) {
self.inner.lock().allowed_diagnostic_codes.extend(codes);
}
pub fn disable_warnings(self) -> Self {
self.with_flags(|f| f.can_emit_warnings = false)
}
pub fn can_emit_warnings(&self) -> bool {
self.inner.lock().flags.can_emit_warnings
}
pub fn reset_err_count(&self) {
let mut inner = self.inner.lock();
inner.err_count = 0;
inner.deduplicated_err_count = 0;
inner.warn_count = 0;
inner.deduplicated_warn_count = 0;
inner.note_count = 0;
inner.deduplicated_note_count = 0;
inner.emitted_diagnostics.clear();
}
pub fn track_diagnostics(&self) -> bool {
self.inner.lock().flags.track_diagnostics
}
#[inline]
pub fn emit_diagnostic(&self, mut diagnostic: Diag) -> Result<(), ErrorGuaranteed> {
self.emit_diagnostic_without_consuming(&mut diagnostic)
}
pub(super) fn emit_diagnostic_without_consuming(
&self,
diagnostic: &mut Diag,
) -> Result<(), ErrorGuaranteed> {
let mut deferral = self.take_deferral();
#[cfg(debug_assertions)]
debug_assert!(
deferral.is_some()
|| self.defers.load(Ordering::Relaxed) == 0
|| DEFERRING
.with_borrow(|deferring| deferring.iter().any(|&dcx| std::ptr::eq(dcx, self)))
|| matches!(diagnostic.level, Level::Bug | Level::Fatal),
"diagnostic emitted outside the deferral that its parallel work expects: {:?}",
diagnostic.messages.first().map(|(message, _)| message.as_str()),
);
let result = self.inner.lock().emit_diagnostic_without_consuming(
diagnostic,
deferral.as_mut().map(|deferral| (&self.inner, &mut deferral.batch)),
);
self.restore_deferral(deferral);
result
}
fn take_deferral(&self) -> Option<Deferral> {
DEFERRED.with_borrow_mut(|deferral| {
deferral.take_if(|deferral| std::ptr::eq(deferral.dcx, self))
})
}
fn restore_deferral(&self, deferral: Option<Deferral>) {
if deferral.is_some() {
DEFERRED.set(deferral);
}
}
pub fn defer<R>(&self, f: impl FnOnce() -> R) -> (R, DeferredDiagnostics) {
struct Restore<'a> {
#[cfg_attr(not(debug_assertions), allow(dead_code))]
dcx: &'a DiagCtxt,
outer: Option<Deferral>,
}
impl Drop for Restore<'_> {
fn drop(&mut self) {
DEFERRED.set(self.outer.take());
#[cfg(debug_assertions)]
{
self.dcx.defers.fetch_sub(1, Ordering::Relaxed);
DEFERRING.with_borrow_mut(|deferring| deferring.pop());
}
}
}
#[cfg(debug_assertions)]
{
self.defers.fetch_add(1, Ordering::Relaxed);
DEFERRING.with_borrow_mut(|deferring| deferring.push(self));
}
let outer = DEFERRED.replace(Some(Deferral { dcx: self, batch: None }));
let restore = Restore { dcx: self, outer };
let result = f();
let deferral = DEFERRED.take();
drop(restore);
(
result,
DeferredDiagnostics(deferral.and_then(|deferral| deferral.batch).into_iter().collect()),
)
}
pub fn emit_deferred(&self, deferred: DeferredDiagnostics) {
let diagnostics = deferred.take_diagnostics();
if diagnostics.is_empty() {
return;
}
let mut deferral = self.take_deferral();
{
let mut inner = self.inner.lock();
match deferral.as_mut() {
Some(deferral) => {
let batch = inner.withhold(&self.inner, &mut deferral.batch);
batch.diagnostics.lock().extend(diagnostics);
}
None => {
for mut diagnostic in diagnostics {
inner.deliver_diagnostic(&mut diagnostic);
}
}
}
}
self.restore_deferral(deferral);
}
pub fn flush_withheld(&self) {
flush_inner(&self.inner);
}
pub fn par_defer<I, R>(
&self,
iter: I,
f: impl Fn(I::Item) -> R + Sync + Send,
) -> (Vec<R>, DeferredDiagnostics)
where
I: ParallelIterator,
R: Send,
{
let outputs = iter.map(|item| self.defer(|| f(item))).collect::<Vec<_>>();
let mut results = Vec::with_capacity(outputs.len());
let mut deferred = DeferredDiagnostics::default();
for (result, batch) in outputs {
results.push(result);
deferred.append(batch);
}
(results, deferred)
}
pub fn par_for_each<I>(&self, iter: I, f: impl Fn(I::Item) + Sync + Send)
where
I: ParallelIterator,
{
self.emit_deferred(self.par_defer(iter, f).1);
}
pub fn err_count(&self) -> usize {
self.inner.lock().err_count
}
pub fn has_errors(&self) -> Result<(), ErrorGuaranteed> {
if self.inner.lock().has_errors() { Err(ErrorGuaranteed::new_unchecked()) } else { Ok(()) }
}
pub fn warn_count(&self) -> usize {
self.inner.lock().warn_count
}
pub fn note_count(&self) -> usize {
self.inner.lock().note_count
}
#[inline]
pub fn emitted_diagnostics_result(
&self,
) -> Option<Result<EmittedDiagnostics, EmittedDiagnostics>> {
let inner = self.inner.lock();
let diags = EmittedDiagnostics(inner.emitter.local_buffer()?.to_string());
Some(if inner.has_errors() { Err(diags) } else { Ok(diags) })
}
pub fn emitted_diagnostics(&self) -> Option<EmittedDiagnostics> {
let inner = self.inner.lock();
Some(EmittedDiagnostics(inner.emitter.local_buffer()?.to_string()))
}
pub fn emitted_errors(&self) -> Option<Result<(), EmittedDiagnostics>> {
let inner = self.inner.lock();
let buffer = inner.emitter.local_buffer()?;
Some(if inner.has_errors() { Err(EmittedDiagnostics(buffer.to_string())) } else { Ok(()) })
}
pub fn print_error_count(&self) -> Result {
self.inner.lock().print_error_count()
}
}
impl DiagCtxt {
#[track_caller]
pub fn diag<G: EmissionGuarantee>(
&self,
level: Level,
msg: impl Into<DiagMsg>,
) -> DiagBuilder<'_, G> {
DiagBuilder::new(self, level, msg)
}
#[track_caller]
#[cold]
pub fn bug(&self, msg: impl Into<DiagMsg>) -> DiagBuilder<'_, BugAbort> {
self.diag(Level::Bug, msg)
}
#[track_caller]
#[cold]
pub fn fatal(&self, msg: impl Into<DiagMsg>) -> DiagBuilder<'_, FatalAbort> {
self.diag(Level::Fatal, msg)
}
#[track_caller]
pub fn err(&self, msg: impl Into<DiagMsg>) -> DiagBuilder<'_, ErrorGuaranteed> {
self.diag(Level::Error, msg)
}
#[track_caller]
pub fn emit_err(&self, span: impl Into<MultiSpan>, msg: impl Into<DiagMsg>) -> ErrorGuaranteed {
self.err(msg).span(span).emit()
}
#[track_caller]
pub fn emit_err_note(
&self,
span: impl Into<MultiSpan>,
msg: impl Into<DiagMsg>,
note: impl Into<DiagMsg>,
) -> ErrorGuaranteed {
self.err(msg).span(span).note(note).emit()
}
#[track_caller]
pub fn emit_err_span_note(
&self,
span: impl Into<MultiSpan>,
msg: impl Into<DiagMsg>,
note_span: impl Into<MultiSpan>,
note: impl Into<DiagMsg>,
) -> ErrorGuaranteed {
self.err(msg).span(span).span_note(note_span, note).emit()
}
#[track_caller]
pub fn emit_err_label(
&self,
span: impl Into<MultiSpan>,
msg: impl Into<DiagMsg>,
label_span: Span,
label: impl Into<DiagMsg>,
) -> ErrorGuaranteed {
self.err(msg).span(span).span_label(label_span, label).emit()
}
#[track_caller]
pub fn warn(&self, msg: impl Into<DiagMsg>) -> DiagBuilder<'_, ()> {
self.diag(Level::Warning, msg)
}
#[track_caller]
pub fn help(&self, msg: impl Into<DiagMsg>) -> DiagBuilder<'_, ()> {
self.diag(Level::Help, msg)
}
#[track_caller]
pub fn note(&self, msg: impl Into<DiagMsg>) -> DiagBuilder<'_, ()> {
self.diag(Level::Note, msg)
}
}
impl DiagCtxtInner {
fn emit_diagnostic(&mut self, mut diagnostic: Diag) -> Result<(), ErrorGuaranteed> {
self.emit_diagnostic_without_consuming(&mut diagnostic, None)
}
fn emit_diagnostic_without_consuming(
&mut self,
diagnostic: &mut Diag,
deferral: Option<Withholding<'_>>,
) -> Result<(), ErrorGuaranteed> {
if self.is_allowed_diagnostic(diagnostic) {
return Ok(());
}
if diagnostic.level == Level::Warning && !self.flags.can_emit_warnings {
return Ok(());
}
if diagnostic.level == Level::Allow {
return Ok(());
}
if matches!(diagnostic.level, Level::Error | Level::Fatal) && self.treat_next_err_as_bug() {
diagnostic.level = Level::Bug;
}
match deferral {
Some((handle, batch)) if !matches!(diagnostic.level, Level::Bug | Level::Fatal) => {
let batch = self.withhold(handle, batch);
batch.diagnostics.lock().push(diagnostic.clone());
}
_ => {
if matches!(diagnostic.level, Level::Bug | Level::Fatal) {
self.flush_withheld();
}
self.deliver_diagnostic(diagnostic);
}
}
if diagnostic.is_error() {
self.bump_err_count();
Err(ErrorGuaranteed::new_unchecked())
} else {
if diagnostic.level == Level::Warning {
self.bump_warn_count();
} else if diagnostic.is_note() {
self.bump_note_count();
}
Ok(())
}
}
fn withhold<'a>(
&mut self,
handle: &Arc<Mutex<Self>>,
slot: &'a mut Option<Arc<Batch>>,
) -> &'a Arc<Batch> {
slot.get_or_insert_with(|| {
let batch =
Arc::new(Batch { dcx: Arc::clone(handle), diagnostics: Mutex::new(Vec::new()) });
if self.withheld.len() >= self.prune_withheld_at {
self.withheld.retain(|batch| batch.strong_count() > 0);
self.prune_withheld_at = (2 * self.withheld.len()).max(64);
}
self.withheld.push(Arc::downgrade(&batch));
if !mem::replace(&mut self.registered, true) {
let mut contexts = WITHHOLDING.lock();
contexts.retain(|context| context.strong_count() > 0);
contexts.push(Arc::downgrade(handle));
}
batch
})
}
fn flush_withheld(&mut self) {
let batches = self.withheld.iter().filter_map(Weak::upgrade).collect::<Vec<_>>();
for batch in batches {
let diagnostics = mem::take(&mut *batch.diagnostics.lock());
for mut diagnostic in diagnostics {
self.deliver_diagnostic(&mut diagnostic);
}
}
}
fn deliver_diagnostic(&mut self, diagnostic: &mut Diag) {
let already_emitted = self.insert_diagnostic(diagnostic);
if self.flags.deduplicate_diagnostics && already_emitted {
return;
}
diagnostic.children.retain(|sub| {
if !matches!(sub.level, Level::OnceNote | Level::OnceHelp) {
return true;
}
let sub_already_emitted = self.insert_diagnostic(sub);
!sub_already_emitted
});
self.emitter.emit_diagnostic(diagnostic);
if diagnostic.is_error() {
self.deduplicated_err_count += 1;
} else if diagnostic.level == Level::Warning {
self.deduplicated_warn_count += 1;
} else if diagnostic.is_note() {
self.deduplicated_note_count += 1;
}
}
fn print_error_count(&mut self) -> Result {
if self.treat_err_as_bug() {
return Ok(());
}
let errors = match self.deduplicated_err_count {
0 => None,
1 => Some(Cow::from("aborting due to 1 previous error")),
count => Some(Cow::from(format!("aborting due to {count} previous errors"))),
};
let mut others = Vec::with_capacity(2);
match self.deduplicated_warn_count {
1 => others.push(Cow::from("1 warning emitted")),
count if count > 1 => others.push(Cow::from(format!("{count} warnings emitted"))),
_ => {}
}
match self.deduplicated_note_count {
1 => others.push(Cow::from("1 note emitted")),
count if count > 1 => others.push(Cow::from(format!("{count} notes emitted"))),
_ => {}
}
match (errors, others.is_empty()) {
(None, true) => Ok(()),
(None, false) => {
if self.flags.track_diagnostics {
let msg = others.join(", ");
self.emitter.emit_diagnostic(&mut Diag::new(Level::Warning, msg));
}
Ok(())
}
(Some(e), true) => self.emit_diagnostic(Diag::new(Level::Error, e)),
(Some(e), false) => self
.emit_diagnostic(Diag::new(Level::Error, format!("{}; {}", e, others.join(", ")))),
}
}
fn insert_diagnostic<H: std::hash::Hash>(&mut self, diag: &H) -> bool {
let hash = solar_data_structures::map::rustc_hash::FxBuildHasher.hash_one(diag);
!self.emitted_diagnostics.insert(hash)
}
fn treat_err_as_bug(&self) -> bool {
self.flags.treat_err_as_bug.is_some_and(|c| self.err_count >= c.get())
}
fn treat_next_err_as_bug(&self) -> bool {
self.flags.treat_err_as_bug.is_some_and(|c| self.err_count + 1 >= c.get())
}
fn is_allowed_diagnostic(&self, diagnostic: &Diag) -> bool {
diagnostic.level == Level::Warning
&& diagnostic.id().is_some_and(|id| self.allowed_diagnostic_codes.contains(id))
}
fn bump_err_count(&mut self) {
self.err_count += 1;
self.panic_if_treat_err_as_bug();
}
fn bump_warn_count(&mut self) {
self.warn_count += 1;
}
fn bump_note_count(&mut self) {
self.note_count += 1;
}
fn has_errors(&self) -> bool {
self.err_count > 0
}
fn panic_if_treat_err_as_bug(&self) {
if self.treat_err_as_bug() {
match (self.err_count, self.flags.treat_err_as_bug.unwrap().get()) {
(1, 1) => panic!("aborting due to `-Z treat-err-as-bug=1`"),
(count, val) => {
panic!("aborting after {count} errors due to `-Z treat-err-as-bug={val}`")
}
}
}
}
}