Skip to content

Commit b48d944

Browse files
committed
Clean emitted diagnostics when reset_err_count is called.
When external tools like `rustfmt` calls to `reset_err_count` for handler reusing, it will set the error count on the handler to 0, but since #47146 the handler will contain status that will prevent the error count to be bumped if this handler is reused. This caused `rustfmt` idempotency tests to fail: rust-lang/rustfmt#2338 Fixes: rust-lang/rustfmt#2338
1 parent 90e019b commit b48d944

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/librustc_errors/lib.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -310,9 +310,13 @@ impl Handler {
310310
self.continue_after_error.set(continue_after_error);
311311
}
312312

313-
// NOTE: DO NOT call this function from rustc, as it relies on `err_count` being non-zero
314-
// if an error happened to avoid ICEs. This function should only be called from tools.
313+
/// Resets the diagnostic error count as well as the cached emitted diagnostics.
314+
///
315+
/// NOTE: DO NOT call this function from rustc. It is only meant to be called from external
316+
/// tools that want to reuse a `Parser` cleaning the previously emitted diagnostics as well as
317+
/// the overall count of emitted error diagnostics.
315318
pub fn reset_err_count(&self) {
319+
self.emitted_diagnostics.replace(FxHashSet());
316320
self.err_count.store(0, SeqCst);
317321
}
318322

0 commit comments

Comments
 (0)