diff options
| author | bors <bors@rust-lang.org> | 2023-06-02 09:36:05 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-06-02 09:36:05 +0000 |
| commit | 7c448a6910bf9ceda0df8d0871a34dc398dbde9d (patch) | |
| tree | 919e452aace798551d570b671b5bc1b29bbbdd93 /tests/ui | |
| parent | 30448e8cf98d4754350db0c959644564f317bc0f (diff) | |
| parent | ad76687b2f2cf041190ca44f7a53d89f84ac552b (diff) | |
| download | rust-7c448a6910bf9ceda0df8d0871a34dc398dbde9d.tar.gz rust-7c448a6910bf9ceda0df8d0871a34dc398dbde9d.zip | |
Auto merge of #10860 - ihciah:master, r=Manishearth
add checking for cfg(features = ...) *Please write a short comment explaining your change (or "none" for internal only changes)* changelog: [`maybe_misused_cfg`]: check if `#[cfg(feature = "...")]` misused as `#[cfg(features = "...")]` I've found that there is no indication when `#[cfg(features = "...")]` is used incorrectly, which can easily make mistakes hard to spot. When I searched for this code on github, I also found many misuse cases([link](https://github.com/search?q=%23%5Bcfg%28features+language%3ARust&type=code)). PS: This clippy name is just a temporary name, it can be replaced with a better name.
Diffstat (limited to 'tests/ui')
| -rw-r--r-- | tests/ui/cfg_features.rs | 12 | ||||
| -rw-r--r-- | tests/ui/cfg_features.stderr | 28 |
2 files changed, 40 insertions, 0 deletions
diff --git a/tests/ui/cfg_features.rs b/tests/ui/cfg_features.rs new file mode 100644 index 00000000000..bc4109c2c89 --- /dev/null +++ b/tests/ui/cfg_features.rs @@ -0,0 +1,12 @@ +#![warn(clippy::maybe_misused_cfg)] + +fn main() { + #[cfg(features = "not-really-a-feature")] + let _ = 1 + 2; + + #[cfg(all(feature = "right", features = "wrong"))] + let _ = 1 + 2; + + #[cfg(all(features = "wrong1", any(feature = "right", features = "wrong2", feature, features)))] + let _ = 1 + 2; +} diff --git a/tests/ui/cfg_features.stderr b/tests/ui/cfg_features.stderr new file mode 100644 index 00000000000..00405985d48 --- /dev/null +++ b/tests/ui/cfg_features.stderr @@ -0,0 +1,28 @@ +error: feature may misspelled as features + --> $DIR/cfg_features.rs:4:11 + | +LL | #[cfg(features = "not-really-a-feature")] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `feature = "not-really-a-feature"` + | + = note: `-D clippy::maybe-misused-cfg` implied by `-D warnings` + +error: feature may misspelled as features + --> $DIR/cfg_features.rs:7:34 + | +LL | #[cfg(all(feature = "right", features = "wrong"))] + | ^^^^^^^^^^^^^^^^^^ help: use: `feature = "wrong"` + +error: feature may misspelled as features + --> $DIR/cfg_features.rs:10:15 + | +LL | #[cfg(all(features = "wrong1", any(feature = "right", features = "wrong2", feature, features)))] + | ^^^^^^^^^^^^^^^^^^^ help: use: `feature = "wrong1"` + +error: feature may misspelled as features + --> $DIR/cfg_features.rs:10:59 + | +LL | #[cfg(all(features = "wrong1", any(feature = "right", features = "wrong2", feature, features)))] + | ^^^^^^^^^^^^^^^^^^^ help: use: `feature = "wrong2"` + +error: aborting due to 4 previous errors + |
