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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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
Comment on lines -380 to -388
#[derive(LintDiagnostic)]
#[diag(trait_selection_ignored_diagnostic_option)]
pub struct IgnoredDiagnosticOption {
pub option_name: &'static str,
#[label]
pub span: Span,
#[label(trait_selection_other_label)]
pub prev_span: Span,
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a duplicate of the one in ../on_unimplemented.rs, I think I accidentally copy pasted it in the past 😞

@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
Copy link
Contributor

oli-obk commented May 7, 2025

cc @estebank @weiznich you probably have opinions on this

@weiznich

This comment was marked as off-topic.

@joshtriplett joshtriplett added T-lang Relevant to the language team, which will review and decide on the PR/issue. 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, which will review and decide on the PR/issue. labels May 7, 2025
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. I-lang-nominated Nominated for discussion during a lang team meeting. proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. 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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants