Skip to content

Clean up AttributeLintKind and refactor diagnostic attribute linting#155215

Merged
rust-bors[bot] merged 8 commits intorust-lang:mainfrom
mejrs:condense_diag_lints
Apr 16, 2026
Merged

Clean up AttributeLintKind and refactor diagnostic attribute linting#155215
rust-bors[bot] merged 8 commits intorust-lang:mainfrom
mejrs:condense_diag_lints

Conversation

@mejrs
Copy link
Copy Markdown
Contributor

@mejrs mejrs commented Apr 12, 2026

There was a fair amount of duplication here, and thanks to the proliferation of new diagnostic attributes these days, it was threatening to grow bigger.

@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 12, 2026

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 Apr 12, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 12, 2026

r? @JohnTitor

rustbot has assigned @JohnTitor.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 69 candidates
  • Random selection from 12 candidates

@mejrs mejrs force-pushed the condense_diag_lints branch from 0dd591a to a4e8640 Compare April 12, 2026 21:54
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 12, 2026

The Miri subtree was changed

cc @rust-lang/miri

@rustbot rustbot added the WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) label Apr 12, 2026
@rustbot

This comment has been minimized.

@mejrs mejrs force-pushed the condense_diag_lints branch from a4e8640 to 0dd591a Compare April 12, 2026 22:00
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 12, 2026

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@mejrs
Copy link
Copy Markdown
Contributor Author

mejrs commented Apr 13, 2026

@rustbot label -WG-trait-system-refactor

@rustbot rustbot removed the WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) label Apr 13, 2026
span,
);
}
if matches!(mode, Mode::RustcOnUnimplemented) {
Copy link
Copy Markdown
Contributor

@JonathanBrouwer JonathanBrouwer Apr 14, 2026

Choose a reason for hiding this comment

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

I don't really like matches! here because if we ever add another rustc diagnostic attribute, we could forget to check it. How about a method mode.should_error(), that has an exhaustive match in it?

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It doesn't actually matter, assuming we don't ship a std that compiles with warnings?

So far my decisions on whether rustc_on_unimplemented errors or issues a diagnostic namespace lint have been largely focused on keeping the implementation simple:

  • erroring is easier than adding AttributeLintKind variants
  • so hard error in rustc_on_unimplemented-only paths to simplify there
  • issue lints in shared paths so you don't have to care about which attr it is

In fact, maybe this should just be a warning regardless?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

That mentality also sounds reasonable to me, lets make this a warning to keep the implementation simple

Copy link
Copy Markdown
Contributor Author

@mejrs mejrs Apr 14, 2026

Choose a reason for hiding this comment

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

I think I remember why it is this way, I applied the suggestion and then I got annoyed because

LL | #[rustc_on_unimplemented(lorem = "")]
   |                          ^^^^^^^^^^ invalid option found here
   |
   = help: only `message`, `note` and `label` are allowed as options

is not quite right.

The last commit fixes that by letting you customize the "allowed options" list per attribute. Note that I'm inclined to have an attribute with only "note" allowed, (#155200 (comment)) so we will need some kind of customization (or more lint variants) anyway.

Let me know what you think about the last few commits, idm backing it out if you prefer.

Copy link
Copy Markdown
Contributor

@JonathanBrouwer JonathanBrouwer Apr 15, 2026

Choose a reason for hiding this comment

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

Seems reasonable, especially since we need this in the future :)

Copy link
Copy Markdown
Contributor

@JonathanBrouwer JonathanBrouwer left a comment

Choose a reason for hiding this comment

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

r=me with nit fixed
@bors delegate

View changes since this review

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors bot commented Apr 14, 2026

✌️ @mejrs, you can now approve this pull request!

If @JonathanBrouwer told you to "r=me" after making some further change, then please make that change and post @bors r=JonathanBrouwer.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@mejrs mejrs force-pushed the condense_diag_lints branch from 79d2d9a to 103adaa Compare April 15, 2026 10:36
@rust-log-analyzer

This comment has been minimized.

@mejrs mejrs force-pushed the condense_diag_lints branch from 103adaa to d6bccac Compare April 15, 2026 11:50
@JonathanBrouwer
Copy link
Copy Markdown
Contributor

@bors r+ rollup

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors bot commented Apr 15, 2026

📌 Commit d6bccac 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 Apr 15, 2026
jhpratt added a commit to jhpratt/rust that referenced this pull request Apr 16, 2026
…hanBrouwer

Clean up `AttributeLintKind` and refactor diagnostic attribute linting

There was a fair amount of duplication here, and thanks to the proliferation of new diagnostic attributes these days, it was threatening to grow bigger.
rust-bors bot pushed a commit that referenced this pull request Apr 16, 2026
Rollup of 18 pull requests

Successful merges:

 - #154595 (Emit fatal on invalid const args with nested defs)
 - #154599 (report the `varargs_without_pattern` lint in deps)
 - #154699 (`core::unicode`: Replace `Cased` table with `Lt`)
 - #155353 (resolve: Remove `inaccessible_ctor_reexport` resolver field)
 - #155357 (Add `--remap-path-scope` as unstable in rustdoc)
 - #150649 (clippy fix: non_canonical_clone_impl)
 - #154604 (abort in core)
 - #154616 (Add `--quiet` flag to x.py and bootstrap to suppress output)
 - #154970 (rustdoc: preserve `doc(cfg)` on locally re-exported type aliases)
 - #155215 (Clean up `AttributeLintKind` and refactor diagnostic attribute linting)
 - #155228 (Check diagnostic output in incremental `cpass` and `rpass` revisions)
 - #155266 (Adjust release notes for post-merge feedback)
 - #155326 (Disallow ZST allocations with `TypedArena`.)
 - #155334 (docs: Use `0b1` instead of `NonZero::MIN` in `NonZero::bit_width` doctests)
 - #155340 (Handle nonnull pattern types in size skeleton)
 - #155347 (Add push_mut and new Layout methods to release notes)
 - #155356 (remove calls to AliasTyKind::def_id)
 - #155364 (Reduce diagnostic type visibilities.)
rust-bors bot pushed a commit that referenced this pull request Apr 16, 2026
Rollup of 18 pull requests

Successful merges:

 - #154451 (Require that a `<_ as Try>::Residual` implement the `Residual` trait)
 - #154595 (Emit fatal on invalid const args with nested defs)
 - #154599 (report the `varargs_without_pattern` lint in deps)
 - #154699 (`core::unicode`: Replace `Cased` table with `Lt`)
 - #155353 (resolve: Remove `inaccessible_ctor_reexport` resolver field)
 - #155357 (Add `--remap-path-scope` as unstable in rustdoc)
 - #150649 (clippy fix: non_canonical_clone_impl)
 - #154604 (abort in core)
 - #154616 (Add `--quiet` flag to x.py and bootstrap to suppress output)
 - #155215 (Clean up `AttributeLintKind` and refactor diagnostic attribute linting)
 - #155228 (Check diagnostic output in incremental `cpass` and `rpass` revisions)
 - #155266 (Adjust release notes for post-merge feedback)
 - #155326 (Disallow ZST allocations with `TypedArena`.)
 - #155334 (docs: Use `0b1` instead of `NonZero::MIN` in `NonZero::bit_width` doctests)
 - #155340 (Handle nonnull pattern types in size skeleton)
 - #155347 (Add push_mut and new Layout methods to release notes)
 - #155356 (remove calls to AliasTyKind::def_id)
 - #155364 (Reduce diagnostic type visibilities.)
@rust-bors rust-bors bot merged commit 0d98e0d into rust-lang:main Apr 16, 2026
11 checks passed
rust-timer added a commit that referenced this pull request Apr 16, 2026
Rollup merge of #155215 - mejrs:condense_diag_lints, r=JonathanBrouwer

Clean up `AttributeLintKind` and refactor diagnostic attribute linting

There was a fair amount of duplication here, and thanks to the proliferation of new diagnostic attributes these days, it was threatening to grow bigger.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-attributes Area: Attributes (`#[…]`, `#![…]`) 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants