Skip to main content

subdiagnostic_derive

Function subdiagnostic_derive 

Source
pub(crate) fn subdiagnostic_derive(s: Structure<'_>) -> TokenStream
Expand description

Implements #[derive(Subdiagnostic)], which allows for labels, notes, helps and suggestions to be specified as a structs or enums, independent from the actual diagnostics emitting code or diagnostic derives.

ⓘ
#[derive(Subdiagnostic)]
pub(crate) enum BuiltinUnusedDocCommentSub {
    #[help("use `//` for a plain comment")]
    PlainHelp,
    #[help("use `/* */` for a plain comment")]
    BlockHelp,
}

Then, later, use the subdiagnostic in a diagnostic:

ⓘ
#[derive(Diagnostic)]
#[diag("unused doc comment")]
pub(crate) struct BuiltinUnusedDocComment<'a> {
    pub kind: &'a str,
    #[label("rustdoc does not generate documentation for {$kind}")]
    pub label: Span,
    #[subdiagnostic]
    pub sub: BuiltinUnusedDocCommentSub,
}