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

Comment thread compiler/rustc_attr_parsing/src/attributes/cfg.rs
Comment thread tests/ui/lint/empty-cfg-predicate.rs Outdated
Comment thread compiler/rustc_lint_defs/src/builtin.rs
@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.

@clubby789 clubby789 added the I-lang-nominated Nominated for discussion during a lang team meeting. label Jun 21, 2026
@rustbot

rustbot commented Jun 21, 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.

@JonathanBrouwer JonathanBrouwer added the S-waiting-on-t-lang Status: Awaiting decision from T-lang label Jun 21, 2026

@JonathanBrouwer JonathanBrouwer left a comment

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.

r=me after T-lang approves

View changes since this review

@clubby789 clubby789 removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jun 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-attributes Area: Attributes (`#[…]`, `#![…]`) I-lang-nominated Nominated for discussion during a lang team meeting. O-windows Operating system: Windows S-waiting-on-t-lang Status: Awaiting decision from T-lang 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