about summary refs log tree commit diff
diff options
context:
space:
mode:
authory21 <30553356+y21@users.noreply.github.com>2024-06-01 13:44:13 +0200
committery21 <30553356+y21@users.noreply.github.com>2024-06-01 13:44:13 +0200
commit4aa20d2e951d764c0345c5635daa0c9f0841dcd3 (patch)
tree588bf2592831b0a7bf3df96111eed576fc4c2253
parent28e887fe719ed8fdcf2047c2e587efcd25e4d62e (diff)
downloadrust-4aa20d2e951d764c0345c5635daa0c9f0841dcd3.tar.gz
rust-4aa20d2e951d764c0345c5635daa0c9f0841dcd3.zip
deprecate `maybe_misused_cfg`
-rw-r--r--clippy_lints/src/attrs/maybe_misused_cfg.rs51
-rw-r--r--clippy_lints/src/attrs/mod.rs35
-rw-r--r--clippy_lints/src/declared_lints.rs1
-rw-r--r--clippy_lints/src/deprecated_lints.rs13
-rw-r--r--clippy_lints/src/lib.deprecated.rs4
-rw-r--r--tests/ui/cfg_features.fixed29
-rw-r--r--tests/ui/cfg_features.rs29
-rw-r--r--tests/ui/cfg_features.stderr53
-rw-r--r--tests/ui/deprecated.rs1
-rw-r--r--tests/ui/deprecated.stderr8
-rw-r--r--tests/ui/unnecessary_clippy_cfg.rs8
-rw-r--r--tests/ui/unnecessary_clippy_cfg.stderr28
12 files changed, 43 insertions, 217 deletions
diff --git a/clippy_lints/src/attrs/maybe_misused_cfg.rs b/clippy_lints/src/attrs/maybe_misused_cfg.rs
deleted file mode 100644
index e6b2e835be8..00000000000
--- a/clippy_lints/src/attrs/maybe_misused_cfg.rs
+++ /dev/null
@@ -1,51 +0,0 @@
-use super::{Attribute, MAYBE_MISUSED_CFG};
-use clippy_utils::diagnostics::span_lint_and_sugg;
-use rustc_ast::{MetaItemKind, NestedMetaItem};
-use rustc_errors::Applicability;
-use rustc_lint::EarlyContext;
-use rustc_span::sym;
-
-pub(super) fn check(cx: &EarlyContext<'_>, attr: &Attribute) {
-    if attr.has_name(sym::cfg)
-        && let Some(items) = attr.meta_item_list()
-    {
-        check_nested_misused_cfg(cx, &items);
-    }
-}
-
-fn check_nested_misused_cfg(cx: &EarlyContext<'_>, items: &[NestedMetaItem]) {
-    for item in items {
-        if let NestedMetaItem::MetaItem(meta) = item {
-            if let Some(ident) = meta.ident()
-                && ident.name.as_str() == "features"
-                && let Some(val) = meta.value_str()
-            {
-                span_lint_and_sugg(
-                    cx,
-                    MAYBE_MISUSED_CFG,
-                    meta.span,
-                    "'feature' may be misspelled as 'features'",
-                    "did you mean",
-                    format!("feature = \"{val}\""),
-                    Applicability::MaybeIncorrect,
-                );
-            }
-            if let MetaItemKind::List(list) = &meta.kind {
-                check_nested_misused_cfg(cx, list);
-            // If this is not a list, then we check for `cfg(test)`.
-            } else if let Some(ident) = meta.ident()
-                && matches!(ident.name.as_str(), "tests" | "Test")
-            {
-                span_lint_and_sugg(
-                    cx,
-                    MAYBE_MISUSED_CFG,
-                    meta.span,
-                    format!("'test' may be misspelled as '{}'", ident.name.as_str()),
-                    "did you mean",
-                    "test".to_string(),
-                    Applicability::MaybeIncorrect,
-                );
-            }
-        }
-    }
-}
diff --git a/clippy_lints/src/attrs/mod.rs b/clippy_lints/src/attrs/mod.rs
index a24bd5ed44b..764ad497dfe 100644
--- a/clippy_lints/src/attrs/mod.rs
+++ b/clippy_lints/src/attrs/mod.rs
@@ -7,7 +7,6 @@ mod deprecated_semver;
 mod duplicated_attributes;
 mod empty_line_after;
 mod inline_always;
-mod maybe_misused_cfg;
 mod mismatched_target_os;
 mod mixed_attributes_style;
 mod non_minimal_cfg;
