Skip to content

Unexpected diagnostic field attributes accepted #444

@john-h-kastner-aws

Description

@john-h-kastner-aws

Given a structure deriving Diagnostic with an unexpected field attribute #[diagnostic(bogus)], I expect that miette would report an error but it does not. The following struct compiles without error, simply ignoring the attribute.

use miette::Diagnostic;
use thiserror::Error;
#[derive(Diagnostic, Error, Debug)]
#[error("")]
struct E {
    #[diagnostic(bogus)]
    i: i32
}

This is particularly problematic when the attribute is in fact supported on records. For example, if a field is annotated with #[diagnostic(transparent)], it feels reasonable to think it will forward the diagnostic impl to that field, but instead the annotation is silently ignored.

#[derive(Diagnostic, Error, Debug)]
#[error("")]
struct E2 {
    #[diagnostic(transparent)]
    e: E
}

This specifically lead to a bug in our library where some errors where missing source labels and help messages.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions