Skip to content

Unsafety checking on diagnostic attributes is inconsistent #165692

Closed

Description

@JonathanBrouwer

On existing diagnostic attributes, unsafe attributes produce an error:

#[unsafe(diagnostic::on_unimplemented(message = "xyz"))] //~ ERROR `diagnostic::on_unimplemented` is not an unsafe attribute
trait Test1 {}

On non-existing diagnostic attributes, it is ignored:

#[unsafe(diagnostic::invalid)] //~ WARN unknown diagnostic attribute
trait Test2 {}

This is a problem because it means introducing new diagnostic attributes is a breaking change.
This bug was introduced in rust 1.99, in 1.98 and earlier both examples produced an error.

We propose to go back to this, so both examples should produce an error.
This makes sense because diagnostic attributes should never effect behaviour, so the effect they have can never be unsafe.

cc @mejrs

Activity

  1. added
    A-attributes
    C-bug
    on Nov 9, 2026
  2. added
    needs-triage
    on Nov 9, 2026
  3. added
    I-lang-nominated
    on Nov 9, 2026
  4. added a commit that references this issue on Nov 9, 2026
  5. added a commit that references this issue on Nov 9, 2026
  6. removed
    I-lang-nominated
    on Nov 10, 2026
  7. added 3 commits that reference this issue on Nov 22, 2026
  8. removed
    needs-triage
    on Nov 22, 2026
  9. added a commit that references this issue on Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

A-attributesC-bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions