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.
This commit is contained in:
parent
a0f5431e23
commit
552bed8048
1 changed files with 6 additions and 23 deletions
|
@ -255,35 +255,18 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
|
||||||
/// Stashes diagnostic for possible later improvement in a different,
|
/// Stashes diagnostic for possible later improvement in a different,
|
||||||
/// later stage of the compiler. The diagnostic can be accessed with
|
/// later stage of the compiler. The diagnostic can be accessed with
|
||||||
/// the provided `span` and `key` through [`DiagCtxt::steal_diagnostic()`].
|
/// the provided `span` and `key` through [`DiagCtxt::steal_diagnostic()`].
|
||||||
///
|
|
||||||
/// As with `buffer`, this is unless the dcx has disabled such buffering.
|
|
||||||
pub fn stash(self, span: Span, key: StashKey) {
|
pub fn stash(self, span: Span, key: StashKey) {
|
||||||
if let Some((diag, dcx)) = self.into_diagnostic() {
|
self.dcx.stash_diagnostic(span, key, self.into_diagnostic());
|
||||||
dcx.stash_diagnostic(span, key, diag);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Converts the builder to a `Diagnostic` for later emission,
|
/// Converts the builder to a `Diagnostic` for later emission.
|
||||||
/// unless dcx has disabled such buffering.
|
fn into_diagnostic(mut self) -> Diagnostic {
|
||||||
fn into_diagnostic(mut self) -> Option<(Diagnostic, &'a DiagCtxt)> {
|
self.take_diag()
|
||||||
if self.dcx.inner.lock().flags.treat_err_as_bug.is_some() {
|
|
||||||
self.emit();
|
|
||||||
return None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let diag = self.take_diag();
|
/// Buffers the diagnostic for later emission.
|
||||||
|
|
||||||
// Logging here is useful to help track down where in logs an error was
|
|
||||||
// actually emitted.
|
|
||||||
debug!("buffer: diag={:?}", diag);
|
|
||||||
|
|
||||||
Some((diag, self.dcx))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Buffers the diagnostic for later emission,
|
|
||||||
/// unless dcx has disabled such buffering.
|
|
||||||
pub fn buffer(self, buffered_diagnostics: &mut Vec<Diagnostic>) {
|
pub fn buffer(self, buffered_diagnostics: &mut Vec<Diagnostic>) {
|
||||||
buffered_diagnostics.extend(self.into_diagnostic().map(|(diag, _)| diag));
|
buffered_diagnostics.push(self.into_diagnostic());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Delay emission of this diagnostic as a bug.
|
/// Delay emission of this diagnostic as a bug.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue