Skip to content

Make unsafe unknown diagnostic attributes an error again - #165782

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
mejrs:unsafe_attrs
Nov 22, 2026
Merged

rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
mejrs:unsafe_attrs

Conversation

@mejrs

@mejrs mejrs commented Nov 10, 2026 •

Copy link
Copy Markdown
Member

Fixes #165692

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, technically.

This bug was introduced in rust 1.99, in 1.98 and earlier both examples produced an error. This PR makes it an error again. We did not find any occurrences of this pattern on Github and it's rather contrived, so we believe nobody is affected by this.

An alternative way to address this is to make both examples trigger the unused_unsafe lint, instead of emitting an error.
However we'd prefer restoring the error behavior, as tool attributes, diagnostic included, should never effect behavior, so the effect they can never be unsafe.

r? @JonathanBrouwer

@rustbot

rustbot commented Nov 10, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred in compiler/rustc_attr_parsing

cc @jdonszelmann, @JonathanBrouwer

@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 10, 2026
@mejrs mejrs added the I-lang-nominated Nominated for discussion during a lang team meeting. label Nov 10, 2026
@traviscross traviscross added I-lang-radar Items that are on lang's radar and will need eventual work or consideration. P-lang-drag-1 Lang team prioritization drag level 1. https://rust-lang.zulipchat.com/#narrow/channel/410516-t-lang labels Nov 11, 2026
@traviscross

Copy link
Copy Markdown
Contributor

Makes sense to me. Thanks @mejrs.

@rfcbot fcp merge lang

@rust-rfcbot rust-rfcbot added the T-lang Relevant to the language team label Nov 11, 2026
@rust-rfcbot

rust-rfcbot commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

@traviscross has proposed to merge this. The next step is review by the rest of the tagged team members:

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

cc @rust-lang/lang-advisors: FCP proposed for lang, please feel free to register concerns.
See this document for info about what commands tagged team members can give me.

@rust-rfcbot rust-rfcbot added proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. labels Nov 11, 2026

@JonathanBrouwer JonathanBrouwer left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r=me with lang approval

View changes since this review

@JonathanBrouwer JonathanBrouwer added S-waiting-on-t-lang Status: Awaiting decision from T-lang and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 11, 2026
@rust-rfcbot rust-rfcbot added final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. and removed proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. labels Nov 11, 2026
@rust-rfcbot

Copy link
Copy Markdown
Collaborator

🔔 This is now entering its final comment period, as per the review above. 🔔

@scottmcm

Copy link
Copy Markdown
Member

If I'm reading this right, this means that unsafe diagnostics attributes are always an error, known or not?

That sounds good to me, since the point of the diagnostics namespace is that it cannot have semantic effect and thus necessarily cannot ever have preconditions.

@rfcbot reviewed

@JonathanBrouwer

JonathanBrouwer commented Nov 11, 2026 •

Copy link
Copy Markdown
Member

If I'm reading this right, this means that unsafe diagnostics attributes are always an error, known or not?

Before this PR, unknown unsafe diagnostic attributes don't produce an error.
After this PR, unsafe diagnostic attributes are always an error.

@mejrs

mejrs commented Nov 11, 2026

Copy link
Copy Markdown
Member Author

Tool attributes in general cannot be unsafe.

@traviscross traviscross removed I-lang-nominated Nominated for discussion during a lang team meeting. P-lang-drag-1 Lang team prioritization drag level 1. https://rust-lang.zulipchat.com/#narrow/channel/410516-t-lang labels Nov 18, 2026
@rust-rfcbot rust-rfcbot added finished-final-comment-period The final comment period is finished for this PR / Issue. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. to-announce Announce this issue on triage meeting and removed final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. labels Nov 21, 2026
@rust-rfcbot

Copy link
Copy Markdown
Collaborator

The final comment period, with a disposition to merge, as per the review above, is now complete.

As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.

@JonathanBrouwer JonathanBrouwer left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rust-bors

rust-bors Bot commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

📌 Commit eaa4d94 has been approved by JonathanBrouwer

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 22, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Nov 22, 2026
Make unsafe unknown diagnostic attributes an error again

Fixes rust-lang#165692

