diff options
| author | Yacin Tmimi <yacintmimi@gmail.com> | 2024-03-19 12:58:23 -0400 |
|---|---|---|
| committer | Yacin Tmimi <yacintmimi@gmail.com> | 2024-03-19 13:48:07 -0400 |
| commit | d49d136b3a0e9749e4aa517b7aa6490752444cf7 (patch) | |
| tree | f5313908038b97c3f06aeb6103ffb5eb2c2e2ae8 /compiler | |
| parent | 200e3f7995e231535fdea3be9cb9a3f098b4c856 (diff) | |
| download | rust-d49d136b3a0e9749e4aa517b7aa6490752444cf7.tar.gz rust-d49d136b3a0e9749e4aa517b7aa6490752444cf7.zip | |
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.
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_errors/src/emitter.rs | 3 | ||||
| -rw-r--r-- | compiler/rustc_errors/src/lib.rs | 8 | ||||
| -rw-r--r-- | compiler/rustc_interface/src/interface.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_session/src/parse.rs | 7 |
4 files changed, 17 insertions, 3 deletions
diff --git a/compiler/rustc_errors/src/emitter.rs b/compiler/rustc_errors/src/emitter.rs index 4f033e3fefa..f5d275fc452 100644 --- a/compiler/rustc_errors/src/emitter.rs +++ b/compiler/rustc_errors/src/emitter.rs @@ -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()); } diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index 723f13dbe8d..ff5e1948db8 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -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, }) }); } diff --git a/compiler/rustc_interface/src/interface.rs b/compiler/rustc_interface/src/interface.rs index 1a82e6c6910..edf52fe8c34 100644 --- a/compiler/rustc_interface/src/interface.rs +++ b/compiler/rustc_interface/src/interface.rs @@ -48,6 +48,7 @@ pub(crate) fn parse_cfg(dcx: &DiagCtxt, cfgs: Vec<String>) -> Cfg { let psess = ParseSess::with_silent_emitter( vec![crate::DEFAULT_LOCALE_RESOURCE, rustc_parse::DEFAULT_LOCALE_RESOURCE], format!("this error occurred on the command line: `--cfg={s}`"), + true, ); 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( vec![crate::DEFAULT_LOCALE_RESOURCE, rustc_parse::DEFAULT_LOCALE_RESOURCE], format!("this error occurred on the command line: `--check-cfg={s}`"), + true, ); let filename = FileName::cfg_spec_source_code(&s); diff --git a/compiler/rustc_session/src/parse.rs b/compiler/rustc_session/src/parse.rs index 5434bbe0b98..f6053f43fbd 100644 --- a/compiler/rustc_session/src/parse.rs +++ b/compiler/rustc_session/src/parse.rs @@ -269,7 +269,11 @@ impl ParseSess { } } - 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 sm = Lrc::new(SourceMap::new(FilePathMapping::empty())); let emitter = Box::new(HumanEmitter::new( @@ -281,6 +285,7 @@ impl ParseSess { fallback_bundle, fatal_dcx, fatal_note: Some(fatal_note), + emit_fatal_diagnostic, })) .disable_warnings(); ParseSess::with_dcx(dcx, sm) |
