diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index 5ff99f06525..11ac5239445 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -1096,7 +1096,10 @@ pub fn fatal(&self, msg: impl Into) -> ! { #[rustc_lint_diagnostics] pub fn err(&self, msg: impl Into) -> ErrorGuaranteed { - self.inner.borrow_mut().emit(Error { lint: false }, msg) + self.inner + .borrow_mut() + .emit_diagnostic(&mut Diagnostic::new(Error { lint: false }, msg)) + .unwrap() } #[rustc_lint_diagnostics] @@ -1126,7 +1129,7 @@ pub fn has_errors(&self) -> Option { } pub fn has_errors_or_lint_errors(&self) -> Option { - let inner = self.inner.borrow(); + let inner = self.inner.borrow(); let has_errors_or_lint_errors = inner.has_errors() || inner.lint_err_count > 0; has_errors_or_lint_errors.then(|| { #[allow(deprecated)] @@ -1135,7 +1138,7 @@ pub fn has_errors_or_lint_errors(&self) -> Option { } pub fn has_errors_or_span_delayed_bugs(&self) -> Option { - let inner = self.inner.borrow(); + let inner = self.inner.borrow(); let has_errors_or_span_delayed_bugs = inner.has_errors() || !inner.span_delayed_bugs.is_empty(); has_errors_or_span_delayed_bugs.then(|| { @@ -1443,6 +1446,11 @@ fn emit_stashed_diagnostics(&mut self) -> Option { // FIXME(eddyb) this should ideally take `diagnostic` by value. fn emit_diagnostic(&mut self, diagnostic: &mut Diagnostic) -> Option { + if matches!(diagnostic.level, Level::Error { .. } | Level::Fatal) && self.treat_err_as_bug() + { + diagnostic.level = Level::Bug; + } + // The `LintExpectationId` can be stable or unstable depending on when it was created. // Diagnostics created before the definition of `HirId`s are unstable and can not yet // be stored. Instead, they are buffered until the `LintExpectationId` is replaced by @@ -1589,18 +1597,10 @@ fn failure_note(&mut self, msg: impl Into) { // Note: unlike `Handler::fatal`, this doesn't return `!`, because that is // inappropriate for some of its call sites. fn fatal_no_raise(&mut self, msg: impl Into) -> FatalError { - self.emit(Fatal, msg); + self.emit_diagnostic(&mut Diagnostic::new(Fatal, msg)); FatalError } - /// Emit an error; level should be `Error` or `Fatal`. - fn emit(&mut self, level: Level, msg: impl Into) -> ErrorGuaranteed { - if self.treat_err_as_bug() { - self.bug(msg); - } - self.emit_diagnostic(&mut Diagnostic::new(level, msg)).unwrap() - } - fn bug(&mut self, msg: impl Into) -> ! { self.emit_diagnostic(&mut Diagnostic::new(Bug, msg)); panic::panic_any(ExplicitBug);