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
|
@ -1883,7 +1883,11 @@ impl Translate for SharedEmitter {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Emitter for SharedEmitter {
|
impl Emitter for SharedEmitter {
|
||||||
fn emit_diagnostic(&mut self, mut diag: rustc_errors::DiagInner) {
|
fn emit_diagnostic(
|
||||||
|
&mut self,
|
||||||
|
mut diag: rustc_errors::DiagInner,
|
||||||
|
_registry: &rustc_errors::registry::Registry,
|
||||||
|
) {
|
||||||
// Check that we aren't missing anything interesting when converting to
|
// Check that we aren't missing anything interesting when converting to
|
||||||
// the cut-down local `DiagInner`.
|
// the cut-down local `DiagInner`.
|
||||||
assert_eq!(diag.span, MultiSpan::new());
|
assert_eq!(diag.span, MultiSpan::new());
|
||||||
|
|
|
@ -12,6 +12,7 @@ use rustc_span::SourceFile;
|
||||||
use rustc_span::source_map::SourceMap;
|
use rustc_span::source_map::SourceMap;
|
||||||
|
|
||||||
use crate::emitter::FileWithAnnotatedLines;
|
use crate::emitter::FileWithAnnotatedLines;
|
||||||
|
use crate::registry::Registry;
|
||||||
use crate::snippet::Line;
|
use crate::snippet::Line;
|
||||||
use crate::translation::{Translate, to_fluent_args};
|
use crate::translation::{Translate, to_fluent_args};
|
||||||
use crate::{
|
use crate::{
|
||||||
|
@ -45,7 +46,7 @@ impl Translate for AnnotateSnippetEmitter {
|
||||||
|
|
||||||
impl Emitter for AnnotateSnippetEmitter {
|
impl Emitter for AnnotateSnippetEmitter {
|
||||||
/// The entry point for the diagnostics generation
|
/// The entry point for the diagnostics generation
|
||||||
fn emit_diagnostic(&mut self, mut diag: DiagInner) {
|
fn emit_diagnostic(&mut self, mut diag: DiagInner, _registry: &Registry) {
|
||||||
let fluent_args = to_fluent_args(diag.args.iter());
|
let fluent_args = to_fluent_args(diag.args.iter());
|
||||||
|
|
||||||
let mut suggestions = diag.suggestions.unwrap_tag();
|
let mut suggestions = diag.suggestions.unwrap_tag();
|
||||||
|
|
|
@ -27,6 +27,7 @@ use termcolor::{Buffer, BufferWriter, Color, ColorChoice, ColorSpec, StandardStr
|
||||||
use tracing::{debug, instrument, trace, warn};
|
use tracing::{debug, instrument, trace, warn};
|
||||||
|
|
||||||
use crate::diagnostic::DiagLocation;
|
use crate::diagnostic::DiagLocation;
|
||||||
|
use crate::registry::Registry;
|
||||||
use crate::snippet::{
|
use crate::snippet::{
|
||||||
Annotation, AnnotationColumn, AnnotationType, Line, MultilineAnnotation, Style, StyledString,
|
Annotation, AnnotationColumn, AnnotationType, Line, MultilineAnnotation, Style, StyledString,
|
||||||
};
|
};
|
||||||
|
@ -181,7 +182,7 @@ pub type DynEmitter = dyn Emitter + DynSend;
|
||||||
/// Emitter trait for emitting errors.
|
/// Emitter trait for emitting errors.
|
||||||
pub trait Emitter: Translate {
|
pub trait Emitter: Translate {
|
||||||
/// Emit a structured diagnostic.
|
/// Emit a structured diagnostic.
|
||||||
fn emit_diagnostic(&mut self, diag: DiagInner);
|
fn emit_diagnostic(&mut self, diag: DiagInner, registry: &Registry);
|
||||||
|
|
||||||
/// Emit a notification that an artifact has been output.
|
/// Emit a notification that an artifact has been output.
|
||||||
/// Currently only supported for the JSON format.
|
/// Currently only supported for the JSON format.
|
||||||
|
@ -189,7 +190,7 @@ pub trait Emitter: Translate {
|
||||||
|
|
||||||
/// Emit a report about future breakage.
|
/// Emit a report about future breakage.
|
||||||
/// Currently only supported for the JSON format.
|
/// Currently only supported for the JSON format.
|
||||||
fn emit_future_breakage_report(&mut self, _diags: Vec<DiagInner>) {}
|
fn emit_future_breakage_report(&mut self, _diags: Vec<DiagInner>, _registry: &Registry) {}
|
||||||
|
|
||||||
/// Emit list of unused externs.
|
/// Emit list of unused externs.
|
||||||
/// Currently only supported for the JSON format.
|
/// Currently only supported for the JSON format.
|
||||||
|
@ -500,7 +501,7 @@ impl Emitter for HumanEmitter {
|
||||||
self.sm.as_deref()
|
self.sm.as_deref()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn emit_diagnostic(&mut self, mut diag: DiagInner) {
|
fn emit_diagnostic(&mut self, mut diag: DiagInner, _registry: &Registry) {
|
||||||
let fluent_args = to_fluent_args(diag.args.iter());
|
let fluent_args = to_fluent_args(diag.args.iter());
|
||||||
|
|
||||||
let mut suggestions = diag.suggestions.unwrap_tag();
|
let mut suggestions = diag.suggestions.unwrap_tag();
|
||||||
|
@ -561,7 +562,7 @@ impl Emitter for SilentEmitter {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
fn emit_diagnostic(&mut self, mut diag: DiagInner) {
|
fn emit_diagnostic(&mut self, mut diag: DiagInner, _registry: &Registry) {
|
||||||
if self.emit_fatal_diagnostic && diag.level == Level::Fatal {
|
if self.emit_fatal_diagnostic && diag.level == Level::Fatal {
|
||||||
if let Some(fatal_note) = &self.fatal_note {
|
if let Some(fatal_note) = &self.fatal_note {
|
||||||
diag.sub(Level::Note, fatal_note.clone(), MultiSpan::new());
|
diag.sub(Level::Note, fatal_note.clone(), MultiSpan::new());
|
||||||
|
|
|
@ -44,7 +44,6 @@ mod tests;
|
||||||
pub struct JsonEmitter {
|
pub struct JsonEmitter {
|
||||||
#[setters(skip)]
|
#[setters(skip)]
|
||||||
dst: IntoDynSyncSend<Box<dyn Write + Send>>,
|
dst: IntoDynSyncSend<Box<dyn Write + Send>>,
|
||||||
registry: Option<Registry>,
|
|
||||||
#[setters(skip)]
|
#[setters(skip)]
|
||||||
sm: Lrc<SourceMap>,
|
sm: Lrc<SourceMap>,
|
||||||
fluent_bundle: Option<Lrc<FluentBundle>>,
|
fluent_bundle: Option<Lrc<FluentBundle>>,
|
||||||
|
@ -74,7 +73,6 @@ impl JsonEmitter {
|
||||||
) -> JsonEmitter {
|
) -> JsonEmitter {
|
||||||
JsonEmitter {
|
JsonEmitter {
|
||||||
dst: IntoDynSyncSend(dst),
|
dst: IntoDynSyncSend(dst),
|
||||||
registry: None,
|
|
||||||
sm,
|
sm,
|
||||||
fluent_bundle: None,
|
fluent_bundle: None,
|
||||||
fallback_bundle,
|
fallback_bundle,
|
||||||
|
@ -121,8 +119,8 @@ impl Translate for JsonEmitter {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Emitter for JsonEmitter {
|
impl Emitter for JsonEmitter {
|
||||||
fn emit_diagnostic(&mut self, diag: crate::DiagInner) {
|
fn emit_diagnostic(&mut self, diag: crate::DiagInner, registry: &Registry) {
|
||||||
let data = Diagnostic::from_errors_diagnostic(diag, self);
|
let data = Diagnostic::from_errors_diagnostic(diag, self, registry);
|
||||||
let result = self.emit(EmitTyped::Diagnostic(data));
|
let result = self.emit(EmitTyped::Diagnostic(data));
|
||||||
if let Err(e) = result {
|
if let Err(e) = result {
|
||||||
panic!("failed to print diagnostics: {e:?}");
|
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
|
let data: Vec<FutureBreakageItem<'_>> = diags
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|mut diag| {
|
.map(|mut diag| {
|
||||||
|
@ -151,7 +149,7 @@ impl Emitter for JsonEmitter {
|
||||||
}
|
}
|
||||||
FutureBreakageItem {
|
FutureBreakageItem {
|
||||||
diagnostic: EmitTyped::Diagnostic(Diagnostic::from_errors_diagnostic(
|
diagnostic: EmitTyped::Diagnostic(Diagnostic::from_errors_diagnostic(
|
||||||
diag, self,
|
diag, self, registry,
|
||||||
)),
|
)),
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -291,7 +289,11 @@ struct UnusedExterns<'a> {
|
||||||
|
|
||||||
impl Diagnostic {
|
impl Diagnostic {
|
||||||
/// Converts from `rustc_errors::DiagInner` to `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 args = to_fluent_args(diag.args.iter());
|
||||||
let sugg_to_diag = |sugg: &CodeSuggestion| {
|
let sugg_to_diag = |sugg: &CodeSuggestion| {
|
||||||
let translated_message =
|
let translated_message =
|
||||||
|
@ -344,7 +346,7 @@ impl Diagnostic {
|
||||||
let code = if let Some(code) = diag.code {
|
let code = if let Some(code) = diag.code {
|
||||||
Some(DiagnosticCode {
|
Some(DiagnosticCode {
|
||||||
code: code.to_string(),
|
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 {
|
} else if let Some(IsLint { name, .. }) = &diag.is_lint {
|
||||||
Some(DiagnosticCode { code: name.to_string(), explanation: None })
|
Some(DiagnosticCode { code: name.to_string(), explanation: None })
|
||||||
|
@ -382,7 +384,7 @@ impl Diagnostic {
|
||||||
} else {
|
} else {
|
||||||
OutputTheme::Ascii
|
OutputTheme::Ascii
|
||||||
})
|
})
|
||||||
.emit_diagnostic(diag);
|
.emit_diagnostic(diag, registry);
|
||||||
let buf = Arc::try_unwrap(buf.0).unwrap().into_inner().unwrap();
|
let buf = Arc::try_unwrap(buf.0).unwrap().into_inner().unwrap();
|
||||||
let buf = String::from_utf8(buf).unwrap();
|
let buf = String::from_utf8(buf).unwrap();
|
||||||
|
|
||||||
|
|
|
@ -55,7 +55,6 @@ pub use diagnostic_impls::{
|
||||||
};
|
};
|
||||||
pub use emitter::ColorConfig;
|
pub use emitter::ColorConfig;
|
||||||
use emitter::{DynEmitter, Emitter, is_case_difference, is_different};
|
use emitter::{DynEmitter, Emitter, is_case_difference, is_different};
|
||||||
use registry::Registry;
|
|
||||||
use rustc_data_structures::AtomicRef;
|
use rustc_data_structures::AtomicRef;
|
||||||
use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet};
|
use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet};
|
||||||
use rustc_data_structures::stable_hasher::{Hash128, StableHasher};
|
use rustc_data_structures::stable_hasher::{Hash128, StableHasher};
|
||||||
|
@ -77,6 +76,8 @@ pub use snippet::Style;
|
||||||
pub use termcolor::{Color, ColorSpec, WriteColor};
|
pub use termcolor::{Color, ColorSpec, WriteColor};
|
||||||
use tracing::debug;
|
use tracing::debug;
|
||||||
|
|
||||||
|
use crate::registry::Registry;
|
||||||
|
|
||||||
pub mod annotate_snippet_emitter_writer;
|
pub mod annotate_snippet_emitter_writer;
|
||||||
pub mod codes;
|
pub mod codes;
|
||||||
mod diagnostic;
|
mod diagnostic;
|
||||||
|
@ -483,6 +484,8 @@ impl<'a> std::ops::Deref for DiagCtxtHandle<'a> {
|
||||||
struct DiagCtxtInner {
|
struct DiagCtxtInner {
|
||||||
flags: DiagCtxtFlags,
|
flags: DiagCtxtFlags,
|
||||||
|
|
||||||
|
registry: Registry,
|
||||||
|
|
||||||
/// The error guarantees from all emitted errors. The length gives the error count.
|
/// The error guarantees from all emitted errors. The length gives the error count.
|
||||||
err_guars: Vec<ErrorGuaranteed>,
|
err_guars: Vec<ErrorGuaranteed>,
|
||||||
/// The error guarantee from all emitted lint errors. The length gives the
|
/// The error guarantee from all emitted lint errors. The length gives the
|
||||||
|
@ -664,6 +667,11 @@ impl DiagCtxt {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn with_registry(mut self, registry: Registry) -> Self {
|
||||||
|
self.inner.get_mut().registry = registry;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
pub fn new(emitter: Box<DynEmitter>) -> Self {
|
pub fn new(emitter: Box<DynEmitter>) -> Self {
|
||||||
Self { inner: Lock::new(DiagCtxtInner::new(emitter)) }
|
Self { inner: Lock::new(DiagCtxtInner::new(emitter)) }
|
||||||
}
|
}
|
||||||
|
@ -694,7 +702,7 @@ impl DiagCtxt {
|
||||||
struct FalseEmitter;
|
struct FalseEmitter;
|
||||||
|
|
||||||
impl Emitter for 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`")
|
unimplemented!("false emitter must only used during `wrap_emitter`")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -759,6 +767,7 @@ impl DiagCtxt {
|
||||||
let mut inner = self.inner.borrow_mut();
|
let mut inner = self.inner.borrow_mut();
|
||||||
let DiagCtxtInner {
|
let DiagCtxtInner {
|
||||||
flags: _,
|
flags: _,
|
||||||
|
registry: _,
|
||||||
err_guars,
|
err_guars,
|
||||||
lint_err_guars,
|
lint_err_guars,
|
||||||
delayed_bugs,
|
delayed_bugs,
|
||||||
|
@ -964,7 +973,7 @@ impl<'a> DiagCtxtHandle<'a> {
|
||||||
self.inner.borrow().has_errors_or_delayed_bugs()
|
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();
|
let mut inner = self.inner.borrow_mut();
|
||||||
|
|
||||||
// Any stashed diagnostics should have been handled by
|
// Any stashed diagnostics should have been handled by
|
||||||
|
@ -1014,7 +1023,7 @@ impl<'a> DiagCtxtHandle<'a> {
|
||||||
.emitted_diagnostic_codes
|
.emitted_diagnostic_codes
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|&code| {
|
.filter_map(|&code| {
|
||||||
if registry.try_find_description(code).is_ok() {
|
if inner.registry.try_find_description(code).is_ok() {
|
||||||
Some(code.to_string())
|
Some(code.to_string())
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
@ -1075,10 +1084,10 @@ impl<'a> DiagCtxtHandle<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn emit_future_breakage_report(&self) {
|
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);
|
let diags = std::mem::take(&mut inner.future_breakage_diagnostics);
|
||||||
if !diags.is_empty() {
|
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 {
|
fn new(emitter: Box<DynEmitter>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
flags: DiagCtxtFlags { can_emit_warnings: true, ..Default::default() },
|
flags: DiagCtxtFlags { can_emit_warnings: true, ..Default::default() },
|
||||||
|
registry: Registry::new(&[]),
|
||||||
err_guars: Vec::new(),
|
err_guars: Vec::new(),
|
||||||
lint_err_guars: Vec::new(),
|
lint_err_guars: Vec::new(),
|
||||||
delayed_bugs: Vec::new(),
|
delayed_bugs: Vec::new(),
|
||||||
|
@ -1582,7 +1592,7 @@ impl DiagCtxtInner {
|
||||||
}
|
}
|
||||||
self.has_printed = true;
|
self.has_printed = true;
|
||||||
|
|
||||||
self.emitter.emit_diagnostic(diagnostic);
|
self.emitter.emit_diagnostic(diagnostic, &self.registry);
|
||||||
}
|
}
|
||||||
|
|
||||||
if is_error {
|
if is_error {
|
||||||
|
|
|
@ -441,7 +441,7 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se
|
||||||
temps_dir,
|
temps_dir,
|
||||||
},
|
},
|
||||||
bundle,
|
bundle,
|
||||||
config.registry.clone(),
|
config.registry,
|
||||||
locale_resources,
|
locale_resources,
|
||||||
config.lint_caps,
|
config.lint_caps,
|
||||||
target,
|
target,
|
||||||
|
@ -499,7 +499,7 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se
|
||||||
// If `f` panics, `finish_diagnostics` will run during
|
// If `f` panics, `finish_diagnostics` will run during
|
||||||
// unwinding because of the `defer`.
|
// unwinding because of the `defer`.
|
||||||
let sess_abort_guard = defer(|| {
|
let sess_abort_guard = defer(|| {
|
||||||
compiler.sess.finish_diagnostics(&config.registry);
|
compiler.sess.finish_diagnostics();
|
||||||
});
|
});
|
||||||
|
|
||||||
let res = f(&compiler);
|
let res = f(&compiler);
|
||||||
|
|
|
@ -19,7 +19,6 @@ use rustc_errors::emitter::{
|
||||||
DynEmitter, HumanEmitter, HumanReadableErrorType, OutputTheme, stderr_destination,
|
DynEmitter, HumanEmitter, HumanReadableErrorType, OutputTheme, stderr_destination,
|
||||||
};
|
};
|
||||||
use rustc_errors::json::JsonEmitter;
|
use rustc_errors::json::JsonEmitter;
|
||||||
use rustc_errors::registry::Registry;
|
|
||||||
use rustc_errors::{
|
use rustc_errors::{
|
||||||
Diag, DiagCtxt, DiagCtxtHandle, DiagMessage, Diagnostic, ErrorGuaranteed, FatalAbort,
|
Diag, DiagCtxt, DiagCtxtHandle, DiagMessage, Diagnostic, ErrorGuaranteed, FatalAbort,
|
||||||
FluentBundle, LazyFallbackBundle, TerminalUrl, fallback_fluent_bundle,
|
FluentBundle, LazyFallbackBundle, TerminalUrl, fallback_fluent_bundle,
|
||||||
|
@ -276,11 +275,11 @@ impl Session {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Invoked all the way at the end to finish off diagnostics printing.
|
/// Invoked all the way at the end to finish off diagnostics printing.
|
||||||
pub fn finish_diagnostics(&self, registry: &Registry) -> Option<ErrorGuaranteed> {
|
pub fn finish_diagnostics(&self) -> Option<ErrorGuaranteed> {
|
||||||
let mut guar = None;
|
let mut guar = None;
|
||||||
guar = guar.or(self.check_miri_unleashed_features());
|
guar = guar.or(self.check_miri_unleashed_features());
|
||||||
guar = guar.or(self.dcx().emit_stashed_diagnostics());
|
guar = guar.or(self.dcx().emit_stashed_diagnostics());
|
||||||
self.dcx().print_error_count(registry);
|
self.dcx().print_error_count();
|
||||||
if self.opts.json_future_incompat {
|
if self.opts.json_future_incompat {
|
||||||
self.dcx().emit_future_breakage_report();
|
self.dcx().emit_future_breakage_report();
|
||||||
}
|
}
|
||||||
|
@ -880,7 +879,6 @@ impl Session {
|
||||||
#[allow(rustc::bad_opt_access)]
|
#[allow(rustc::bad_opt_access)]
|
||||||
fn default_emitter(
|
fn default_emitter(
|
||||||
sopts: &config::Options,
|
sopts: &config::Options,
|
||||||
registry: rustc_errors::registry::Registry,
|
|
||||||
source_map: Lrc<SourceMap>,
|
source_map: Lrc<SourceMap>,
|
||||||
bundle: Option<Lrc<FluentBundle>>,
|
bundle: Option<Lrc<FluentBundle>>,
|
||||||
fallback_bundle: LazyFallbackBundle,
|
fallback_bundle: LazyFallbackBundle,
|
||||||
|
@ -943,7 +941,6 @@ fn default_emitter(
|
||||||
json_rendered,
|
json_rendered,
|
||||||
color_config,
|
color_config,
|
||||||
)
|
)
|
||||||
.registry(Some(registry))
|
|
||||||
.fluent_bundle(bundle)
|
.fluent_bundle(bundle)
|
||||||
.ui_testing(sopts.unstable_opts.ui_testing)
|
.ui_testing(sopts.unstable_opts.ui_testing)
|
||||||
.ignored_directories_in_source_blocks(
|
.ignored_directories_in_source_blocks(
|
||||||
|
@ -999,11 +996,11 @@ pub fn build_session(
|
||||||
sopts.unstable_opts.translate_directionality_markers,
|
sopts.unstable_opts.translate_directionality_markers,
|
||||||
);
|
);
|
||||||
let source_map = rustc_span::source_map::get_source_map().unwrap();
|
let source_map = rustc_span::source_map::get_source_map().unwrap();
|
||||||
let emitter =
|
let emitter = default_emitter(&sopts, Lrc::clone(&source_map), bundle, fallback_bundle);
|
||||||
default_emitter(&sopts, registry, Lrc::clone(&source_map), bundle, fallback_bundle);
|
|
||||||
|
|
||||||
let mut dcx =
|
let mut dcx = DiagCtxt::new(emitter)
|
||||||
DiagCtxt::new(emitter).with_flags(sopts.unstable_opts.dcx_flags(can_emit_warnings));
|
.with_flags(sopts.unstable_opts.dcx_flags(can_emit_warnings))
|
||||||
|
.with_registry(registry);
|
||||||
if let Some(ice_file) = ice_file {
|
if let Some(ice_file) = ice_file {
|
||||||
dcx = dcx.with_ice_file(ice_file);
|
dcx = dcx.with_ice_file(ice_file);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
use rustc_data_structures::sync::{Lock, Lrc};
|
use rustc_data_structures::sync::{Lock, Lrc};
|
||||||
use rustc_errors::emitter::Emitter;
|
use rustc_errors::emitter::Emitter;
|
||||||
|
use rustc_errors::registry::Registry;
|
||||||
use rustc_errors::translation::{Translate, to_fluent_args};
|
use rustc_errors::translation::{Translate, to_fluent_args};
|
||||||
use rustc_errors::{Applicability, DiagCtxt, DiagInner, LazyFallbackBundle};
|
use rustc_errors::{Applicability, DiagCtxt, DiagInner, LazyFallbackBundle};
|
||||||
use rustc_parse::{source_str_to_stream, unwrap_or_emit_fatal};
|
use rustc_parse::{source_str_to_stream, unwrap_or_emit_fatal};
|
||||||
|
@ -155,7 +156,7 @@ impl Translate for BufferEmitter {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Emitter for BufferEmitter {
|
impl Emitter for BufferEmitter {
|
||||||
fn emit_diagnostic(&mut self, diag: DiagInner) {
|
fn emit_diagnostic(&mut self, diag: DiagInner, _registry: &Registry) {
|
||||||
let mut buffer = self.buffer.borrow_mut();
|
let mut buffer = self.buffer.borrow_mut();
|
||||||
|
|
||||||
let fluent_args = to_fluent_args(diag.args.iter());
|
let fluent_args = to_fluent_args(diag.args.iter());
|
||||||
|
|
|
@ -3,6 +3,7 @@ use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
|
|
||||||
use rustc_data_structures::sync::{IntoDynSyncSend, Lrc};
|
use rustc_data_structures::sync::{IntoDynSyncSend, Lrc};
|
||||||
use rustc_errors::emitter::{DynEmitter, Emitter, HumanEmitter, SilentEmitter, stderr_destination};
|
use rustc_errors::emitter::{DynEmitter, Emitter, HumanEmitter, SilentEmitter, stderr_destination};
|
||||||
|
use rustc_errors::registry::Registry;
|
||||||
use rustc_errors::translation::Translate;
|
use rustc_errors::translation::Translate;
|
||||||
use rustc_errors::{ColorConfig, Diag, DiagCtxt, DiagInner, Level as DiagnosticLevel};
|
use rustc_errors::{ColorConfig, Diag, DiagCtxt, DiagInner, Level as DiagnosticLevel};
|
||||||
use rustc_session::parse::ParseSess as RawParseSess;
|
use rustc_session::parse::ParseSess as RawParseSess;
|
||||||
|
@ -38,10 +39,10 @@ struct SilentOnIgnoredFilesEmitter {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SilentOnIgnoredFilesEmitter {
|
impl SilentOnIgnoredFilesEmitter {
|
||||||
fn handle_non_ignoreable_error(&mut self, diag: DiagInner) {
|
fn handle_non_ignoreable_error(&mut self, diag: DiagInner, registry: &Registry) {
|
||||||
self.has_non_ignorable_parser_errors = true;
|
self.has_non_ignorable_parser_errors = true;
|
||||||
self.can_reset.store(false, Ordering::Release);
|
self.can_reset.store(false, Ordering::Release);
|
||||||
self.emitter.emit_diagnostic(diag);
|
self.emitter.emit_diagnostic(diag, registry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,9 +61,9 @@ impl Emitter for SilentOnIgnoredFilesEmitter {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
fn emit_diagnostic(&mut self, diag: DiagInner) {
|
fn emit_diagnostic(&mut self, diag: DiagInner, registry: &Registry) {
|
||||||
if diag.level() == DiagnosticLevel::Fatal {
|
if diag.level() == DiagnosticLevel::Fatal {
|
||||||
return self.handle_non_ignoreable_error(diag);
|
return self.handle_non_ignoreable_error(diag, registry);
|
||||||
}
|
}
|
||||||
if let Some(primary_span) = &diag.span.primary_span() {
|
if let Some(primary_span) = &diag.span.primary_span() {
|
||||||
let file_name = self.source_map.span_to_filename(*primary_span);
|
let file_name = self.source_map.span_to_filename(*primary_span);
|
||||||
|
@ -80,7 +81,7 @@ impl Emitter for SilentOnIgnoredFilesEmitter {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
self.handle_non_ignoreable_error(diag);
|
self.handle_non_ignoreable_error(diag, registry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -358,7 +359,7 @@ mod tests {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
fn emit_diagnostic(&mut self, _diag: DiagInner) {
|
fn emit_diagnostic(&mut self, _diag: DiagInner, _registry: &Registry) {
|
||||||
self.num_emitted_errors.fetch_add(1, Ordering::Release);
|
self.num_emitted_errors.fetch_add(1, Ordering::Release);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -412,6 +413,7 @@ mod tests {
|
||||||
SourceMapFileName::Real(RealFileName::LocalPath(PathBuf::from("foo.rs"))),
|
SourceMapFileName::Real(RealFileName::LocalPath(PathBuf::from("foo.rs"))),
|
||||||
source,
|
source,
|
||||||
);
|
);
|
||||||
|
let registry = Registry::new(&[]);
|
||||||
let mut emitter = build_emitter(
|
let mut emitter = build_emitter(
|
||||||
Lrc::clone(&num_emitted_errors),
|
Lrc::clone(&num_emitted_errors),
|
||||||
Lrc::clone(&can_reset_errors),
|
Lrc::clone(&can_reset_errors),
|
||||||
|
@ -420,7 +422,7 @@ mod tests {
|
||||||
);
|
);
|
||||||
let span = MultiSpan::from_span(mk_sp(BytePos(0), BytePos(1)));
|
let span = MultiSpan::from_span(mk_sp(BytePos(0), BytePos(1)));
|
||||||
let fatal_diagnostic = build_diagnostic(DiagnosticLevel::Fatal, Some(span));
|
let fatal_diagnostic = build_diagnostic(DiagnosticLevel::Fatal, Some(span));
|
||||||
emitter.emit_diagnostic(fatal_diagnostic);
|
emitter.emit_diagnostic(fatal_diagnostic, ®istry);
|
||||||
assert_eq!(num_emitted_errors.load(Ordering::Acquire), 1);
|
assert_eq!(num_emitted_errors.load(Ordering::Acquire), 1);
|
||||||
assert_eq!(can_reset_errors.load(Ordering::Acquire), false);
|
assert_eq!(can_reset_errors.load(Ordering::Acquire), false);
|
||||||
}
|
}
|
||||||
|
@ -437,6 +439,7 @@ mod tests {
|
||||||
SourceMapFileName::Real(RealFileName::LocalPath(PathBuf::from("foo.rs"))),
|
SourceMapFileName::Real(RealFileName::LocalPath(PathBuf::from("foo.rs"))),
|
||||||
source,
|
source,
|
||||||
);
|
);
|
||||||
|
let registry = Registry::new(&[]);
|
||||||
let mut emitter = build_emitter(
|
let mut emitter = build_emitter(
|
||||||
Lrc::clone(&num_emitted_errors),
|
Lrc::clone(&num_emitted_errors),
|
||||||
Lrc::clone(&can_reset_errors),
|
Lrc::clone(&can_reset_errors),
|
||||||
|
@ -445,7 +448,7 @@ mod tests {
|
||||||
);
|
);
|
||||||
let span = MultiSpan::from_span(mk_sp(BytePos(0), BytePos(1)));
|
let span = MultiSpan::from_span(mk_sp(BytePos(0), BytePos(1)));
|
||||||
let non_fatal_diagnostic = build_diagnostic(DiagnosticLevel::Warning, Some(span));
|
let non_fatal_diagnostic = build_diagnostic(DiagnosticLevel::Warning, Some(span));
|
||||||
emitter.emit_diagnostic(non_fatal_diagnostic);
|
emitter.emit_diagnostic(non_fatal_diagnostic, ®istry);
|
||||||
assert_eq!(num_emitted_errors.load(Ordering::Acquire), 0);
|
assert_eq!(num_emitted_errors.load(Ordering::Acquire), 0);
|
||||||
assert_eq!(can_reset_errors.load(Ordering::Acquire), true);
|
assert_eq!(can_reset_errors.load(Ordering::Acquire), true);
|
||||||
}
|
}
|
||||||
|
@ -461,6 +464,7 @@ mod tests {
|
||||||
SourceMapFileName::Real(RealFileName::LocalPath(PathBuf::from("foo.rs"))),
|
SourceMapFileName::Real(RealFileName::LocalPath(PathBuf::from("foo.rs"))),
|
||||||
source,
|
source,
|
||||||
);
|
);
|
||||||
|
let registry = Registry::new(&[]);
|
||||||
let mut emitter = build_emitter(
|
let mut emitter = build_emitter(
|
||||||
Lrc::clone(&num_emitted_errors),
|
Lrc::clone(&num_emitted_errors),
|
||||||
Lrc::clone(&can_reset_errors),
|
Lrc::clone(&can_reset_errors),
|
||||||
|
@ -469,7 +473,7 @@ mod tests {
|
||||||
);
|
);
|
||||||
let span = MultiSpan::from_span(mk_sp(BytePos(0), BytePos(1)));
|
let span = MultiSpan::from_span(mk_sp(BytePos(0), BytePos(1)));
|
||||||
let non_fatal_diagnostic = build_diagnostic(DiagnosticLevel::Warning, Some(span));
|
let non_fatal_diagnostic = build_diagnostic(DiagnosticLevel::Warning, Some(span));
|
||||||
emitter.emit_diagnostic(non_fatal_diagnostic);
|
emitter.emit_diagnostic(non_fatal_diagnostic, ®istry);
|
||||||
assert_eq!(num_emitted_errors.load(Ordering::Acquire), 1);
|
assert_eq!(num_emitted_errors.load(Ordering::Acquire), 1);
|
||||||
assert_eq!(can_reset_errors.load(Ordering::Acquire), false);
|
assert_eq!(can_reset_errors.load(Ordering::Acquire), false);
|
||||||
}
|
}
|
||||||
|
@ -497,6 +501,7 @@ mod tests {
|
||||||
SourceMapFileName::Real(RealFileName::LocalPath(PathBuf::from("fatal.rs"))),
|
SourceMapFileName::Real(RealFileName::LocalPath(PathBuf::from("fatal.rs"))),
|
||||||
fatal_source,
|
fatal_source,
|
||||||
);
|
);
|
||||||
|
let registry = Registry::new(&[]);
|
||||||
let mut emitter = build_emitter(
|
let mut emitter = build_emitter(
|
||||||
Lrc::clone(&num_emitted_errors),
|
Lrc::clone(&num_emitted_errors),
|
||||||
Lrc::clone(&can_reset_errors),
|
Lrc::clone(&can_reset_errors),
|
||||||
|
@ -508,9 +513,9 @@ mod tests {
|
||||||
let bar_diagnostic = build_diagnostic(DiagnosticLevel::Warning, Some(bar_span));
|
let bar_diagnostic = build_diagnostic(DiagnosticLevel::Warning, Some(bar_span));
|
||||||
let foo_diagnostic = build_diagnostic(DiagnosticLevel::Warning, Some(foo_span));
|
let foo_diagnostic = build_diagnostic(DiagnosticLevel::Warning, Some(foo_span));
|
||||||
let fatal_diagnostic = build_diagnostic(DiagnosticLevel::Fatal, None);
|
let fatal_diagnostic = build_diagnostic(DiagnosticLevel::Fatal, None);
|
||||||
emitter.emit_diagnostic(bar_diagnostic);
|
emitter.emit_diagnostic(bar_diagnostic, ®istry);
|
||||||
emitter.emit_diagnostic(foo_diagnostic);
|
emitter.emit_diagnostic(foo_diagnostic, ®istry);
|
||||||
emitter.emit_diagnostic(fatal_diagnostic);
|
emitter.emit_diagnostic(fatal_diagnostic, ®istry);
|
||||||
assert_eq!(num_emitted_errors.load(Ordering::Acquire), 2);
|
assert_eq!(num_emitted_errors.load(Ordering::Acquire), 2);
|
||||||
assert_eq!(can_reset_errors.load(Ordering::Acquire), false);
|
assert_eq!(can_reset_errors.load(Ordering::Acquire), false);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue