Add Handler::struct_diagnostic()
This unifies the struct_{warn,error,fatal}() methods in one generic method.
This commit is contained in:
parent
aa8e761def
commit
91ad4e38f5
4 changed files with 49 additions and 2 deletions
|
@ -84,6 +84,13 @@ pub trait EmissionGuarantee: Sized {
|
|||
/// of `Self` without actually performing the emission.
|
||||
#[track_caller]
|
||||
fn diagnostic_builder_emit_producing_guarantee(db: &mut DiagnosticBuilder<'_, Self>) -> Self;
|
||||
|
||||
/// Creates a new `DiagnosticBuilder` that will return this type of guarantee.
|
||||
#[track_caller]
|
||||
fn make_diagnostic_builder(
|
||||
handler: &Handler,
|
||||
msg: impl Into<DiagnosticMessage>,
|
||||
) -> DiagnosticBuilder<'_, Self>;
|
||||
}
|
||||
|
||||
/// Private module for sealing the `IsError` helper trait.
|
||||
|
@ -166,6 +173,15 @@ impl EmissionGuarantee for ErrorGuaranteed {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn make_diagnostic_builder(
|
||||
handler: &Handler,
|
||||
msg: impl Into<DiagnosticMessage>,
|
||||
) -> DiagnosticBuilder<'_, Self> {
|
||||
DiagnosticBuilder::new_guaranteeing_error::<_, { Level::Error { lint: false } }>(
|
||||
handler, msg,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> DiagnosticBuilder<'a, ()> {
|
||||
|
@ -208,6 +224,13 @@ impl EmissionGuarantee for () {
|
|||
DiagnosticBuilderState::AlreadyEmittedOrDuringCancellation => {}
|
||||
}
|
||||
}
|
||||
|
||||
fn make_diagnostic_builder(
|
||||
handler: &Handler,
|
||||
msg: impl Into<DiagnosticMessage>,
|
||||
) -> DiagnosticBuilder<'_, Self> {
|
||||
DiagnosticBuilder::new(handler, Level::Warning(None), msg)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> DiagnosticBuilder<'a, !> {
|
||||
|
@ -247,6 +270,13 @@ impl EmissionGuarantee for ! {
|
|||
// Then fatally error, returning `!`
|
||||
crate::FatalError.raise()
|
||||
}
|
||||
|
||||
fn make_diagnostic_builder(
|
||||
handler: &Handler,
|
||||
msg: impl Into<DiagnosticMessage>,
|
||||
) -> DiagnosticBuilder<'_, Self> {
|
||||
DiagnosticBuilder::new_fatal(handler, msg)
|
||||
}
|
||||
}
|
||||
|
||||
/// In general, the `DiagnosticBuilder` uses deref to allow access to
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue