diff options
| author | Camille GILLOT <gillot.camille@gmail.com> | 2022-03-20 20:02:18 +0100 |
|---|---|---|
| committer | Camille GILLOT <gillot.camille@gmail.com> | 2022-03-20 20:36:26 +0100 |
| commit | 0b49d05ea33d68391e3d5472f3398d0ad1d9f9a6 (patch) | |
| tree | 29a5bae15a0ce8bbc268c68c8e12a047a4481234 /compiler/rustc_errors | |
| parent | 056951d6289e3fbba444cbadec8b4eea7f92928e (diff) | |
| download | rust-0b49d05ea33d68391e3d5472f3398d0ad1d9f9a6.tar.gz rust-0b49d05ea33d68391e3d5472f3398d0ad1d9f9a6.zip | |
Filter OnceNote in diagnostic infra.
Diffstat (limited to 'compiler/rustc_errors')
| -rw-r--r-- | compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_errors/src/diagnostic.rs | 21 | ||||
| -rw-r--r-- | compiler/rustc_errors/src/diagnostic_builder.rs | 6 | ||||
| -rw-r--r-- | compiler/rustc_errors/src/lib.rs | 25 |
4 files changed, 49 insertions, 5 deletions
diff --git a/compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs b/compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs index c380455012d..5f59eba23f8 100644 --- a/compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs +++ b/compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs @@ -70,7 +70,7 @@ fn annotation_type_for_level(level: Level) -> AnnotationType { AnnotationType::Error } Level::Warning => AnnotationType::Warning, - Level::Note => AnnotationType::Note, + Level::Note | Level::OnceNote => AnnotationType::Note, Level::Help => AnnotationType::Help, // FIXME(#59346): Not sure how to map this level Level::FailureNote => AnnotationType::Error, diff --git a/compiler/rustc_errors/src/diagnostic.rs b/compiler/rustc_errors/src/diagnostic.rs index 5c36c3c55b5..00ecbbbb93b 100644 --- a/compiler/rustc_errors/src/diagnostic.rs +++ b/compiler/rustc_errors/src/diagnostic.rs @@ -135,7 +135,12 @@ impl Diagnostic { | Level::Error { .. } | Level::FailureNote => true, - Level::Warning | Level::Note | Level::Help | Level::Allow | Level::Expect(_) => false, + Level::Warning + | Level::Note + | Level::OnceNote + | Level::Help + | Level::Allow + | Level::Expect(_) => false, } } @@ -335,11 +340,25 @@ impl Diagnostic { /// Prints the span with a note above it. /// This is like [`Diagnostic::note()`], but it gets its own span. + pub fn note_once(&mut self, msg: &str) -> &mut Self { + self.sub(Level::OnceNote, msg, MultiSpan::new(), None); + self + } + + /// Prints the span with a note above it. + /// This is like [`Diagnostic::note()`], but it gets its own span. pub fn span_note<S: Into<MultiSpan>>(&mut self, sp: S, msg: &str) -> &mut Self { self.sub(Level::Note, msg, sp.into(), None); self } + /// Prints the span with a note above it. + /// This is like [`Diagnostic::note()`], but it gets its own span. + pub fn span_note_once<S: Into<MultiSpan>>(&mut self, sp: S, msg: &str) -> &mut Self { + self.sub(Level::OnceNote, msg, sp.into(), None); + self + } + /// Add a warning attached to this diagnostic. pub fn warn(&mut self, msg: &str) -> &mut Self { self.sub(Level::Warning, msg, MultiSpan::new(), None); diff --git a/compiler/rustc_errors/src/diagnostic_builder.rs b/compiler/rustc_errors/src/diagnostic_builder.rs index 34236d36035..088f6091528 100644 --- a/compiler/rustc_errors/src/diagnostic_builder.rs +++ b/compiler/rustc_errors/src/diagnostic_builder.rs @@ -396,11 +396,17 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> { ) -> &mut Self); forward!(pub fn note(&mut self, msg: &str) -> &mut Self); + forward!(pub fn note_once(&mut self, msg: &str) -> &mut Self); forward!(pub fn span_note( &mut self, sp: impl Into<MultiSpan>, msg: &str, ) -> &mut Self); + forward!(pub fn span_note_once( + &mut self, + sp: impl Into<MultiSpan>, + msg: &str, + ) -> &mut Self); forward!(pub fn warn(&mut self, msg: &str) -> &mut Self); forward!(pub fn span_warn(&mut self, sp: impl Into<MultiSpan>, msg: &str) -> &mut Self); forward!(pub fn help(&mut self, msg: &str) -> &mut Self); diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index 7cfb332d69d..2f2f6ed1a5a 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -4,6 +4,7 @@ #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] #![feature(crate_visibility_modifier)] +#![feature(drain_filter)] #![feature(backtrace)] #![feature(if_let_guard)] #![feature(let_else)] @@ -1070,7 +1071,23 @@ impl HandlerInner { // Only emit the diagnostic if we've been asked to deduplicate and // haven't already emitted an equivalent diagnostic. if !(self.flags.deduplicate_diagnostics && already_emitted(self)) { - self.emitter.emit_diagnostic(diagnostic); + debug!(?diagnostic); + debug!(?self.emitted_diagnostics); + let already_emitted_sub = |sub: &mut SubDiagnostic| { + debug!(?sub); + if sub.level != Level::OnceNote { + return false; + } + let mut hasher = StableHasher::new(); + sub.hash(&mut hasher); + let diagnostic_hash = hasher.finish(); + debug!(?diagnostic_hash); + !self.emitted_diagnostics.insert(diagnostic_hash) + }; + + diagnostic.children.drain_filter(already_emitted_sub).for_each(|_| {}); + + self.emitter.emit_diagnostic(&diagnostic); if diagnostic.is_error() { self.deduplicated_err_count += 1; } else if diagnostic.level == Warning { @@ -1350,6 +1367,8 @@ pub enum Level { }, Warning, Note, + /// A note that is only emitted once. + OnceNote, Help, FailureNote, Allow, @@ -1372,7 +1391,7 @@ impl Level { Warning => { spec.set_fg(Some(Color::Yellow)).set_intense(cfg!(windows)); } - Note => { + Note | OnceNote => { spec.set_fg(Some(Color::Green)).set_intense(true); } Help => { @@ -1389,7 +1408,7 @@ impl Level { Bug | DelayedBug => "error: internal compiler error", Fatal | Error { .. } => "error", Warning => "warning", - Note => "note", + Note | OnceNote => "note", Help => "help", FailureNote => "failure-note", Allow => panic!("Shouldn't call on allowed error"), |
