1
Fork 0

Store a single copy of the error registry in DiagCtxt

And pass this to the individual emitters when necessary.
This commit is contained in:
bjorn3 2024-11-09 18:30:13 +00:00
parent ea6f5cbd2f
commit 030545d8c3
9 changed files with 67 additions and 46 deletions

View file

@ -55,7 +55,6 @@ pub use diagnostic_impls::{
};
pub use emitter::ColorConfig;
use emitter::{DynEmitter, Emitter, is_case_difference, is_different};
use registry::Registry;
use rustc_data_structures::AtomicRef;
use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet};
use rustc_data_structures::stable_hasher::{Hash128, StableHasher};
@ -77,6 +76,8 @@ pub use snippet::Style;
pub use termcolor::{Color, ColorSpec, WriteColor};
use tracing::debug;
use crate::registry::Registry;
pub mod annotate_snippet_emitter_writer;
pub mod codes;
mod diagnostic;
@ -483,6 +484,8 @@ impl<'a> std::ops::Deref for DiagCtxtHandle<'a> {
struct DiagCtxtInner {
flags: DiagCtxtFlags,
registry: Registry,
/// The error guarantees from all emitted errors. The length gives the error count.
err_guars: Vec<ErrorGuaranteed>,
/// The error guarantee from all emitted lint errors. The length gives the
@ -664,6 +667,11 @@ impl DiagCtxt {
self
}
pub fn with_registry(mut self, registry: Registry) -> Self {
self.inner.get_mut().registry = registry;
self
}
pub fn new(emitter: Box<DynEmitter>) -> Self {
Self { inner: Lock::new(DiagCtxtInner::new(emitter)) }
}
@ -694,7 +702,7 @@ impl DiagCtxt {
struct FalseEmitter;
impl Emitter for FalseEmitter {
fn emit_diagnostic(&mut self, _: DiagInner) {
fn emit_diagnostic(&mut self, _: DiagInner, _: &Registry) {
unimplemented!("false emitter must only used during `wrap_emitter`")
}
@ -759,6 +767,7 @@ impl DiagCtxt {
let mut inner = self.inner.borrow_mut();
let DiagCtxtInner {
flags: _,
registry: _,
err_guars,
lint_err_guars,
delayed_bugs,
@ -964,7 +973,7 @@ impl<'a> DiagCtxtHandle<'a> {
self.inner.borrow().has_errors_or_delayed_bugs()
}
pub fn print_error_count(&self, registry: &Registry) {
pub fn print_error_count(&self) {
let mut inner = self.inner.borrow_mut();
// Any stashed diagnostics should have been handled by
@ -1014,7 +1023,7 @@ impl<'a> DiagCtxtHandle<'a> {
.emitted_diagnostic_codes
.iter()
.filter_map(|&code| {
if registry.try_find_description(code).is_ok() {
if inner.registry.try_find_description(code).is_ok() {
Some(code.to_string())
} else {
None
@ -1075,10 +1084,10 @@ impl<'a> DiagCtxtHandle<'a> {
}
pub fn emit_future_breakage_report(&self) {
let mut inner = self.inner.borrow_mut();
let inner = &mut *self.inner.borrow_mut();
let diags = std::mem::take(&mut inner.future_breakage_diagnostics);
if !diags.is_empty() {
inner.emitter.emit_future_breakage_report(diags);
inner.emitter.emit_future_breakage_report(diags, &inner.registry);
}
}
@ -1409,6 +1418,7 @@ impl DiagCtxtInner {
fn new(emitter: Box<DynEmitter>) -> Self {
Self {
flags: DiagCtxtFlags { can_emit_warnings: true, ..Default::default() },
registry: Registry::new(&[]),
err_guars: Vec::new(),
lint_err_guars: Vec::new(),
delayed_bugs: Vec::new(),
@ -1582,7 +1592,7 @@ impl DiagCtxtInner {
}
self.has_printed = true;
self.emitter.emit_diagnostic(diagnostic);
self.emitter.emit_diagnostic(diagnostic, &self.registry);
}
if is_error {