Skip to content

Commit 883bdb7

Browse files
committed
Remove HandlerInner::emit.
This is weird: `HandlerInner::emit` calls `HandlerInner::emit_diagnostic`, but only after doing a `treat-err-as-bug` check. Which is fine, *except* that there are multiple others paths for an `Error` or `Fatal` diagnostic to be passed to `HandlerInner::emit_diagnostic` without going through `HandlerInner::emit`, e.g. `Handler::span_err` call `Handler::emit_diag_at_span`, which calls `emit_diagnostic`. So that suggests that the coverage for `treat-err-as-bug` is incomplete. This commit removes `HandlerInner::emit` and moves the `treat-err-as-bug` check to `HandlerInner::emit_diagnostic`, so it cannot by bypassed.
1 parent a8ff867 commit 883bdb7

File tree

1 file changed

+12
-12
lines changed
  • compiler/rustc_errors/src

1 file changed

+12
-12
lines changed

compiler/rustc_errors/src/lib.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -1096,7 +1096,10 @@ impl Handler {
10961096

10971097
#[rustc_lint_diagnostics]
10981098
pub fn err(&self, msg: impl Into<DiagnosticMessage>) -> ErrorGuaranteed {
1099-
self.inner.borrow_mut().emit(Error { lint: false }, msg)
1099+
self.inner
1100+
.borrow_mut()
1101+
.emit_diagnostic(&mut Diagnostic::new(Error { lint: false }, msg))
1102+
.unwrap()
11001103
}
11011104

11021105
#[rustc_lint_diagnostics]
@@ -1126,7 +1129,7 @@ impl Handler {
11261129
}
11271130

11281131
pub fn has_errors_or_lint_errors(&self) -> Option<ErrorGuaranteed> {
1129-
let inner = self.inner.borrow();
1132+
let inner = self.inner.borrow();
11301133
let has_errors_or_lint_errors = inner.has_errors() || inner.lint_err_count > 0;
11311134
has_errors_or_lint_errors.then(|| {
11321135
#[allow(deprecated)]
@@ -1135,7 +1138,7 @@ impl Handler {
11351138
}
11361139

11371140
pub fn has_errors_or_span_delayed_bugs(&self) -> Option<ErrorGuaranteed> {
1138-
let inner = self.inner.borrow();
1141+
let inner = self.inner.borrow();
11391142
let has_errors_or_span_delayed_bugs =
11401143
inner.has_errors() || !inner.span_delayed_bugs.is_empty();
11411144
has_errors_or_span_delayed_bugs.then(|| {
@@ -1443,6 +1446,11 @@ impl HandlerInner {
14431446

14441447
// FIXME(eddyb) this should ideally take `diagnostic` by value.
14451448
fn emit_diagnostic(&mut self, diagnostic: &mut Diagnostic) -> Option<ErrorGuaranteed> {
1449+
if matches!(diagnostic.level, Level::Error { .. } | Level::Fatal) && self.treat_err_as_bug()
1450+
{
1451+
diagnostic.level = Level::Bug;
1452+
}
1453+
14461454
// The `LintExpectationId` can be stable or unstable depending on when it was created.
14471455
// Diagnostics created before the definition of `HirId`s are unstable and can not yet
14481456
// be stored. Instead, they are buffered until the `LintExpectationId` is replaced by
@@ -1589,18 +1597,10 @@ impl HandlerInner {
15891597
// Note: unlike `Handler::fatal`, this doesn't return `!`, because that is
15901598
// inappropriate for some of its call sites.
15911599
fn fatal_no_raise(&mut self, msg: impl Into<DiagnosticMessage>) -> FatalError {
1592-
self.emit(Fatal, msg);
1600+
self.emit_diagnostic(&mut Diagnostic::new(Fatal, msg));
15931601
FatalError
15941602
}
15951603

1596-
/// Emit an error; level should be `Error` or `Fatal`.
1597-
fn emit(&mut self, level: Level, msg: impl Into<DiagnosticMessage>) -> ErrorGuaranteed {
1598-
if self.treat_err_as_bug() {
1599-
self.bug(msg);
1600-
}
1601-
self.emit_diagnostic(&mut Diagnostic::new(level, msg)).unwrap()
1602-
}
1603-
16041604
fn bug(&mut self, msg: impl Into<DiagnosticMessage>) -> ! {
16051605
self.emit_diagnostic(&mut Diagnostic::new(Bug, msg));
16061606
panic::panic_any(ExplicitBug);

0 commit comments

Comments
 (0)