Trait rustc_errors::diagnostic::Diagnostic
source · pub trait Diagnostic<'a, G: EmissionGuarantee = ErrorGuaranteed> {
// Required method
fn into_diag(self, dcx: &'a DiagCtxt, level: Level) -> Diag<'a, G>;
}
Expand description
Trait implemented by error types. This is rarely implemented manually. Instead, use
#[derive(Diagnostic)]
– see rustc_macros::Diagnostic.
When implemented manually, it should be generic over the emission guarantee, i.e.:
ⓘ
impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for Foo { ... }
rather than being specific:
ⓘ
impl<'a> Diagnostic<'a> for Bar { ... } // the default type param is `ErrorGuaranteed`
impl<'a> Diagnostic<'a, ()> for Baz { ... }
There are two reasons for this.
- A diagnostic like
Foo
could be emitted at any level –level
is passed in tointo_diag
from outside. Even if in practice it is always emitted at a single level, we let the diagnostic creation/emission site determine the level (by usingcreate_err
,emit_warn
, etc.) rather than theDiagnostic
impl. - Derived impls are always generic, and it’s good for the hand-written impls to be consistent with them.