diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2024-03-06 22:02:46 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-03-06 22:02:46 +0100 |
| commit | efe9deace861039956aa182d8c17c38ef9ef2408 (patch) | |
| tree | b9854ba5f0310cbbc3dc518fadb2bb3d27785643 /compiler/rustc_errors/src/lib.rs | |
| parent | c7fca03240dfba93363505bc9c6839a224cc8ca6 (diff) | |
| parent | 3591e77b3566772023b7e35e96224106243ef214 (diff) | |
| download | rust-efe9deace861039956aa182d8c17c38ef9ef2408.tar.gz rust-efe9deace861039956aa182d8c17c38ef9ef2408.zip | |
Rollup merge of #121382 - nnethercote:rework-untranslatable_diagnostic-lint, r=davidtwco
Rework `untranslatable_diagnostic` lint
Currently it only checks calls to functions marked with `#[rustc_lint_diagnostics]`. This PR changes it to check calls to any function with an `impl Into<{D,Subd}iagnosticMessage>` parameter. This greatly improves its coverage and doesn't rely on people remembering to add `#[rustc_lint_diagnostics]`. It also lets us add `#[rustc_lint_diagnostics]` to a number of functions that don't have an `impl Into<{D,Subd}iagnosticMessage>`, such as `Diag::span`.
r? ``@davidtwco``
Diffstat (limited to 'compiler/rustc_errors/src/lib.rs')
| -rw-r--r-- | compiler/rustc_errors/src/lib.rs | 40 |
1 files changed, 24 insertions, 16 deletions
diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index 0caa8fa9e8a..76b44f73f47 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -1101,32 +1101,36 @@ impl DiagCtxt { // Functions beginning with `struct_`/`create_` create a diagnostic. Other // functions create and emit a diagnostic all in one go. impl DiagCtxt { - // No `#[rustc_lint_diagnostics]` because bug messages aren't user-facing. + // No `#[rustc_lint_diagnostics]` and no `impl Into<DiagMessage>` because bug messages aren't + // user-facing. #[track_caller] - pub fn struct_bug(&self, msg: impl Into<DiagMessage>) -> Diag<'_, BugAbort> { - Diag::new(self, Bug, msg) + pub fn struct_bug(&self, msg: impl Into<Cow<'static, str>>) -> Diag<'_, BugAbort> { + Diag::new(self, Bug, msg.into()) } - // No `#[rustc_lint_diagnostics]` because bug messages aren't user-facing. + // No `#[rustc_lint_diagnostics]` and no `impl Into<DiagMessage>` because bug messages aren't + // user-facing. #[track_caller] - pub fn bug(&self, msg: impl Into<DiagMessage>) -> ! { + pub fn bug(&self, msg: impl Into<Cow<'static, str>>) -> ! { self.struct_bug(msg).emit() } - // No `#[rustc_lint_diagnostics]` because bug messages aren't user-facing. + // No `#[rustc_lint_diagnostics]` and no `impl Into<DiagMessage>` because bug messages aren't + // user-facing. #[track_caller] pub fn struct_span_bug( &self, span: impl Into<MultiSpan>, - msg: impl Into<DiagMessage>, + msg: impl Into<Cow<'static, str>>, ) -> Diag<'_, BugAbort> { self.struct_bug(msg).with_span(span) } - // No `#[rustc_lint_diagnostics]` because bug messages aren't user-facing. + // No `#[rustc_lint_diagnostics]` and no `impl Into<DiagMessage>` because bug messages aren't + // user-facing. #[track_caller] - pub fn span_bug(&self, span: impl Into<MultiSpan>, msg: impl Into<DiagMessage>) -> ! { - self.struct_span_bug(span, msg).emit() + pub fn span_bug(&self, span: impl Into<MultiSpan>, msg: impl Into<Cow<'static, str>>) -> ! { + self.struct_span_bug(span, msg.into()).emit() } #[track_caller] @@ -1240,24 +1244,28 @@ impl DiagCtxt { } /// Ensures that an error is printed. See `Level::DelayedBug`. - // No `#[rustc_lint_diagnostics]` because bug messages aren't user-facing. + // + // No `#[rustc_lint_diagnostics]` and no `impl Into<DiagMessage>` because bug messages aren't + // user-facing. #[track_caller] - pub fn delayed_bug(&self, msg: impl Into<DiagMessage>) -> ErrorGuaranteed { - Diag::<ErrorGuaranteed>::new(self, DelayedBug, msg).emit() + pub fn delayed_bug(&self, msg: impl Into<Cow<'static, str>>) -> ErrorGuaranteed { + Diag::<ErrorGuaranteed>::new(self, DelayedBug, msg.into()).emit() } /// Ensures that an error is printed. See `Level::DelayedBug`. /// /// Note: this function used to be called `delay_span_bug`. It was renamed /// to match similar functions like `span_err`, `span_warn`, etc. - // No `#[rustc_lint_diagnostics]` because bug messages aren't user-facing. + // + // No `#[rustc_lint_diagnostics]` and no `impl Into<DiagMessage>` because bug messages aren't + // user-facing. #[track_caller] pub fn span_delayed_bug( &self, sp: impl Into<MultiSpan>, - msg: impl Into<DiagMessage>, + msg: impl Into<Cow<'static, str>>, ) -> ErrorGuaranteed { - Diag::<ErrorGuaranteed>::new(self, DelayedBug, msg).with_span(sp).emit() + Diag::<ErrorGuaranteed>::new(self, DelayedBug, msg.into()).with_span(sp).emit() } #[rustc_lint_diagnostics] |
