Skip to content

Split up the unknown_or_malformed_diagnostic_attributes lint #140717

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 13, 2025

Conversation

mejrs
Copy link
Contributor

@mejrs mejrs commented May 6, 2025

This splits up the lint into the following lint group:

  • unknown_diagnostic_attributes - triggers if the attribute is unknown to the current compiler
  • misplaced_diagnostic_attributes - triggers if the attribute exists but it is not placed on the item kind it's meant for
  • malformed_diagnostic_attributes - triggers if the attribute's syntax or options are invalid
  • malformed_diagnostic_format_literals - triggers if the format string literal is invalid, for example if it has unpaired curly braces or invalid parameters
  • this pr doesn't create it, but future lints for things like deprecations can also go here.

This PR does not start emitting lints in places that previously did not.

Motivation

I want to have finer control over what unknown_or_malformed_diagnostic_attributes does

I have a project with fairly low msrv that is/will have a lower msrv than future diagnostic attributes. So lints will be emitted when I or others compile it on a lower msrv.

At this time, there are two options to silence these lints:

  • #[allow(unknown_or_malformed_diagnostic_attributes)] - this risks diagnostic regressions if I (or others) mess up using the attribute, or if the attribute's syntax ever changes.
  • write a build script to detect the compiler version and emit cfgs, and then conditionally enable the attribute:
    #[cfg_attr(rust_version_99, diagnostic::new_attr_in_rust_99(thing = ..))]`
    struct Foo;
    or conditionally allow the lint:
    // lib.rs
    #![cfg_attr(not(current_rust), allow(unknown_or_malformed_diagnostic_attributes))]

I like to avoid using build scripts if I can, so the following works much better for me. That is what this PR will let me do in the future:

    #[allow(unknown_diagnostic_attribute, reason = "attribute came out in rust 1.99 but msrv is 1.70")]
    #[diagnostic::new_attr_in_rust_99(thing = ..)]`
    struct Foo;

@rustbot
Copy link
Collaborator

rustbot commented May 6, 2025

r? @oli-obk

rustbot has assigned @oli-obk.
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

@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 May 6, 2025
@rustbot
Copy link
Collaborator

rustbot commented May 6, 2025

Some changes occurred in compiler/rustc_passes/src/check_attr.rs

cc @jdonszelmann

@mejrs
Copy link
Contributor Author

mejrs commented May 6, 2025

I know creating a new lint requires lang team approval, but I'm unsure if splitting a lint needs it.

@rustbot labels +I-lang-nominated

@rustbot rustbot added the I-lang-nominated Nominated for discussion during a lang team meeting. label May 6, 2025
@rust-log-analyzer

This comment has been minimized.

@mejrs mejrs force-pushed the diagnostic_lints branch from fd8016c to eb183ad Compare May 6, 2025 22:04
@oli-obk

This comment was marked as resolved.

@weiznich

This comment was marked as off-topic.

@joshtriplett joshtriplett added T-lang Relevant to the language team and removed T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 7, 2025
@joshtriplett
Copy link
Member

This seems consistent with how diagnostic attributes are intended to be used, and useful for ensuring that when you allow one of them because you know what you're doing, you still benefit from the other warnings.

@rfcbot merge

@rfcbot
Copy link
Collaborator

rfcbot commented May 7, 2025

Team member @joshtriplett 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!

See this document for info about what commands tagged team members can give me.

@rfcbot 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 May 7, 2025
@traviscross
Copy link
Contributor

@rfcbot reviewed

@joshtriplett joshtriplett added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed T-lang Relevant to the language team labels May 7, 2025
@traviscross traviscross added the P-lang-drag-2 Lang team prioritization drag level 2.https://rust-lang.zulipchat.com/#narrow/channel/410516-t-lang. label May 16, 2025
@weiznich
Copy link
Contributor

Just to add the context why this was implemented as a single lint: #114452 (comment)

Which means @petrochenkov might still have opinions about this.

@tmandry
Copy link
Member

tmandry commented May 21, 2025

@rfcbot reviewed

I think we definitely want to split out the "unknown" case for the reason given in the description. I feel less strongly about the other cases, but I can imagine wanting to allow those because of version skew, e.g. when a lint doesn't apply to certain item kinds in older versions of the compiler but does in newer versions.

@estebank
Copy link
Contributor

estebank commented May 22, 2025

Responding to the earlier ping, I'm always in favor of more targeted lints, so I'm in favor of turning this into a group.

@mejrs mejrs force-pushed the diagnostic_lints branch from eb183ad to 8ecabf8 Compare May 24, 2025 16:22
@tmandry
Copy link
Member

tmandry commented May 28, 2025

@rfcbot reviewed

Trying again.

@traviscross
Copy link
Contributor

@rfcbot ping

@rfcbot rfcbot added the final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. label May 28, 2025
@rfcbot
Copy link
Collaborator

rfcbot commented May 28, 2025

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

Copy link
Contributor

@traviscross traviscross left a comment

Choose a reason for hiding this comment

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

Looks OK to me.

@bors
Copy link
Collaborator

bors commented Jun 13, 2025

☔ The latest upstream changes (presumably #142432) made this pull request unmergeable. Please resolve the merge conflicts.

@mejrs mejrs force-pushed the diagnostic_lints branch from 3e654e6 to f975708 Compare June 13, 2025 10:16
@apiraino apiraino removed the to-announce Announce this issue on triage meeting label Jun 26, 2025
@mejrs
Copy link
Contributor Author

mejrs commented Jul 9, 2025

@oli-obk are you available to review the implementation? I can reroll otherwise.

@oli-obk
Copy link
Contributor

oli-obk commented Jul 10, 2025

@bors r+

@bors
Copy link
Collaborator

bors commented Jul 10, 2025

📌 Commit f975708 has been approved by oli-obk

It is now in the queue for this repository.

@bors bors 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 Jul 10, 2025
bors added a commit that referenced this pull request Jul 10, 2025
Split up the `unknown_or_malformed_diagnostic_attributes` lint

This splits up the lint into the following lint group:
- `unknown_diagnostic_attributes` - triggers if the attribute is unknown to the current compiler
- `misplaced_diagnostic_attributes` - triggers if the attribute exists but it is not placed on the item kind it's meant for
- `malformed_diagnostic_attributes` - triggers if the attribute's syntax or options are invalid
- `malformed_diagnostic_format_literals` - triggers if the format string literal is invalid, for example if it has unpaired curly braces or invalid parameters
- this pr doesn't create it, but future lints for things like deprecations can also go here.

This PR does not start emitting lints in places that previously did not.

## Motivation

I want to have finer control over what `unknown_or_malformed_diagnostic_attributes` does

I have a project with fairly low msrv that is/will have a lower msrv than future diagnostic attributes. So lints will be emitted when I or others compile it on a lower msrv.

At this time, there are two options to silence these lints:

-  `#[allow(unknown_or_malformed_diagnostic_attributes)]` - this risks diagnostic regressions if I (or others) mess up using the attribute, or if the attribute's syntax ever changes.
- write a build script to detect the compiler version and emit cfgs, and then conditionally enable the attribute:
    ```rust
    #[cfg_attr(rust_version_99, diagnostic::new_attr_in_rust_99(thing = ..))]`
    struct Foo;
    ```
    or conditionally `allow`  the lint:
    ```rust
   // lib.rs
   #![cfg_attr(not(current_rust), allow(unknown_or_malformed_diagnostic_attributes))]
   ```

I like to avoid using build scripts if I can, so the following works much better for me. That is what this PR will let me do in the future:
```rust
    #[allow(unknown_diagnostic_attribute, reason = "attribute came out in rust 1.99 but msrv is 1.70")]
    #[diagnostic::new_attr_in_rust_99(thing = ..)]`
    struct Foo;
@bors
Copy link
Collaborator

bors commented Jul 10, 2025

⌛ Testing commit f975708 with merge 25c1ecc...

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Collaborator

bors commented Jul 10, 2025

💔 Test failed - checks-actions

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jul 10, 2025
@mejrs mejrs force-pushed the diagnostic_lints branch from f975708 to cee3868 Compare July 10, 2025 23:24
@mejrs mejrs force-pushed the diagnostic_lints branch from cee3868 to a7bf5c4 Compare July 10, 2025 23:24
@oli-obk
Copy link
Contributor

oli-obk commented Jul 11, 2025

@bors r+

@bors
Copy link
Collaborator

bors commented Jul 11, 2025

📌 Commit a7bf5c4 has been approved by oli-obk

It is now in the queue for this repository.

@bors bors 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 Jul 11, 2025
@bors
Copy link
Collaborator

bors commented Jul 13, 2025

⌛ Testing commit a7bf5c4 with merge b1d2f2c...

@bors
Copy link
Collaborator

bors commented Jul 13, 2025

☀️ Test successful - checks-actions
Approved by: oli-obk
Pushing b1d2f2c to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jul 13, 2025
@bors bors merged commit b1d2f2c into rust-lang:master Jul 13, 2025
12 checks passed
@rustbot rustbot added this to the 1.90.0 milestone Jul 13, 2025
Copy link
Contributor

What is this? This is an experimental post-merge analysis report that shows differences in test outcomes between the merged PR and its parent PR.

Comparing 288e94c (parent) -> b1d2f2c (this PR)

Test differences

Show 277 test diffs

277 doctest diffs were found. These are ignored, as they are noisy.

Test dashboard

Run

cargo run --manifest-path src/ci/citool/Cargo.toml -- \
    test-dashboard b1d2f2c64c6254b2a935d6a2d29b68f4511cf500 --output-dir test-dashboard

And then open test-dashboard/index.html in your browser to see an overview of all executed tests.

Job duration changes

  1. x86_64-apple-2: 4054.2s -> 5567.4s (37.3%)
  2. dist-x86_64-apple: 7720.1s -> 10386.6s (34.5%)
  3. dist-aarch64-apple: 5498.4s -> 6454.7s (17.4%)
  4. aarch64-apple: 4631.3s -> 5132.8s (10.8%)
  5. x86_64-msvc-1: 9445.1s -> 8515.5s (-9.8%)
  6. dist-apple-various: 6656.2s -> 7285.2s (9.5%)
  7. x86_64-rust-for-linux: 2798.3s -> 3001.5s (7.3%)
  8. dist-aarch64-msvc: 5791.5s -> 5388.0s (-7.0%)
  9. x86_64-apple-1: 7663.0s -> 7178.3s (-6.3%)
  10. aarch64-msvc-2: 5194.1s -> 5459.9s (5.1%)
How to interpret the job duration changes?

Job durations can vary a lot, based on the actual runner instance
that executed the job, system noise, invalidated caches, etc. The table above is provided
mostly for t-infra members, for simpler debugging of potential CI slow-downs.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (b1d2f2c): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

Results (primary 1.6%, secondary -0.6%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
1.6% [1.6%, 1.6%] 1
Regressions ❌
(secondary)
1.5% [1.5%, 1.5%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.7% [-2.7%, -2.7%] 1
All ❌✅ (primary) 1.6% [1.6%, 1.6%] 1

Cycles

Results (primary 2.4%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
2.4% [2.4%, 2.4%] 1
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 2.4% [2.4%, 2.4%] 1

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 468.578s -> 466.487s (-0.45%)
Artifact size: 374.72 MiB -> 374.73 MiB (0.00%)

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. merged-by-bors This PR was explicitly merged by bors. 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.