Skip to content

Lint against empty cfg(any()/all())#158136

Open
clubby789 wants to merge 1 commit into
rust-lang:mainfrom
clubby789:lint-empty-cfg
Open

Lint against empty cfg(any()/all())#158136
clubby789 wants to merge 1 commit into
rust-lang:mainfrom
clubby789:lint-empty-cfg

Conversation

@clubby789

@clubby789 clubby789 commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Detect usages of cfg(any()) and cfg(all()) and suggest the literal boolean equivalents. When --lint-rust-version is available, gate the diagnostic appropriately.
Will need to be updated for #158134

Implements the lint suggested in rust-lang/rfcs#3695 (Tracking: #131204)
Tracking issue: #157574

@rustbot

rustbot commented Jun 19, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred in compiler/rustc_attr_parsing

cc @jdonszelmann, @JonathanBrouwer

@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) O-windows Operating system: Windows 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 Jun 19, 2026
@rustbot

rustbot commented Jun 19, 2026

Copy link
Copy Markdown
Collaborator

r? @Kivooeo

rustbot has assigned @Kivooeo.
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 73 candidates
  • Random selection from 19 candidates

@clubby789 clubby789 removed O-windows Operating system: Windows T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jun 19, 2026
@rust-log-analyzer

This comment has been minimized.

@rustbot

rustbot commented Jun 19, 2026

Copy link
Copy Markdown
Collaborator

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

cc @rust-lang/miri

@rustbot rustbot added the O-windows Operating system: Windows label Jun 19, 2026
@mejrs

mejrs commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Does this lint fire if the cfg predicate is produced in a macro expansion? I can see some valid use cases for producing all() etc in a macro.

Comment thread library/std/src/os/windows/raw.rs
@clubby789

Copy link
Copy Markdown
Contributor Author

Does this lint fire if the cfg predicate is produced in a macro expansion? I can see some valid use cases for producing all() etc in a macro.

No;

if list.is_empty() && !list.span.from_expansion() {

gates the emission.

@rust-log-analyzer

This comment has been minimized.

@rustbot

rustbot commented Jun 19, 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 Jun 19, 2026
@clubby789

Copy link
Copy Markdown
Contributor Author

This does overlap somewhat with clippy::non_minimal_cfg

list.span,
),
Some(sym::any) => {
if list.is_empty() && !list.span.from_expansion() {

@JonathanBrouwer JonathanBrouwer Jun 20, 2026

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.

Could you add a test that checks that this lint when the attribute is produced by a macro expansion?

View changes since the review

@@ -0,0 +1,18 @@
//@ revisions: novers lowvers highvers
//@[lowvers] compile-flags: -Zlint-rust-version=1.87.0

@JonathanBrouwer JonathanBrouwer Jun 20, 2026

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.

As you noted in the PR description, this PR needs to be rebased

View changes since the review

@eval_always = true
}

declare_lint! {

@JonathanBrouwer JonathanBrouwer Jun 20, 2026

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.

In rust-lang/rfcs#3695, this lint is mentioned as a "future possibility".
I'm not super familiar with the process, but I think this means that the change has not actually been FCP'ed yet by the lang team. Is this correct? If so, please lang-nominate this

View changes since the review

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 20, 2026
@rustbot

rustbot commented Jun 20, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-attributes Area: Attributes (`#[…]`, `#![…]`) O-windows Operating system: Windows S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-clippy Relevant to the Clippy team. 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.

9 participants