diff options
| author | bjorn3 <17426603+bjorn3@users.noreply.github.com> | 2025-02-02 15:36:28 +0000 |
|---|---|---|
| committer | bjorn3 <17426603+bjorn3@users.noreply.github.com> | 2025-02-02 16:06:43 +0000 |
| commit | 6556147d15f077dfc88dae22f3983b3598bce465 (patch) | |
| tree | 0ca8b89e687a856423d336ff1c7b41141bc1e216 | |
| parent | aa2b870bb59a1eb6af3ee35567291a0f8c8a2828 (diff) | |
| download | rust-6556147d15f077dfc88dae22f3983b3598bce465.tar.gz rust-6556147d15f077dfc88dae22f3983b3598bce465.zip | |
Use fallback fluent bundle from inner emitter in SilentEmitter
| -rw-r--r-- | compiler/rustc_errors/src/emitter.rs | 5 | ||||
| -rw-r--r-- | compiler/rustc_errors/src/lib.rs | 8 | ||||
| -rw-r--r-- | compiler/rustc_session/src/parse.rs | 7 | ||||
| -rw-r--r-- | src/tools/rustfmt/src/parse/session.rs | 14 |
4 files changed, 6 insertions, 28 deletions
diff --git a/compiler/rustc_errors/src/emitter.rs b/compiler/rustc_errors/src/emitter.rs index 050088d95ba..d0b4211c351 100644 --- a/compiler/rustc_errors/src/emitter.rs +++ b/compiler/rustc_errors/src/emitter.rs @@ -540,7 +540,6 @@ impl Emitter for HumanEmitter { /// Fatal diagnostics are forwarded to `fatal_emitter` to avoid silent /// failures of rustc, as witnessed e.g. in issue #89358. pub struct SilentEmitter { - pub fallback_bundle: LazyFallbackBundle, pub fatal_emitter: Box<dyn Emitter + DynSend>, pub fatal_note: Option<String>, pub emit_fatal_diagnostic: bool, @@ -552,9 +551,7 @@ impl Translate for SilentEmitter { } fn fallback_fluent_bundle(&self) -> &FluentBundle { - // Ideally this field wouldn't be necessary and the fallback bundle in `fatal_dcx` would be - // used but the lock prevents this. - &self.fallback_bundle + self.fatal_emitter.fallback_fluent_bundle() } } diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index 41862330458..e64bb003dde 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -676,12 +676,7 @@ impl DiagCtxt { Self { inner: Lock::new(DiagCtxtInner::new(emitter)) } } - pub fn make_silent( - &self, - fallback_bundle: LazyFallbackBundle, - fatal_note: Option<String>, - emit_fatal_diagnostic: bool, - ) { + pub fn make_silent(&self, fatal_note: Option<String>, emit_fatal_diagnostic: bool) { // An empty type that implements `Emitter` to temporarily swap in place of the real one, // which will be used in constructing its replacement. struct FalseEmitter; @@ -710,7 +705,6 @@ impl DiagCtxt { let mut prev_emitter = Box::new(FalseEmitter) as Box<dyn Emitter + DynSend>; std::mem::swap(&mut inner.emitter, &mut prev_emitter); let new_emitter = Box::new(emitter::SilentEmitter { - fallback_bundle, fatal_emitter: prev_emitter, fatal_note, emit_fatal_diagnostic, diff --git a/compiler/rustc_session/src/parse.rs b/compiler/rustc_session/src/parse.rs index 0c8040944fb..b6b13a715ec 100644 --- a/compiler/rustc_session/src/parse.rs +++ b/compiler/rustc_session/src/parse.rs @@ -277,12 +277,9 @@ impl ParseSess { ) -> Self { let fallback_bundle = fallback_fluent_bundle(locale_resources, false); let sm = Lrc::new(SourceMap::new(FilePathMapping::empty())); - let fatal_emitter = Box::new(HumanEmitter::new( - stderr_destination(ColorConfig::Auto), - Lrc::clone(&fallback_bundle), - )); + let fatal_emitter = + Box::new(HumanEmitter::new(stderr_destination(ColorConfig::Auto), fallback_bundle)); let dcx = DiagCtxt::new(Box::new(SilentEmitter { - fallback_bundle, fatal_emitter, fatal_note: Some(fatal_note), emit_fatal_diagnostic, diff --git a/src/tools/rustfmt/src/parse/session.rs b/src/tools/rustfmt/src/parse/session.rs index d1a2974a617..34077c5f866 100644 --- a/src/tools/rustfmt/src/parse/session.rs +++ b/src/tools/rustfmt/src/parse/session.rs @@ -114,13 +114,12 @@ fn default_dcx( false, ); let emitter = Box::new( - HumanEmitter::new(stderr_destination(emit_color), fallback_bundle.clone()) + HumanEmitter::new(stderr_destination(emit_color), fallback_bundle) .sm(Some(source_map.clone())), ); let emitter: Box<DynEmitter> = if !show_parse_errors { Box::new(SilentEmitter { - fallback_bundle, fatal_emitter: emitter, fatal_note: None, emit_fatal_diagnostic: false, @@ -205,16 +204,7 @@ impl ParseSess { } pub(crate) fn set_silent_emitter(&mut self) { - // Ideally this invocation wouldn't be necessary and the fallback bundle in - // `self.parse_sess.dcx` could be used, but the lock in `DiagCtxt` prevents this. - // See `<rustc_errors::SilentEmitter as Translate>::fallback_fluent_bundle`. - let fallback_bundle = rustc_errors::fallback_fluent_bundle( - rustc_driver::DEFAULT_LOCALE_RESOURCES.to_vec(), - false, - ); - self.raw_psess - .dcx() - .make_silent(fallback_bundle, None, false); + self.raw_psess.dcx().make_silent(None, false); } pub(crate) fn span_to_filename(&self, span: Span) -> FileName { |
