Store a single copy of the error registry in DiagCtxt
And pass this to the individual emitters when necessary.
This commit is contained in:
parent
ea6f5cbd2f
commit
030545d8c3
9 changed files with 67 additions and 46 deletions
|
@ -44,7 +44,6 @@ mod tests;
|
|||
pub struct JsonEmitter {
|
||||
#[setters(skip)]
|
||||
dst: IntoDynSyncSend<Box<dyn Write + Send>>,
|
||||
registry: Option<Registry>,
|
||||
#[setters(skip)]
|
||||
sm: Lrc<SourceMap>,
|
||||
fluent_bundle: Option<Lrc<FluentBundle>>,
|
||||
|
@ -74,7 +73,6 @@ impl JsonEmitter {
|
|||
) -> JsonEmitter {
|
||||
JsonEmitter {
|
||||
dst: IntoDynSyncSend(dst),
|
||||
registry: None,
|
||||
sm,
|
||||
fluent_bundle: None,
|
||||
fallback_bundle,
|
||||
|
@ -121,8 +119,8 @@ impl Translate for JsonEmitter {
|
|||
}
|
||||
|
||||
impl Emitter for JsonEmitter {
|
||||
fn emit_diagnostic(&mut self, diag: crate::DiagInner) {
|
||||
let data = Diagnostic::from_errors_diagnostic(diag, self);
|
||||
fn emit_diagnostic(&mut self, diag: crate::DiagInner, registry: &Registry) {
|
||||
let data = Diagnostic::from_errors_diagnostic(diag, self, registry);
|
||||
let result = self.emit(EmitTyped::Diagnostic(data));
|
||||
if let Err(e) = result {
|
||||
panic!("failed to print diagnostics: {e:?}");
|
||||
|
@ -137,7 +135,7 @@ impl Emitter for JsonEmitter {
|
|||
}
|
||||
}
|
||||
|
||||
fn emit_future_breakage_report(&mut self, diags: Vec<crate::DiagInner>) {
|
||||
fn emit_future_breakage_report(&mut self, diags: Vec<crate::DiagInner>, registry: &Registry) {
|
||||
let data: Vec<FutureBreakageItem<'_>> = diags
|
||||
.into_iter()
|
||||
.map(|mut diag| {
|
||||
|
@ -151,7 +149,7 @@ impl Emitter for JsonEmitter {
|
|||
}
|
||||
FutureBreakageItem {
|
||||
diagnostic: EmitTyped::Diagnostic(Diagnostic::from_errors_diagnostic(
|
||||
diag, self,
|
||||
diag, self, registry,
|
||||
)),
|
||||
}
|
||||
})
|
||||
|
@ -291,7 +289,11 @@ struct UnusedExterns<'a> {
|
|||
|
||||
impl Diagnostic {
|
||||
/// Converts from `rustc_errors::DiagInner` to `Diagnostic`.
|
||||
fn from_errors_diagnostic(diag: crate::DiagInner, je: &JsonEmitter) -> Diagnostic {
|
||||
fn from_errors_diagnostic(
|
||||
diag: crate::DiagInner,
|
||||
je: &JsonEmitter,
|
||||
registry: &Registry,
|
||||
) -> Diagnostic {
|
||||
let args = to_fluent_args(diag.args.iter());
|
||||
let sugg_to_diag = |sugg: &CodeSuggestion| {
|
||||
let translated_message =
|
||||
|
@ -344,7 +346,7 @@ impl Diagnostic {
|
|||
let code = if let Some(code) = diag.code {
|
||||
Some(DiagnosticCode {
|
||||
code: code.to_string(),
|
||||
explanation: je.registry.as_ref().unwrap().try_find_description(code).ok(),
|
||||
explanation: registry.try_find_description(code).ok(),
|
||||
})
|
||||
} else if let Some(IsLint { name, .. }) = &diag.is_lint {
|
||||
Some(DiagnosticCode { code: name.to_string(), explanation: None })
|
||||
|
@ -382,7 +384,7 @@ impl Diagnostic {
|
|||
} else {
|
||||
OutputTheme::Ascii
|
||||
})
|
||||
.emit_diagnostic(diag);
|
||||
.emit_diagnostic(diag, registry);
|
||||
let buf = Arc::try_unwrap(buf.0).unwrap().into_inner().unwrap();
|
||||
let buf = String::from_utf8(buf).unwrap();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue