diff options
| author | Nicholas Nethercote <n.nethercote@gmail.com> | 2023-12-04 14:27:43 +1100 |
|---|---|---|
| committer | Nicholas Nethercote <n.nethercote@gmail.com> | 2023-12-04 18:57:42 +1100 |
| commit | 883bdb7fda9b2eda5e3c1846ed653e7edf4936c4 (patch) | |
| tree | ac98dc640cac1388b5baf28b402a1f5872abd398 /compiler/rustc_errors/src | |
| parent | a8ff867d5c3f88224cfec66f36b697cac0c6f75e (diff) | |
| download | rust-883bdb7fda9b2eda5e3c1846ed653e7edf4936c4.tar.gz rust-883bdb7fda9b2eda5e3c1846ed653e7edf4936c4.zip | |
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.
Diffstat (limited to 'compiler/rustc_errors/src')
| -rw-r--r-- | compiler/rustc_errors/src/lib.rs | 24 |
1 files changed, 12 insertions, 12 deletions
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 @@ impl Handler { #[rustc_lint_diagnostics] pub fn err(&self, msg: impl Into<DiagnosticMessage>) -> 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 @@ impl Handler { } pub fn has_errors_or_lint_errors(&self) -> Option<ErrorGuaranteed> { - 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 @@ impl Handler { } pub fn has_errors_or_span_delayed_bugs(&self) -> Option<ErrorGuaranteed> { - 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 @@ impl HandlerInner { // FIXME(eddyb) this should ideally take `diagnostic` by value. fn emit_diagnostic(&mut self, diagnostic: &mut Diagnostic) -> Option<ErrorGuaranteed> { + 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 @@ impl HandlerInner { // 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<DiagnosticMessage>) -> 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<DiagnosticMessage>) -> 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<DiagnosticMessage>) -> ! { self.emit_diagnostic(&mut Diagnostic::new(Bug, msg)); panic::panic_any(ExplicitBug); |
