Skip to content

Commit

Permalink
Introduce an option for disabling deduplication of diagnostics
Browse files Browse the repository at this point in the history
  • Loading branch information
petrochenkov committed Jan 3, 2020
1 parent 30ddb5a commit 4feecee
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
12 changes: 7 additions & 5 deletions src/librustc_errors/lib.rs
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/librustc_session/options.rs
Expand Up @@ -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"),
}
5 changes: 2 additions & 3 deletions src/librustc_session/session.rs
Expand Up @@ -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,
Expand All @@ -964,7 +963,7 @@ pub fn build_session_with_source_map(
report_delayed_bugs,
dont_buffer_diagnostics,
external_macro_backtrace,
..Default::default()
deduplicate_diagnostics,
},
);

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/consts/miri_unleashed/mutable_const2.stderr
Expand Up @@ -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
Expand Down

0 comments on commit 4feecee

Please sign in to comment.