diff options
| author | Fabian Wolff <fabian.wolff@alumni.ethz.ch> | 2021-10-02 19:15:45 +0200 |
|---|---|---|
| committer | Fabian Wolff <fabian.wolff@alumni.ethz.ch> | 2021-10-02 19:15:55 +0200 |
| commit | 041212f8fbb9f52d41167448e4fbc2ce8cc7ee9a (patch) | |
| tree | c13075331c74e7e216d5769ad0f2efa6984b60ec /compiler/rustc_errors/src | |
| parent | ed937594d3912ced11f6f35a90bb8bf591909d2a (diff) | |
| download | rust-041212f8fbb9f52d41167448e4fbc2ce8cc7ee9a.tar.gz rust-041212f8fbb9f52d41167448e4fbc2ce8cc7ee9a.zip | |
Report fatal lexer errors in `--cfg` command line arguments
Diffstat (limited to 'compiler/rustc_errors/src')
| -rw-r--r-- | compiler/rustc_errors/src/emitter.rs | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/compiler/rustc_errors/src/emitter.rs b/compiler/rustc_errors/src/emitter.rs index 29f352ae585..fa986ce8a7e 100644 --- a/compiler/rustc_errors/src/emitter.rs +++ b/compiler/rustc_errors/src/emitter.rs @@ -15,7 +15,7 @@ use rustc_span::{MultiSpan, SourceFile, Span}; use crate::snippet::{Annotation, AnnotationType, Line, MultilineAnnotation, Style, StyledString}; use crate::styled_buffer::StyledBuffer; use crate::{ - CodeSuggestion, Diagnostic, DiagnosticId, Level, SubDiagnostic, SubstitutionHighlight, + CodeSuggestion, Diagnostic, DiagnosticId, Handler, Level, SubDiagnostic, SubstitutionHighlight, SuggestionStyle, }; @@ -527,14 +527,27 @@ impl Emitter for EmitterWriter { } } -/// An emitter that does nothing when emitting a diagnostic. -pub struct SilentEmitter; +/// An emitter that does nothing when emitting a non-fatal diagnostic. +/// Fatal diagnostics are forwarded to `fatal_handler` to avoid silent +/// failures of rustc, as witnessed e.g. in issue #89358. +pub struct SilentEmitter { + pub fatal_handler: Handler, + pub fatal_note: Option<String>, +} impl Emitter for SilentEmitter { fn source_map(&self) -> Option<&Lrc<SourceMap>> { None } - fn emit_diagnostic(&mut self, _: &Diagnostic) {} + fn emit_diagnostic(&mut self, d: &Diagnostic) { + if d.level == Level::Fatal { + let mut d = d.clone(); + if let Some(ref note) = self.fatal_note { + d.note(note); + } + self.fatal_handler.emit_diagnostic(&d); + } + } } /// Maximum number of lines we will print for a multiline suggestion; arbitrary. |
