Skip to content

Commit 552bed8

Browse files
committed
Remove DiagnosticBuilder::into_diagnostic from -Ztreat-err-as-bug consideration.
It seems very wrong to have a `-Ztreat-err-as-bug` check here before the error is even emitted. Once that's done: - `into_diagnostic` is infallible, so its return type doesn't need the `Option`; - the `&'a DiagCtxt` also isn't needed, because only one callsite uses it, and it already have access to it via `self.dcx`; - the comments about dcx disabling buffering are no longer true, this is unconditional now; - and the `debug!` seems unnecessary... the comment greatly overstates its importance because few diagnostics come through `into_diagnostic`, and `-Ztrack-diagnostics` exists anyway.
1 parent a0f5431 commit 552bed8

File tree

1 file changed

+6
-23
lines changed

1 file changed

+6
-23
lines changed

compiler/rustc_errors/src/diagnostic_builder.rs

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -255,35 +255,18 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
255255
/// Stashes diagnostic for possible later improvement in a different,
256256
/// later stage of the compiler. The diagnostic can be accessed with
257257
/// the provided `span` and `key` through [`DiagCtxt::steal_diagnostic()`].
258-
///
259-
/// As with `buffer`, this is unless the dcx has disabled such buffering.
260258
pub fn stash(self, span: Span, key: StashKey) {
261-
if let Some((diag, dcx)) = self.into_diagnostic() {
262-
dcx.stash_diagnostic(span, key, diag);
263-
}
259+
self.dcx.stash_diagnostic(span, key, self.into_diagnostic());
264260
}
265261

266-
/// Converts the builder to a `Diagnostic` for later emission,
267-
/// unless dcx has disabled such buffering.
268-
fn into_diagnostic(mut self) -> Option<(Diagnostic, &'a DiagCtxt)> {
269-
if self.dcx.inner.lock().flags.treat_err_as_bug.is_some() {
270-
self.emit();
271-
return None;
272-
}
273-
274-
let diag = self.take_diag();
275-
276-
// Logging here is useful to help track down where in logs an error was
277-
// actually emitted.
278-
debug!("buffer: diag={:?}", diag);
279-
280-
Some((diag, self.dcx))
262+
/// Converts the builder to a `Diagnostic` for later emission.
263+
fn into_diagnostic(mut self) -> Diagnostic {
264+
self.take_diag()
281265
}
282266

283-
/// Buffers the diagnostic for later emission,
284-
/// unless dcx has disabled such buffering.
267+
/// Buffers the diagnostic for later emission.
285268
pub fn buffer(self, buffered_diagnostics: &mut Vec<Diagnostic>) {
286-
buffered_diagnostics.extend(self.into_diagnostic().map(|(diag, _)| diag));
269+
buffered_diagnostics.push(self.into_diagnostic());
287270
}
288271

289272
/// Delay emission of this diagnostic as a bug.

0 commit comments

Comments
 (0)