-
-
Notifications
You must be signed in to change notification settings - Fork 15k
Lint against empty cfg(any()/all())
#158136
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -46,6 +46,7 @@ pub mod hardwired { | |||||
| DUPLICATE_MACRO_ATTRIBUTES, | ||||||
| ELIDED_LIFETIMES_IN_ASSOCIATED_CONSTANT, | ||||||
| ELIDED_LIFETIMES_IN_PATHS, | ||||||
| EMPTY_CFG_PREDICATE, | ||||||
| EXPLICIT_BUILTIN_CFGS_IN_FLAGS, | ||||||
| EXPORTED_PRIVATE_DEPENDENCIES, | ||||||
| FFI_UNWIND_CALLS, | ||||||
|
|
@@ -5578,3 +5579,31 @@ declare_lint! { | |||||
| "usage of `unsafe` code and other potentially unsound constructs", | ||||||
| @eval_always = true | ||||||
| } | ||||||
|
|
||||||
| declare_lint! { | ||||||
|
clubby789 marked this conversation as resolved.
|
||||||
| /// The `empty_cfg_predicate` lint detects the use of empty `cfg` predicate lists. | ||||||
| /// | ||||||
| /// ### Example | ||||||
| /// | ||||||
| /// ```rust,compile_fail | ||||||
| /// #![deny(empty_cfg_predicate)] | ||||||
| /// #[cfg(any())] | ||||||
| /// fn foo() {} | ||||||
| /// | ||||||
| /// #[cfg(all())] | ||||||
| /// fn bar() {} | ||||||
| /// ``` | ||||||
| /// | ||||||
| /// {{produces}} | ||||||
| /// | ||||||
| /// ### Explanation | ||||||
| /// | ||||||
| /// The meaning of `cfg(any())` and `cfg(all())` is not immediately obvious; | ||||||
| /// `cfg(false)` and `cfg(true)` respectively may be used instead. | ||||||
| /// This used to be a common pattern before `cfg(true)` and `cfg(false)` | ||||||
| /// were added to the language in Rust 1.88 | ||||||
| pub EMPTY_CFG_PREDICATE, | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Per our RFC 0344 guidance, this should be in the plural. Also, the naming seems a bit loose. This is targeting two specific
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's probably my preferred suggestion so far (or |
||||||
| Warn, | ||||||
| "detects use of empty `cfg(any())` and `cfg(all())`", | ||||||
| @msrv = "1.88.0"; | ||||||
| } | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -67,7 +67,7 @@ fn main() { | |
| } | ||
|
|
||
| if true { | ||
| #[cfg(any())] | ||
| #[cfg(false)] | ||
| foo; | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -68,7 +68,7 @@ fn main() { | |
| } | ||
|
|
||
| if true { | ||
| #[cfg(any())] | ||
| #[cfg(false)] | ||
| foo; | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| #![allow(unused)] | ||
| #![allow(empty_cfg_predicate)] | ||
|
|
||
| #[cfg(windows)] | ||
| //~^ non_minimal_cfg | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| #![allow(unused)] | ||
| #![allow(empty_cfg_predicate)] | ||
|
|
||
| #[cfg(all(windows))] | ||
| //~^ non_minimal_cfg | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.