On existing diagnostic attributes, unsafe attributes produce an error:
```rust
#[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:
```rust
#[unsafe(diagnostic::invalid)] //~ WARN unknown diagnostic attribute
trait Test2 {}
```

This is a problem because it means introducing new diagnostic attributes is a breaking change, technically.

This bug was introduced in rust 1.99, in 1.98 and earlier both examples produced an error. This PR makes it an error again. We did not find any occurrences of this pattern on Github and it's rather contrived, so we believe nobody is affected by this.

An alternative way to address this is to make both examples trigger the `unused_unsafe` lint, instead of emitting an error.
However we'd prefer restoring the error behavior, as tool attributes, `diagnostic` included, should never effect behavior, so the effect they can never be unsafe.

r? @JonathanBrouwer
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Nov 22, 2026
Make unsafe unknown diagnostic attributes an error again

Fixes rust-lang#165692

On existing diagnostic attributes, unsafe attributes produce an error:
```rust
#[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:
```rust
#[unsafe(diagnostic::invalid)] //~ WARN unknown diagnostic attribute
trait Test2 {}
```

This is a problem because it means introducing new diagnostic attributes is a breaking change, technically.

This bug was introduced in rust 1.99, in 1.98 and earlier both examples produced an error. This PR makes it an error again. We did not find any occurrences of this pattern on Github and it's rather contrived, so we believe nobody is affected by this.

An alternative way to address this is to make both examples trigger the `unused_unsafe` lint, instead of emitting an error.
However we'd prefer restoring the error behavior, as tool attributes, `diagnostic` included, should never effect behavior, so the effect they can never be unsafe.

r? @JonathanBrouwer
rust-bors Bot pushed a commit that referenced this pull request Nov 22, 2026
…uwer

Rollup of 19 pull requests

Successful merges:

 - #166266 (miri subtree update)
 - #164878 (Don't require `extern "llvm-intrinsic"` return structs to be `#[repr(packed)]`)
 - #165008 (Support `NonNull` pointers as `asm!` input operands)
 - #165892 (`rustc_builtin_macros` cleanup, part 10)
 - #165930 (Add red-green mark when dumping dep graph. Show DefIds if available)
 - #166280 (std: also mark doctests with skip_unsupported_miri_tests)
 - #166295 (use `cfg!(overflow_checks)` in `overflow_checks` intrinsic instead of `cfg!(debug_assertions)`)
 - #164485 (Stabilize unchecked `nonzero_ops`)
 - #165618 (Implement RangeIntersect on core::range types)
 - #165782 (Make unsafe unknown diagnostic attributes an error again)
 - #165833 (Deallocate with the right provenance on Windows)
 - #165834 (Implement tidy alphabetical --bless on Windows)
 - #165889 (Fix docs of alloc fn: Allocator API stabilized)
 - #165923 (Don't load/store a LLVM aggregate type when returning an array from a generic SIMD intrinsic)
 - #166012 (Added more queries to AdtDef in rustc_public to check for rust language types)
 - #166186 (OpenOptions::append: clarify docs)
 - #166216 (Stop using #![no_core] in profiler_builtins)
 - #166259 (fmt: Improve `Debug` for `FormattingOptions`)
 - #166263 (Show slice split results for empty and singleton slices)
rust-bors Bot pushed a commit that referenced this pull request Nov 22, 2026
…uwer

Rollup of 18 pull requests

Successful merges:

 - #164878 (Don't require `extern "llvm-intrinsic"` return structs to be `#[repr(packed)]`)
 - #165008 (Support `NonNull` pointers as `asm!` input operands)
 - #165892 (`rustc_builtin_macros` cleanup, part 10)
 - #165930 (Add red-green mark when dumping dep graph. Show DefIds if available)
 - #166280 (std: also mark doctests with skip_unsupported_miri_tests)
 - #166295 (use `cfg!(overflow_checks)` in `overflow_checks` intrinsic instead of `cfg!(debug_assertions)`)
 - #164485 (Stabilize unchecked `nonzero_ops`)
 - #165618 (Implement RangeIntersect on core::range types)
 - #165782 (Make unsafe unknown diagnostic attributes an error again)
 - #165833 (Deallocate with the right provenance on Windows)
 - #165834 (Implement tidy alphabetical --bless on Windows)
 - #165889 (Fix docs of alloc fn: Allocator API stabilized)
 - #165923 (Don't load/store a LLVM aggregate type when returning an array from a generic SIMD intrinsic)
 - #166012 (Added more queries to AdtDef in rustc_public to check for rust language types)
 - #166186 (OpenOptions::append: clarify docs)
 - #166216 (Stop using #![no_core] in profiler_builtins)
 - #166259 (fmt: Improve `Debug` for `FormattingOptions`)
 - #166263 (Show slice split results for empty and singleton slices)
rust-bors Bot pushed a commit that referenced this pull request Nov 22, 2026
…uwer

Rollup of 18 pull requests

