Rollup merge of #122737 - ytmimi:conditionally_ignore_fatal_diagnostic, r=davidtwco
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 #121301 the `SilentEmitter` was shared between rustc and rustfmt. This changed rustfmt's behavior from ignoring all diagnostic to emitting fatal diagnostics, which lead to https://github.com/rust-lang/rustfmt/issues/6109. These changes allow rustfmt to maintain its previous behaviour when using the `SilentEmitter`, while allowing rustc code to still emit fatal diagnostics.
This commit is contained in:
commit
3fe9f66133
@ -541,6 +541,7 @@ pub struct SilentEmitter {
|
|||||||
pub fallback_bundle: LazyFallbackBundle,
|
pub fallback_bundle: LazyFallbackBundle,
|
||||||
pub fatal_dcx: DiagCtxt,
|
pub fatal_dcx: DiagCtxt,
|
||||||
pub fatal_note: Option<String>,
|
pub fatal_note: Option<String>,
|
||||||
|
pub emit_fatal_diagnostic: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Translate for SilentEmitter {
|
impl Translate for SilentEmitter {
|
||||||
@ -561,7 +562,7 @@ fn source_map(&self) -> Option<&Lrc<SourceMap>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn emit_diagnostic(&mut self, mut diag: DiagInner) {
|
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 {
|
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());
|
||||||
}
|
}
|
||||||
|
@ -612,12 +612,18 @@ pub fn new(emitter: Box<DynEmitter>) -> Self {
|
|||||||
Self { inner: Lock::new(DiagCtxtInner::new(emitter)) }
|
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| {
|
self.wrap_emitter(|old_dcx| {
|
||||||
Box::new(emitter::SilentEmitter {
|
Box::new(emitter::SilentEmitter {
|
||||||
fallback_bundle,
|
fallback_bundle,
|
||||||
fatal_dcx: DiagCtxt { inner: Lock::new(old_dcx) },
|
fatal_dcx: DiagCtxt { inner: Lock::new(old_dcx) },
|
||||||
fatal_note,
|
fatal_note,
|
||||||
|
emit_fatal_diagnostic,
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -48,6 +48,7 @@ pub(crate) fn parse_cfg(dcx: &DiagCtxt, cfgs: Vec<String>) -> Cfg {
|
|||||||
let psess = ParseSess::with_silent_emitter(
|
let psess = ParseSess::with_silent_emitter(
|
||||||
vec![crate::DEFAULT_LOCALE_RESOURCE, rustc_parse::DEFAULT_LOCALE_RESOURCE],
|
vec![crate::DEFAULT_LOCALE_RESOURCE, rustc_parse::DEFAULT_LOCALE_RESOURCE],
|
||||||
format!("this error occurred on the command line: `--cfg={s}`"),
|
format!("this error occurred on the command line: `--cfg={s}`"),
|
||||||
|
true,
|
||||||
);
|
);
|
||||||
let filename = FileName::cfg_spec_source_code(&s);
|
let filename = FileName::cfg_spec_source_code(&s);
|
||||||
|
|
||||||
@ -111,6 +112,7 @@ pub(crate) fn parse_check_cfg(dcx: &DiagCtxt, specs: Vec<String>) -> CheckCfg {
|
|||||||
let psess = ParseSess::with_silent_emitter(
|
let psess = ParseSess::with_silent_emitter(
|
||||||
vec![crate::DEFAULT_LOCALE_RESOURCE, rustc_parse::DEFAULT_LOCALE_RESOURCE],
|
vec![crate::DEFAULT_LOCALE_RESOURCE, rustc_parse::DEFAULT_LOCALE_RESOURCE],
|
||||||
format!("this error occurred on the command line: `--check-cfg={s}`"),
|
format!("this error occurred on the command line: `--check-cfg={s}`"),
|
||||||
|
true,
|
||||||
);
|
);
|
||||||
let filename = FileName::cfg_spec_source_code(&s);
|
let filename = FileName::cfg_spec_source_code(&s);
|
||||||
|
|
||||||
|
@ -269,7 +269,11 @@ pub fn with_dcx(dcx: DiagCtxt, source_map: Lrc<SourceMap>) -> Self {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn with_silent_emitter(locale_resources: Vec<&'static str>, fatal_note: String) -> Self {
|
pub fn with_silent_emitter(
|
||||||
|
locale_resources: Vec<&'static str>,
|
||||||
|
fatal_note: String,
|
||||||
|
emit_fatal_diagnostic: bool,
|
||||||
|
) -> Self {
|
||||||
let fallback_bundle = fallback_fluent_bundle(locale_resources, false);
|
let fallback_bundle = fallback_fluent_bundle(locale_resources, false);
|
||||||
let sm = Lrc::new(SourceMap::new(FilePathMapping::empty()));
|
let sm = Lrc::new(SourceMap::new(FilePathMapping::empty()));
|
||||||
let emitter = Box::new(HumanEmitter::new(
|
let emitter = Box::new(HumanEmitter::new(
|
||||||
@ -281,6 +285,7 @@ pub fn with_silent_emitter(locale_resources: Vec<&'static str>, fatal_note: Stri
|
|||||||
fallback_bundle,
|
fallback_bundle,
|
||||||
fatal_dcx,
|
fatal_dcx,
|
||||||
fatal_note: Some(fatal_note),
|
fatal_note: Some(fatal_note),
|
||||||
|
emit_fatal_diagnostic,
|
||||||
}))
|
}))
|
||||||
.disable_warnings();
|
.disable_warnings();
|
||||||
ParseSess::with_dcx(dcx, sm)
|
ParseSess::with_dcx(dcx, sm)
|
||||||
|
@ -121,6 +121,7 @@ fn default_dcx(
|
|||||||
fallback_bundle,
|
fallback_bundle,
|
||||||
fatal_dcx: DiagCtxt::new(emitter),
|
fatal_dcx: DiagCtxt::new(emitter),
|
||||||
fatal_note: None,
|
fatal_note: None,
|
||||||
|
emit_fatal_diagnostic: false,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
emitter
|
emitter
|
||||||
@ -209,7 +210,7 @@ pub(crate) fn set_silent_emitter(&mut self) {
|
|||||||
rustc_driver::DEFAULT_LOCALE_RESOURCES.to_vec(),
|
rustc_driver::DEFAULT_LOCALE_RESOURCES.to_vec(),
|
||||||
false,
|
false,
|
||||||
);
|
);
|
||||||
self.raw_psess.dcx.make_silent(fallback_bundle, None);
|
self.raw_psess.dcx.make_silent(fallback_bundle, None, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn span_to_filename(&self, span: Span) -> FileName {
|
pub(crate) fn span_to_filename(&self, span: Span) -> FileName {
|
||||||
|
Loading…
Reference in New Issue
Block a user