Skip to content

Add a lint helper attribute namespace - #163625

Open
mejrs wants to merge 4 commits into
rust-lang:mainfrom
mejrs:lint_helper_namespace-
Open

mejrs wants to merge 4 commits into
rust-lang:mainfrom
mejrs:lint_helper_namespace-

Conversation

@mejrs

@mejrs mejrs commented Oct 1, 2026 •

Copy link
Copy Markdown
Member

(and also port over three rustc lint attributes, as proof of concept)

Note

The below discussion assumes #162597 has been merged.

That PR implements an ambiguity error if #[tool::attr] can refer to either an attribute macro or a tool attribute. In particular this means adding a new built-in tool is a breaking change, if not done over an edition.

This PR implements parsing for the lint tool namespace (#[lint::attribute]) but doesn't add it as a builtin tool, so #![register_tool(lint)] is also required to use it. It raises an error on an unknown attribute within that namespace.

The primary motivations for creating this namespace are:

What is a "lint helper"

Attributes that change how or if a lint is emitted. Think of many of the internal attributes like #[rustc_as_ptr] , #[rustc_pass_by_value] etc. Other examples are #[deprecated] and #[must_not_suspend]. Even clippy has such a thing: #[clippy::format_args].

On breaking changes

This doesn't add lint as a built-in tool (like diagnostic, rustfmt, clippy etc are) so this pr is not a breaking change. The breaking changes are opt-in by using #![register_tool(lint)] in the crate root which is unstable at this time.

The way this PR is implemented means that, even if users could use #![register_tool(lint)] stably, they cannot stably use the namespace because an unknown attribute is an error and all valid attributes in it, at this time, are also feature gated. So there is no commitment to stability until we choose to stabilize an attribute in it.

Going forward

We can require using #![register_tool(lint)] indefinitely. It's possible to not require this this by adding lint as a builtin tool, but this (assuming #162597) breaks

#[lint::as_ptr]
struct Foo;

mod lint {
    // On stable rust, this could be a re-exported proc macro
    pub macro as_ptr {
        attr() { $($tt:tt)* } => { $($tt)* }
    }
}

However as nobody on github does this it's probably only theoretically breaking. It's non-breaking to add it across an edition.

r? @estebank
cc @WaffleLapkin @petrochenkov

@rustbot

rustbot commented Oct 1, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred in compiler/rustc_attr_parsing

cc @jdonszelmann, @JonathanBrouwer

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

cc @jdonszelmann, @JonathanBrouwer

Some changes occurred in compiler/rustc_attr_ir

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. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Oct 1, 2026
@rust-log-analyzer

This comment has been minimized.

@rust-bors

This comment has been minimized.

@petrochenkov petrochenkov self-assigned this Oct 2, 2026
@mejrs
mejrs force-pushed the lint_helper_namespace- branch from 6ca0789 to 1656f72 Compare October 2, 2026 16:32
@rustbot

rustbot commented Oct 2, 2026

Copy link
Copy Markdown
Collaborator

clippy is developed in its own repository. If possible, consider making this change to rust-lang/rust-clippy instead.

cc @rust-lang/clippy

@rustbot rustbot added the T-clippy Relevant to the Clippy team. label Oct 2, 2026
@rustbot

rustbot commented Oct 2, 2026

Copy link
Copy Markdown
Collaborator

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.

This branch has not been deployed

No deployments
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-review Status: Awaiting review from the assignee but also interested parties. T-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library 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