Skip to content

Diagnostic/subdiagnostic example struct /struct field fluent slugs outdated #1913

Open
@jieyouxu

Description

@jieyouxu

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: diagnosticsA-diagnostics-infraArea: diagnostics infrastructureA-translationArea: diagnostics translation and other translationsE-mediumDifficulty: might require some prior knowledge or code readingI-outdatedIssue: info is outdatedT-compilerRelevant to compiler team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions