diff options
| author | Cameron Steffen <cam.steffen94@gmail.com> | 2025-06-19 13:05:01 -0500 |
|---|---|---|
| committer | Cameron Steffen <cam.steffen94@gmail.com> | 2025-06-19 13:05:01 -0500 |
| commit | 3388d837850eebca505350bc25f017276551a955 (patch) | |
| tree | 0c7edf9d407568f08a8c955563bd5fa0681f1d9d /compiler/rustc_errors/src | |
| parent | 316f63bc48a9bfe26b2a8fc06e7eeef45ac2b7aa (diff) | |
| download | rust-3388d837850eebca505350bc25f017276551a955.tar.gz rust-3388d837850eebca505350bc25f017276551a955.zip | |
Extract SilentEmitter
Diffstat (limited to 'compiler/rustc_errors/src')
| -rw-r--r-- | compiler/rustc_errors/src/emitter.rs | 19 | ||||
| -rw-r--r-- | compiler/rustc_errors/src/lib.rs | 30 |
2 files changed, 20 insertions, 29 deletions
diff --git a/compiler/rustc_errors/src/emitter.rs b/compiler/rustc_errors/src/emitter.rs index 4464b45775a..e333de4b660 100644 --- a/compiler/rustc_errors/src/emitter.rs +++ b/compiler/rustc_errors/src/emitter.rs @@ -546,7 +546,6 @@ impl Emitter for HumanEmitter { pub struct FatalOnlyEmitter { pub fatal_emitter: Box<dyn Emitter + DynSend>, pub fatal_note: Option<String>, - pub emit_fatal_diagnostic: bool, } impl Emitter for FatalOnlyEmitter { @@ -555,7 +554,7 @@ impl Emitter for FatalOnlyEmitter { } fn emit_diagnostic(&mut self, mut diag: DiagInner, registry: &Registry) { - if self.emit_fatal_diagnostic && diag.level == Level::Fatal { + if diag.level == Level::Fatal { if let Some(fatal_note) = &self.fatal_note { diag.sub(Level::Note, fatal_note.clone(), MultiSpan::new()); } @@ -568,6 +567,22 @@ impl Emitter for FatalOnlyEmitter { } } +pub struct SilentEmitter { + pub translator: Translator, +} + +impl Emitter for SilentEmitter { + fn source_map(&self) -> Option<&SourceMap> { + None + } + + fn emit_diagnostic(&mut self, _diag: DiagInner, _registry: &Registry) {} + + fn translator(&self) -> &Translator { + &self.translator + } +} + /// Maximum number of suggestions to be shown /// /// Arbitrary, but taken from trait import suggestion limit diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index 831a50efa27..207aed8c755 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -748,34 +748,10 @@ impl DiagCtxt { Self { inner: Lock::new(DiagCtxtInner::new(emitter)) } } - 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; - - impl Emitter for FalseEmitter { - fn emit_diagnostic(&mut self, _: DiagInner, _: &Registry) { - unimplemented!("false emitter must only used during `make_silent`") - } - - fn source_map(&self) -> Option<&SourceMap> { - unimplemented!("false emitter must only used during `make_silent`") - } - - fn translator(&self) -> &translation::Translator { - unimplemented!("false emitter must only used during `make_silent`") - } - } - + pub fn make_silent(&self) { let mut inner = self.inner.borrow_mut(); - 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::FatalOnlyEmitter { - fatal_emitter: prev_emitter, - fatal_note, - emit_fatal_diagnostic, - }); - inner.emitter = new_emitter; + let translator = inner.emitter.translator().clone(); + inner.emitter = Box::new(emitter::SilentEmitter { translator }); } pub fn set_emitter(&self, emitter: Box<dyn Emitter + DynSend>) { |
