rustc-dev-guide icon indicating copy to clipboard operation
rustc-dev-guide copied to clipboard

Diagnostic/subdiagnostic example struct /struct field fluent slugs outdated

Open jieyouxu opened this issue 1 year ago • 0 comments

The example on https://rustc-dev-guide.rust-lang.org/diagnostics/diagnostic-structs.html is given as

#[derive(Diagnostic)]
#[diag(hir_analysis_field_already_declared, code = E0124)]
pub struct FieldAlreadyDeclared {
    pub field_name: Ident,
    #[primary_span]
    #[label]
    pub span: Span,
    #[label(previous_decl_label)]
    pub prev_span: Span,
}

but I believe this doesn't work anymore because the label's slug needs to be prefixed by the crate name, so the example needs to become e.g.

#[derive(Diagnostic)]
#[diag(hir_analysis_field_already_declared, code = E0124)]
pub struct FieldAlreadyDeclared {
    pub field_name: Ident,
    #[primary_span]
    #[label]
    pub span: Span,
    #[label(hir_analysis_previous_decl_label)]
    pub prev_span: Span,
}

Probably worth mentioning more explicitly because I wasted 15 minutes trying to debug why my label slugs weren't working lol

jieyouxu avatar Feb 26 '24 23:02 jieyouxu