Skip to content

Use a linting node closer the parsing of #[cfg_attr]#155120

Merged
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
Urgau:check-cfg-allow-cfg_attr-mod
Apr 11, 2026
Merged

Use a linting node closer the parsing of #[cfg_attr]#155120
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
Urgau:check-cfg-allow-cfg_attr-mod

Conversation

@Urgau
Copy link
Copy Markdown
Member

@Urgau Urgau commented Apr 10, 2026

The parsing of #[cfg_attr] unconditionally used the crate-root as a linting node to attach lints, but the unexpected_cfgs lint can fire when parsing the attribute and users expect to be able to allow it at places other than the crate-root.

Let's instead use the linting node id, which is unfortunately always the parent but that's better than the crate-root when you are in a sub-module.

The parsing of #[cfg] and other already use the expansion linting node id, so no change required there.

Related to #155118

r? @JonathanBrouwer
cc @jschwe

@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 10, 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 10, 2026
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.

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors bot commented Apr 11, 2026

📌 Commit f97143d 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 11, 2026
jhpratt added a commit to jhpratt/rust that referenced this pull request Apr 11, 2026
…, r=JonathanBrouwer

Use a linting node closer the parsing of `#[cfg_attr]`

The parsing of `#[cfg_attr]` unconditionally used the crate-root as a linting node to attach lints, but the `unexpected_cfgs` lint can fire when parsing the attribute and users expect to be able to allow it at places other than the crate-root.

Let's instead use the linting node id, which is unfortunately always the parent but that's better than the crate-root when you are in a sub-module.

The parsing of `#[cfg]` and other already use the expansion linting node id, so no change required there.

Related to rust-lang#155118
rust-bors bot pushed a commit that referenced this pull request Apr 11, 2026
Rollup of 3 pull requests

Successful merges:

 - #154827 (distinguish "expected a single argument" and "expected an argument" on attribute parsing)
 - #155104 (bootstrap: auto-patch libgccjit.so for NixOS)
 - #155120 (Use a linting node closer the parsing of `#[cfg_attr]`)
@rust-bors rust-bors bot merged commit b2088a2 into rust-lang:main Apr 11, 2026
11 checks passed
rust-timer added a commit that referenced this pull request Apr 11, 2026
Rollup merge of #155120 - Urgau:check-cfg-allow-cfg_attr-mod, r=JonathanBrouwer

Use a linting node closer the parsing of `#[cfg_attr]`

The parsing of `#[cfg_attr]` unconditionally used the crate-root as a linting node to attach lints, but the `unexpected_cfgs` lint can fire when parsing the attribute and users expect to be able to allow it at places other than the crate-root.

Let's instead use the linting node id, which is unfortunately always the parent but that's better than the crate-root when you are in a sub-module.

The parsing of `#[cfg]` and other already use the expansion linting node id, so no change required there.

Related to #155118
@rustbot rustbot added this to the 1.97.0 milestone Apr 11, 2026
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.

3 participants