@@ -393,38 +392,6 @@ declare_clippy_lint! {
 
 declare_clippy_lint! {
     /// ### What it does
-    /// Checks for `#[cfg(features = "...")]` and suggests to replace it with
-    /// `#[cfg(feature = "...")]`.
-    ///
-    /// It also checks if `cfg(test)` was misspelled.
-    ///
-    /// ### Why is this bad?
-    /// Misspelling `feature` as `features` or `test` as `tests` can be sometimes hard to spot. It
-    /// may cause conditional compilation not work quietly.
-    ///
-    /// ### Example
-    /// ```no_run
-    /// #[cfg(features = "some-feature")]
-    /// fn conditional() { }
-    /// #[cfg(tests)]
-    /// mod tests { }
-    /// ```
-    ///
-    /// Use instead:
-    /// ```no_run
-    /// #[cfg(feature = "some-feature")]
-    /// fn conditional() { }
-    /// #[cfg(test)]
-    /// mod tests { }
-    /// ```
-    #[clippy::version = "1.69.0"]
-    pub MAYBE_MISUSED_CFG,
-    suspicious,
-    "prevent from misusing the wrong attr name"
-}
-
-declare_clippy_lint! {
-    /// ### What it does
     /// Checks for `#[cfg_attr(feature = "cargo-clippy", ...)]` and for
     /// `#[cfg(feature = "cargo-clippy")]` and suggests to replace it with
     /// `#[cfg_attr(clippy, ...)]` or `#[cfg(clippy)]`.
@@ -616,7 +583,6 @@ impl_lint_pass!(EarlyAttributes => [
     EMPTY_LINE_AFTER_OUTER_ATTR,
     EMPTY_LINE_AFTER_DOC_COMMENTS,
     NON_MINIMAL_CFG,
-    MAYBE_MISUSED_CFG,
     DEPRECATED_CLIPPY_CFG_ATTR,
     UNNECESSARY_CLIPPY_CFG,
 ]);
@@ -631,7 +597,6 @@ impl EarlyLintPass for EarlyAttributes {
         deprecated_cfg_attr::check_clippy(cx, attr);
         mismatched_target_os::check(cx, attr);
         non_minimal_cfg::check(cx, attr);
-        maybe_misused_cfg::check(cx, attr);
     }
 
     extract_msrv_attr!(EarlyContext);
diff --git a/clippy_lints/src/declared_lints.rs b/clippy_lints/src/declared_lints.rs
index df2ef465700..a8d5004c3e2 100644
--- a/clippy_lints/src/declared_lints.rs
+++ b/clippy_lints/src/declared_lints.rs
@@ -58,7 +58,6 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[
     crate::attrs::EMPTY_LINE_AFTER_DOC_COMMENTS_INFO,
     crate::attrs::EMPTY_LINE_AFTER_OUTER_ATTR_INFO,
     crate::attrs::INLINE_ALWAYS_INFO,
-    crate::attrs::MAYBE_MISUSED_CFG_INFO,
     crate::attrs::MISMATCHED_TARGET_OS_INFO,
     crate::attrs::MIXED_ATTRIBUTES_STYLE_INFO,
     crate::attrs::NON_MINIMAL_CFG_INFO,
diff --git a/clippy_lints/src/deprecated_lints.rs b/clippy_lints/src/deprecated_lints.rs
index 9aa5af3190f..4c5d3f9d9ee 100644
--- a/clippy_lints/src/deprecated_lints.rs
+++ b/clippy_lints/src/deprecated_lints.rs
@@ -215,3 +215,16 @@ declare_deprecated_lint! {
     pub WRONG_PUB_SELF_CONVENTION,
     "set the `avoid-breaking-exported-api` config option to `false` to enable the `wrong_self_convention` lint for public items"
 }
+
+declare_deprecated_lint! {
+    /// ### What it does
+    /// Nothing. This lint has been deprecated.
+    ///
+    /// ### Deprecation reason
+    /// This lint has been superseded by rustc's own [`unexpected_cfgs`] lint that is able to detect the `#[cfg(features)]` and `#[cfg(tests)]` typos.
+    ///
+    /// [`unexpected_cfgs`]: https://doc.rust-lang.org/rustc/lints/listing/warn-by-default.html#unexpected-cfgs
+    #[clippy::version = "1.80.0"]
+    pub MAYBE_MISUSED_CFG,
+    "this lint has been replaced by `unexpected_cfgs`"
+}
diff --git a/clippy_lints/src/lib.deprecated.rs b/clippy_lints/src/lib.deprecated.rs
index 80bde1b1138..01a23a032aa 100644
--- a/clippy_lints/src/lib.deprecated.rs
+++ b/clippy_lints/src/lib.deprecated.rs
@@ -67,4 +67,8 @@
         "clippy::wrong_pub_self_convention",
         "set the `avoid-breaking-exported-api` config option to `false` to enable the `wrong_self_convention` lint for public items",
     );
+    store.register_removed(
+        "clippy::maybe_misused_cfg",
+        "this lint has been replaced by `unexpected_cfgs`",
+    );
 }
diff --git a/tests/ui/cfg_features.fixed b/tests/ui/cfg_features.fixed
deleted file mode 100644
index 0fe38f169f9..00000000000
--- a/tests/ui/cfg_features.fixed
+++ /dev/null
@@ -1,29 +0,0 @@
-#![warn(clippy::maybe_misused_cfg)]
-
-fn main() {
-    #[cfg(feature = "not-really-a-feature")]
-    //~^ ERROR: 'feature' may be misspelled as 'features'
-    //~| NOTE: `-D clippy::maybe-misused-cfg` implied by `-D warnings`
-    let _ = 1 + 2;
-
-    #[cfg(all(feature = "right", feature = "wrong"))]
-    //~^ ERROR: 'feature' may be misspelled as 'features'
-    let _ = 1 + 2;
-
-    #[cfg(all(feature = "wrong1", any(feature = "right", feature = "wrong2", feature, features)))]
-    //~^ ERROR: 'feature' may be misspelled as 'features'
-    //~| ERROR: 'feature' may be misspelled as 'features'
-    let _ = 1 + 2;
-
-    #[cfg(test)]
-    //~^ ERROR: 'test' may be misspelled as 'tests'
-    let _ = 2;
-    #[cfg(test)]
-    //~^ ERROR: 'test' may be misspelled as 'Test'
-    let _ = 2;
-
-    #[cfg(all(test, test))]
-    //~^ ERROR: 'test' may be misspelled as 'tests'
-    //~| ERROR: 'test' may be misspelled as 'Test'
-    let _ = 2;
-}
diff --git a/tests/ui/cfg_features.rs b/tests/ui/cfg_features.rs
deleted file mode 100644
index 9c0db035eac..00000000000
--- a/tests/ui/cfg_features.rs
+++ /dev/null
@@ -1,29 +0,0 @@
-#![warn(clippy::maybe_misused_cfg)]
-
-fn main() {
-    #[cfg(features = "not-really-a-feature")]
-    //~^ ERROR: 'feature' may be misspelled as 'features'
-    //~| NOTE: `-D clippy::maybe-misused-cfg` implied by `-D warnings`
-    let _ = 1 + 2;
-
-    #[cfg(all(feature = "right", features = "wrong"))]
-    //~^ ERROR: 'feature' may be misspelled as 'features'
-    let _ = 1 + 2;
-
-    #[cfg(all(features = "wrong1", any(feature = "right", features = "wrong2", feature, features)))]
-    //~^ ERROR: 'feature' may be misspelled as 'features'
-    //~| ERROR: 'feature' may be misspelled as 'features'
-    let _ = 1 + 2;
-
-    #[cfg(tests)]
-    //~^ ERROR: 'test' may be misspelled as 'tests'
-    let _ = 2;
-    #[cfg(Test)]
-    //~^ ERROR: 'test' may be misspelled as 'Test'
-    let _ = 2;
-
-    #[cfg(all(tests, Test))]
-    //~^ ERROR: 'test' may be misspelled as 'tests'
-    //~| ERROR: 'test' may be misspelled as 'Test'
-    let _ = 2;
-}
diff --git a/tests/ui/cfg_features.stderr b/tests/ui/cfg_features.stderr
deleted file mode 100644
index d576271f1a2..00000000000
--- a/tests/ui/cfg_features.stderr
+++ /dev/null
@@ -1,53 +0,0 @@
-error: 'feature' may be misspelled as 'features'
-  --> tests/ui/cfg_features.rs:4:11
-   |
-LL |     #[cfg(features = "not-really-a-feature")]
-   |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: did you mean: `feature = "not-really-a-feature"`
-   |
-   = note: `-D clippy::maybe-misused-cfg` implied by `-D warnings`
-   = help: to override `-D warnings` add `#[allow(clippy::maybe_misused_cfg)]`
-
-error: 'feature' may be misspelled as 'features'
-  --> tests/ui/cfg_features.rs:9:34
-   |
-LL |     #[cfg(all(feature = "right", features = "wrong"))]
-   |                                  ^^^^^^^^^^^^^^^^^^ help: did you mean: `feature = "wrong"`
-
-error: 'feature' may be misspelled as 'features'
-  --> tests/ui/cfg_features.rs:13:15
-   |
-LL |     #[cfg(all(features = "wrong1", any(feature = "right", features = "wrong2", feature, features)))]
-   |               ^^^^^^^^^^^^^^^^^^^ help: did you mean: `feature = "wrong1"`
-
-error: 'feature' may be misspelled as 'features'
-  --> tests/ui/cfg_features.rs:13:59
-   |
-LL |     #[cfg(all(features = "wrong1", any(feature = "right", features = "wrong2", feature, features)))]
-   |                                                           ^^^^^^^^^^^^^^^^^^^ help: did you mean: `feature = "wrong2"`
-
-error: 'test' may be misspelled as 'tests'
-  --> tests/ui/cfg_features.rs:18:11
-   |
-LL |     #[cfg(tests)]
-   |           ^^^^^ help: did you mean: `test`
-
-error: 'test' may be misspelled as 'Test'
-  --> tests/ui/cfg_features.rs:21:11
-   |
-LL |     #[cfg(Test)]
-   |           ^^^^ help: did you mean: `test`
-
-error: 'test' may be misspelled as 'tests'
-  --> tests/ui/cfg_features.rs:25:15
-   |
-LL |     #[cfg(all(tests, Test))]
-   |               ^^^^^ help: did you mean: `test`
-
-error: 'test' may be misspelled as 'Test'
-  --> tests/ui/cfg_features.rs:25:22
-   |
-LL |     #[cfg(all(tests, Test))]
-   |                      ^^^^ help: did you mean: `test`
-
-error: aborting due to 8 previous errors
-
diff --git a/tests/ui/deprecated.rs b/tests/ui/deprecated.rs
index 07270bd7636..178bd2f3b66 100644
--- a/tests/ui/deprecated.rs
+++ b/tests/ui/deprecated.rs
@@ -18,5 +18,6 @@
 #![warn(clippy::filter_map)]
 #![warn(clippy::pub_enum_variant_names)]
 #![warn(clippy::wrong_pub_self_convention)]
+#![warn(clippy::maybe_misused_cfg)]
 
 fn main() {}
diff --git a/tests/ui/deprecated.stderr b/tests/ui/deprecated.stderr
index a9cf04bea52..39a2278d8a6 100644
--- a/tests/ui/deprecated.stderr
+++ b/tests/ui/deprecated.stderr
@@ -97,5 +97,11 @@ error: lint `clippy::wrong_pub_self_convention` has been removed: set the `avoid
 LL | #![warn(clippy::wrong_pub_self_convention)]
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
-error: aborting due to 16 previous errors
+error: lint `clippy::maybe_misused_cfg` has been removed: this lint has been replaced by `unexpected_cfgs`
+  --> tests/ui/deprecated.rs:21:9
+   |
+LL | #![warn(clippy::maybe_misused_cfg)]
+   |         ^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to 17 previous errors
 
diff --git a/tests/ui/unnecessary_clippy_cfg.rs b/tests/ui/unnecessary_clippy_cfg.rs
index ff960520f5e..9915f8b843e 100644
--- a/tests/ui/unnecessary_clippy_cfg.rs
+++ b/tests/ui/unnecessary_clippy_cfg.rs
@@ -5,18 +5,18 @@
 //~^ ERROR: no need to put clippy lints behind a `clippy` cfg
 #![cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))]
 //~^ ERROR: no need to put clippy lints behind a `clippy` cfg
-#![cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg, clippy::maybe_misused_cfg))]
+#![cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))]
 //~^ ERROR: no need to put clippy lints behind a `clippy` cfg
-#![cfg_attr(clippy, deny(clippy::non_minimal_cfg, clippy::maybe_misused_cfg))]
+#![cfg_attr(clippy, deny(clippy::non_minimal_cfg))]
 //~^ ERROR: no need to put clippy lints behind a `clippy` cfg
 
 #[cfg_attr(clippy, deny(clippy::non_minimal_cfg))]
 //~^ ERROR: no need to put clippy lints behind a `clippy` cfg
 #[cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))]
 //~^ ERROR: no need to put clippy lints behind a `clippy` cfg
-#[cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg, clippy::maybe_misused_cfg))]
+#[cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))]
 //~^ ERROR: no need to put clippy lints behind a `clippy` cfg
-#[cfg_attr(clippy, deny(clippy::non_minimal_cfg, clippy::maybe_misused_cfg))]
+#[cfg_attr(clippy, deny(clippy::non_minimal_cfg))]
 //~^ ERROR: no need to put clippy lints behind a `clippy` cfg
 pub struct Bar;
 
diff --git a/tests/ui/unnecessary_clippy_cfg.stderr b/tests/ui/unnecessary_clippy_cfg.stderr
index 3d58c9eb5da..16a86165295 100644
--- a/tests/ui/unnecessary_clippy_cfg.stderr
+++ b/tests/ui/unnecessary_clippy_cfg.stderr
@@ -18,16 +18,16 @@ LL | #[cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))]
 error: no need to put clippy lints behind a `clippy` cfg
   --> tests/ui/unnecessary_clippy_cfg.rs:17:36
    |
-LL | #[cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg, clippy::maybe_misused_cfg))]
-   |                                    ^^^^^^^^^^^^^^^^^^^^^^^  ^^^^^^^^^^^^^^^^^^^^^^^^^
+LL | #[cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))]
+   |                                    ^^^^^^^^^^^^^^^^^^^^^^^
    |
-   = note: write instead: `#[deny(clippy::non_minimal_cfg,clippy::maybe_misused_cfg)]`
+   = note: write instead: `#[deny(clippy::non_minimal_cfg)]`
 
 error: no need to put clippy lints behind a `clippy` cfg
   --> tests/ui/unnecessary_clippy_cfg.rs:19:1
    |
-LL | #[cfg_attr(clippy, deny(clippy::non_minimal_cfg, clippy::maybe_misused_cfg))]
-   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `#[deny(clippy::non_minimal_cfg, clippy::maybe_misused_cfg)]`
+LL | #[cfg_attr(clippy, deny(clippy::non_minimal_cfg))]
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `#[deny(clippy::non_minimal_cfg)]`
 
 error: no need to put clippy lints behind a `clippy` cfg
   --> tests/ui/unnecessary_clippy_cfg.rs:4:1
@@ -46,21 +46,21 @@ LL | #![cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))]
 error: no need to put clippy lints behind a `clippy` cfg
   --> tests/ui/unnecessary_clippy_cfg.rs:8:37
    |
-LL | #![cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg, clippy::maybe_misused_cfg))]
-   |                                     ^^^^^^^^^^^^^^^^^^^^^^^  ^^^^^^^^^^^^^^^^^^^^^^^^^
+LL | #![cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))]
+   |                                     ^^^^^^^^^^^^^^^^^^^^^^^
    |
-   = note: write instead: `#![deny(clippy::non_minimal_cfg,clippy::maybe_misused_cfg)]`
+   = note: write instead: `#![deny(clippy::non_minimal_cfg)]`
 
 error: no need to put clippy lints behind a `clippy` cfg
   --> tests/ui/unnecessary_clippy_cfg.rs:10:1
    |
-LL | #![cfg_attr(clippy, deny(clippy::non_minimal_cfg, clippy::maybe_misused_cfg))]
-   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `#![deny(clippy::non_minimal_cfg, clippy::maybe_misused_cfg)]`
+LL | #![cfg_attr(clippy, deny(clippy::non_minimal_cfg))]
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `#![deny(clippy::non_minimal_cfg)]`
 
 error: duplicated attribute
   --> tests/ui/unnecessary_clippy_cfg.rs:8:26
    |
-LL | #![cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg, clippy::maybe_misused_cfg))]
+LL | #![cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))]
    |                          ^^^^^^^^^
    |
 note: first defined here
@@ -71,7 +71,7 @@ LL | #![cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))]
 help: remove this attribute
   --> tests/ui/unnecessary_clippy_cfg.rs:8:26
    |
-LL | #![cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg, clippy::maybe_misused_cfg))]
+LL | #![cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))]
    |                          ^^^^^^^^^
    = note: `-D clippy::duplicated-attributes` implied by `-D warnings`
    = help: to override `-D warnings` add `#[allow(clippy::duplicated_attributes)]`
@@ -79,7 +79,7 @@ LL | #![cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg, clippy::maybe_
 error: duplicated attribute
   --> tests/ui/unnecessary_clippy_cfg.rs:17:25
    |
-LL | #[cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg, clippy::maybe_misused_cfg))]
+LL | #[cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))]
    |                         ^^^^^^^^^
    |
 note: first defined here
@@ -90,7 +90,7 @@ LL | #[cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))]
 help: remove this attribute
   --> tests/ui/unnecessary_clippy_cfg.rs:17:25
    |
-LL | #[cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg, clippy::maybe_misused_cfg))]
+LL | #[cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))]
    |                         ^^^^^^^^^
 
 error: aborting due to 10 previous errors