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 to into_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 using create_err, emit_warn, etc.) rather than the Diagnostic impl.
  • Derived impls are always generic, and it’s good for the hand-written impls to be consistent with them.

Required Methods§


fn into_diag(self, dcx: &'a DiagCtxt, level: Level) -> Diag<'a, G>

Write out as a diagnostic out of DiagCtxt.

Implementations on Foreign Types§


impl<'a, T, G> Diagnostic<'a, G> for Spanned<T>
where T: Diagnostic<'a, G>, G: EmissionGuarantee,


fn into_diag(self, dcx: &'a DiagCtxt, level: Level) -> Diag<'a, G>


impl<G: EmissionGuarantee> Diagnostic<'_, G> for TargetDataLayoutErrors<'_>


fn into_diag(self, dcx: &DiagCtxt, level: Level) -> Diag<'_, G>