From 4feeceecd14d41cb74d10f15933aba3acdd6cc91 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sun, 29 Dec 2019 22:10:47 +0300 Subject: Introduce an option for disabling deduplication of diagnostics --- src/librustc_errors/lib.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'src/librustc_errors') diff --git a/src/librustc_errors/lib.rs b/src/librustc_errors/lib.rs index aa2865a75f9..999c3470e71 100644 --- a/src/librustc_errors/lib.rs +++ b/src/librustc_errors/lib.rs @@ -329,6 +329,8 @@ pub struct HandlerFlags { /// show macro backtraces even for non-local macros. /// (rustc: see `-Z external-macro-backtrace`) pub external_macro_backtrace: bool, + /// If true, identical diagnostics are reported only once. + pub deduplicate_diagnostics: bool, } impl Drop for HandlerInner { @@ -736,16 +738,16 @@ impl HandlerInner { self.emitted_diagnostic_codes.insert(code.clone()); } - let diagnostic_hash = { + let already_emitted = |this: &mut Self| { use std::hash::Hash; let mut hasher = StableHasher::new(); diagnostic.hash(&mut hasher); - hasher.finish() + let diagnostic_hash = hasher.finish(); + !this.emitted_diagnostics.insert(diagnostic_hash) }; - // Only emit the diagnostic if we haven't already emitted an equivalent - // one: - if self.emitted_diagnostics.insert(diagnostic_hash) { + // Only emit the diagnostic if we haven't already emitted an equivalent one. + if !(self.flags.deduplicate_diagnostics && already_emitted(self)) { self.emitter.emit_diagnostic(diagnostic); if diagnostic.is_error() { self.deduplicated_err_count += 1; -- cgit 1.4.1-3-g733a5 From 5bf810599306fd880b0946ecb3e1ec37ca72762f Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Fri, 3 Jan 2020 18:03:11 +0400 Subject: Address review comments + Fix rebase --- src/librustc_errors/lib.rs | 3 ++- src/librustdoc/core.rs | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'src/librustc_errors') diff --git a/src/librustc_errors/lib.rs b/src/librustc_errors/lib.rs index 999c3470e71..2279ed85954 100644 --- a/src/librustc_errors/lib.rs +++ b/src/librustc_errors/lib.rs @@ -746,7 +746,8 @@ impl HandlerInner { !this.emitted_diagnostics.insert(diagnostic_hash) }; - // Only emit the diagnostic if we haven't already emitted an equivalent one. + // 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); if diagnostic.is_error() { diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index c48523961de..5f2ce34afee 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -184,7 +184,7 @@ pub fn new_handler( debugging_opts.terminal_width, false, ) - .ui_testing(debugging_opts.ui_testing), + .ui_testing(debugging_opts.ui_testing()), ) } ErrorOutputType::Json { pretty, json_rendered } => { @@ -193,7 +193,7 @@ pub fn new_handler( }); Box::new( JsonEmitter::stderr(None, source_map, pretty, json_rendered, false) - .ui_testing(debugging_opts.ui_testing), + .ui_testing(debugging_opts.ui_testing()), ) } }; -- cgit 1.4.1-3-g733a5