conditionally ignore fatal diagnostic in the SilentEmitter
This change is primarily meant to allow rustfmt to ignore all diagnostics when using the `SilentEmitter`. Back in PR 121301 the `SilentEmitter` was shared between rustc and rustfmt. This changed rustfmt's behavior from ignoring all diagnostic to emitting fatal diagnostics. These changes allow rustfmt to maintain it's previous behaviour when using the SilentEmitter, while allowing rustc code to still emit fatal diagnostics.
This commit is contained in:
parent
200e3f7995
commit
d49d136b3a
5 changed files with 19 additions and 4 deletions
|
@ -541,6 +541,7 @@ pub struct SilentEmitter {
|
|||
pub fallback_bundle: LazyFallbackBundle,
|
||||
pub fatal_dcx: DiagCtxt,
|
||||
pub fatal_note: Option<String>,
|
||||
pub emit_fatal_diagnostic: bool,
|
||||
}
|
||||
|
||||
impl Translate for SilentEmitter {
|
||||
|
@ -561,7 +562,7 @@ impl Emitter for SilentEmitter {
|
|||
}
|
||||
|
||||
fn emit_diagnostic(&mut self, mut diag: DiagInner) {
|
||||
if diag.level == Level::Fatal {
|
||||
if self.emit_fatal_diagnostic && diag.level == Level::Fatal {
|
||||
if let Some(fatal_note) = &self.fatal_note {
|
||||
diag.sub(Level::Note, fatal_note.clone(), MultiSpan::new());
|
||||
}
|
||||
|
|
|
@ -613,12 +613,18 @@ impl DiagCtxt {
|
|||
Self { inner: Lock::new(DiagCtxtInner::new(emitter)) }
|
||||
}
|
||||
|
||||
pub fn make_silent(&mut self, fallback_bundle: LazyFallbackBundle, fatal_note: Option<String>) {
|
||||
pub fn make_silent(
|
||||
&mut self,
|
||||
fallback_bundle: LazyFallbackBundle,
|
||||
fatal_note: Option<String>,
|
||||
emit_fatal_diagnostic: bool,
|
||||
) {
|
||||
self.wrap_emitter(|old_dcx| {
|
||||
Box::new(emitter::SilentEmitter {
|
||||
fallback_bundle,
|
||||
fatal_dcx: DiagCtxt { inner: Lock::new(old_dcx) },
|
||||
fatal_note,
|
||||
emit_fatal_diagnostic,
|
||||
})
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue