1
Fork 0

Avoid struct_diagnostic where possible.

It's necessary for `derive(Diagnostic)`, but is best avoided elsewhere
because there are clearer alternatives.

This required adding `Handler::struct_almost_fatal`.
This commit is contained in:
Nicholas Nethercote 2023-12-13 15:19:34 +11:00
parent dc05a30996
commit 7bdb227567
7 changed files with 26 additions and 19 deletions

View file

@ -722,7 +722,12 @@ impl Handler {
self.inner.borrow_mut().emit_stashed_diagnostics()
}
/// Construct a builder with the `msg` at the level appropriate for the specific `EmissionGuarantee`.
/// Construct a builder with the `msg` at the level appropriate for the
/// specific `EmissionGuarantee`.
///
/// Note: this is necessary for `derive(Diagnostic)`, but shouldn't be used
/// outside of that. Instead use `struct_err`, `struct_warn`, etc., which
/// make the diagnostic kind clearer.
#[rustc_lint_diagnostics]
#[track_caller]
pub fn struct_diagnostic<G: EmissionGuarantee>(
@ -937,13 +942,23 @@ impl Handler {
result
}
/// Construct a builder at the `Error` level with the `msg`.
/// Construct a builder at the `Fatal` level with the `msg`.
#[rustc_lint_diagnostics]
#[track_caller]
pub fn struct_fatal(&self, msg: impl Into<DiagnosticMessage>) -> DiagnosticBuilder<'_, !> {
DiagnosticBuilder::new(self, Level::Fatal, msg)
}
/// Construct a builder at the `Fatal` level with the `msg`, that doesn't abort.
#[rustc_lint_diagnostics]
#[track_caller]
pub fn struct_almost_fatal(
&self,
msg: impl Into<DiagnosticMessage>,
) -> DiagnosticBuilder<'_, FatalError> {
DiagnosticBuilder::new(self, Level::Fatal, msg)
}
/// Construct a builder at the `Help` level with the `msg`.
#[rustc_lint_diagnostics]
pub fn struct_help(&self, msg: impl Into<DiagnosticMessage>) -> DiagnosticBuilder<'_, ()> {