Skip to content

Commit 4feecee

Browse files
committed
Introduce an option for disabling deduplication of diagnostics
1 parent 30ddb5a commit 4feecee

File tree

4 files changed

+12
-9
lines changed

4 files changed

+12
-9
lines changed

src/librustc_errors/lib.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,8 @@ pub struct HandlerFlags {
329329
/// show macro backtraces even for non-local macros.
330330
/// (rustc: see `-Z external-macro-backtrace`)
331331
pub external_macro_backtrace: bool,
332+
/// If true, identical diagnostics are reported only once.
333+
pub deduplicate_diagnostics: bool,
332334
}
333335

334336
impl Drop for HandlerInner {
@@ -736,16 +738,16 @@ impl HandlerInner {
736738
self.emitted_diagnostic_codes.insert(code.clone());
737739
}
738740

739-
let diagnostic_hash = {
741+
let already_emitted = |this: &mut Self| {
740742
use std::hash::Hash;
741743
let mut hasher = StableHasher::new();
742744
diagnostic.hash(&mut hasher);
743-
hasher.finish()
745+
let diagnostic_hash = hasher.finish();
746+
!this.emitted_diagnostics.insert(diagnostic_hash)
744747
};
745748

746-
// Only emit the diagnostic if we haven't already emitted an equivalent
747-
// one:
748-
if self.emitted_diagnostics.insert(diagnostic_hash) {
749+
// Only emit the diagnostic if we haven't already emitted an equivalent one.
750+
if !(self.flags.deduplicate_diagnostics && already_emitted(self)) {
749751
self.emitter.emit_diagnostic(diagnostic);
750752
if diagnostic.is_error() {
751753
self.deduplicated_err_count += 1;

src/librustc_session/options.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -946,4 +946,6 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
946946
insert_sideeffect: bool = (false, parse_bool, [TRACKED],
947947
"fix undefined behavior when a thread doesn't eventually make progress \
948948
(such as entering an empty infinite loop) by inserting llvm.sideeffect"),
949+
deduplicate_diagnostics: Option<bool> = (None, parse_opt_bool, [UNTRACKED],
950+
"deduplicate identical diagnostics"),
949951
}

src/librustc_session/session.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -943,12 +943,11 @@ pub fn build_session_with_source_map(
943943
let cap_lints_allow = sopts.lint_cap.map_or(false, |cap| cap == lint::Allow);
944944

945945
let can_emit_warnings = !(warnings_allow || cap_lints_allow);
946-
947946
let treat_err_as_bug = sopts.debugging_opts.treat_err_as_bug;
948947
let dont_buffer_diagnostics = sopts.debugging_opts.dont_buffer_diagnostics;
949948
let report_delayed_bugs = sopts.debugging_opts.report_delayed_bugs;
950-
951949
let external_macro_backtrace = sopts.debugging_opts.external_macro_backtrace;
950+
let deduplicate_diagnostics = sopts.debugging_opts.deduplicate_diagnostics.unwrap_or(true);
952951

953952
let write_dest = match diagnostics_output {
954953
DiagnosticOutput::Default => None,
@@ -964,7 +963,7 @@ pub fn build_session_with_source_map(
964963
report_delayed_bugs,
965964
dont_buffer_diagnostics,
966965
external_macro_backtrace,
967-
..Default::default()
966+
deduplicate_diagnostics,
968967
},
969968
);
970969

src/test/ui/consts/miri_unleashed/mutable_const2.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ error: internal compiler error: mutable allocation in constant
1010
LL | const MUTABLE_BEHIND_RAW: *mut i32 = &UnsafeCell::new(42) as *const _ as *mut _;
1111
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1212

13-
thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', src/librustc_errors/lib.rs:345:17
13+
thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', src/librustc_errors/lib.rs:347:17
1414
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
1515

1616
error: internal compiler error: unexpected panic

0 commit comments

Comments
 (0)