Successful merges:

 - #164878 (Don't require `extern "llvm-intrinsic"` return structs to be `#[repr(packed)]`)
 - #165008 (Support `NonNull` pointers as `asm!` input operands)
 - #165892 (`rustc_builtin_macros` cleanup, part 10)
 - #165930 (Add red-green mark when dumping dep graph. Show DefIds if available)
 - #166280 (std: also mark doctests with skip_unsupported_miri_tests)
 - #166295 (use `cfg!(overflow_checks)` in `overflow_checks` intrinsic instead of `cfg!(debug_assertions)`)
 - #164485 (Stabilize unchecked `nonzero_ops`)
 - #165618 (Implement RangeIntersect on core::range types)
 - #165782 (Make unsafe unknown diagnostic attributes an error again)
 - #165833 (Deallocate with the right provenance on Windows)
 - #165834 (Implement tidy alphabetical --bless on Windows)
 - #165889 (Fix docs of alloc fn: Allocator API stabilized)
 - #165923 (Don't load/store a LLVM aggregate type when returning an array from a generic SIMD intrinsic)
 - #166012 (Added more queries to AdtDef in rustc_public to check for rust language types)
 - #166186 (OpenOptions::append: clarify docs)
 - #166216 (Stop using #![no_core] in profiler_builtins)
 - #166259 (fmt: Improve `Debug` for `FormattingOptions`)
 - #166263 (Show slice split results for empty and singleton slices)
@rust-bors
rust-bors Bot merged commit 7998bd4 into rust-lang:main Nov 22, 2026
14 checks passed
@rustbot rustbot added this to the 1.102.0 milestone Nov 22, 2026
rust-bors Bot pushed a commit that referenced this pull request Nov 22, 2026
Rollup merge of #165782 - mejrs:unsafe_attrs, r=JonathanBrouwer

Make unsafe unknown diagnostic attributes an error again

Fixes #165692

On existing diagnostic attributes, unsafe attributes produce an error:
```rust
#[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:
```rust
#[unsafe(diagnostic::invalid)] //~ WARN unknown diagnostic attribute
trait Test2 {}
```

This is a problem because it means introducing new diagnostic attributes is a breaking change, technically.

This bug was introduced in rust 1.99, in 1.98 and earlier both examples produced an error. This PR makes it an error again. We did not find any occurrences of this pattern on Github and it's rather contrived, so we believe nobody is affected by this.

An alternative way to address this is to make both examples trigger the `unused_unsafe` lint, instead of emitting an error.
However we'd prefer restoring the error behavior, as tool attributes, `diagnostic` included, should never effect behavior, so the effect they can never be unsafe.

r? @JonathanBrouwer
mehmettoplu-rs pushed a commit to mehmettoplu-rs/rustc_codegen_gcc that referenced this pull request Nov 27, 2026
…uwer

Rollup of 18 pull requests

Successful merges:

 - rust-lang/rust#164878 (Don't require `extern "llvm-intrinsic"` return structs to be `#[repr(packed)]`)
 - rust-lang/rust#165008 (Support `NonNull` pointers as `asm!` input operands)
 - rust-lang/rust#165892 (`rustc_builtin_macros` cleanup, part 10)
 - rust-lang/rust#165930 (Add red-green mark when dumping dep graph. Show DefIds if available)
 - rust-lang/rust#166280 (std: also mark doctests with skip_unsupported_miri_tests)
 - rust-lang/rust#166295 (use `cfg!(overflow_checks)` in `overflow_checks` intrinsic instead of `cfg!(debug_assertions)`)
 - rust-lang/rust#164485 (Stabilize unchecked `nonzero_ops`)
 - rust-lang/rust#165618 (Implement RangeIntersect on core::range types)
 - rust-lang/rust#165782 (Make unsafe unknown diagnostic attributes an error again)
 - rust-lang/rust#165833 (Deallocate with the right provenance on Windows)
 - rust-lang/rust#165834 (Implement tidy alphabetical --bless on Windows)
 - rust-lang/rust#165889 (Fix docs of alloc fn: Allocator API stabilized)
 - rust-lang/rust#165923 (Don't load/store a LLVM aggregate type when returning an array from a generic SIMD intrinsic)
 - rust-lang/rust#166012 (Added more queries to AdtDef in rustc_public to check for rust language types)
 - rust-lang/rust#166186 (OpenOptions::append: clarify docs)
 - rust-lang/rust#166216 (Stop using #![no_core] in profiler_builtins)
 - rust-lang/rust#166259 (fmt: Improve `Debug` for `FormattingOptions`)
 - rust-lang/rust#166263 (Show slice split results for empty and singleton slices)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-attributes Area: Attributes (`#[…]`, `#![…]`) disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. I-lang-radar Items that are on lang's radar and will need eventual work or consideration. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team to-announce Announce this issue on triage meeting

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unsafety checking on diagnostic attributes is inconsistent

6 participants