about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>2019-12-29 22:10:47 +0300
committerVadim Petrochenkov <vadim.petrochenkov@gmail.com>2020-01-03 18:03:28 +0400
commit4feeceecd14d41cb74d10f15933aba3acdd6cc91 (patch)
tree4f055f83b1e50b99e36df45f59beccb8f48c4a42 /src
parent30ddb5a8c1e85916da0acdc665d6a16535a12dd6 (diff)
downloadrust-4feeceecd14d41cb74d10f15933aba3acdd6cc91.tar.gz
rust-4feeceecd14d41cb74d10f15933aba3acdd6cc91.zip
Introduce an option for disabling deduplication of diagnostics
Diffstat (limited to 'src')
-rw-r--r--src/librustc_errors/lib.rs12
-rw-r--r--src/librustc_session/options.rs2
-rw-r--r--src/librustc_session/session.rs5
-rw-r--r--src/test/ui/consts/miri_unleashed/mutable_const2.stderr2
4 files changed, 12 insertions, 9 deletions
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;
diff --git a/src/librustc_session/options.rs b/src/librustc_session/options.rs
index 7e44ef7d4a4..656c1b019b2 100644
--- a/src/librustc_session/options.rs
+++ b/src/librustc_session/options.rs
@@ -946,4 +946,6 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
     insert_sideeffect: bool = (false, parse_bool, [TRACKED],
         "fix undefined behavior when a thread doesn't eventually make progress \
          (such as entering an empty infinite loop) by inserting llvm.sideeffect"),
+    deduplicate_diagnostics: Option<bool> = (None, parse_opt_bool, [UNTRACKED],
+        "deduplicate identical diagnostics"),
 }
diff --git a/src/librustc_session/session.rs b/src/librustc_session/session.rs
index 28acbd5713f..7375c5e88c0 100644
--- a/src/librustc_session/session.rs
+++ b/src/librustc_session/session.rs
@@ -943,12 +943,11 @@ pub fn build_session_with_source_map(
     let cap_lints_allow = sopts.lint_cap.map_or(false, |cap| cap == lint::Allow);
 
     let can_emit_warnings = !(warnings_allow || cap_lints_allow);
-
     let treat_err_as_bug = sopts.debugging_opts.treat_err_as_bug;
     let dont_buffer_diagnostics = sopts.debugging_opts.dont_buffer_diagnostics;
     let report_delayed_bugs = sopts.debugging_opts.report_delayed_bugs;
-
     let external_macro_backtrace = sopts.debugging_opts.external_macro_backtrace;
+    let deduplicate_diagnostics = sopts.debugging_opts.deduplicate_diagnostics.unwrap_or(true);
 
     let write_dest = match diagnostics_output {
         DiagnosticOutput::Default => None,
@@ -964,7 +963,7 @@ pub fn build_session_with_source_map(
             report_delayed_bugs,
             dont_buffer_diagnostics,
             external_macro_backtrace,
-            ..Default::default()
+            deduplicate_diagnostics,
         },
     );
 
diff --git a/src/test/ui/consts/miri_unleashed/mutable_const2.stderr b/src/test/ui/consts/miri_unleashed/mutable_const2.stderr
index 2212b7d75d2..3493b7c54c4 100644
--- a/src/test/ui/consts/miri_unleashed/mutable_const2.stderr
+++ b/src/test/ui/consts/miri_unleashed/mutable_const2.stderr
@@ -10,7 +10,7 @@ error: internal compiler error: mutable allocation in constant
 LL | const MUTABLE_BEHIND_RAW: *mut i32 = &UnsafeCell::new(42) as *const _ as *mut _;
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
-thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', src/librustc_errors/lib.rs:345:17
+thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', src/librustc_errors/lib.rs:347:17
 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
 
 error: internal compiler error: unexpected panic