about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-03-05 11:29:59 +0000
committerbors <bors@rust-lang.org>2022-03-05 11:29:59 +0000
commitc8a49fc90281d9a3227a547b5bac8e01d17325be (patch)
treeb89ad1cb40935aefc84e61a58468b267d445f6e8 /src
parent86067bb461d044ee30e7880ab6f3b34d5070f1db (diff)
parent92544f43b052b4c6b1d224c7ff73f68c0a19bd5c (diff)
downloadrust-c8a49fc90281d9a3227a547b5bac8e01d17325be.tar.gz
rust-c8a49fc90281d9a3227a547b5bac8e01d17325be.zip
Auto merge of #94561 - Urgau:check-cfg-lint-help-remove, r=petrochenkov
Improve unexpected_cfgs lint when their is no value expected

This pull-request improve the `unexpected_cfgs` when their is no value expected by suggesting to remove the value.

I also took the liberty to special case it for `feature` as it seems wrong to suggest to remove the value when the problem is most probably the absence of value(s) and also the fact that it doesn't make sense to only have `feature` without a value.

r? `@petrochenkov`
Diffstat (limited to 'src')
-rw-r--r--src/test/ui/check-cfg/empty-values.stderr4
-rw-r--r--src/test/ui/check-cfg/no-values.rs6
-rw-r--r--src/test/ui/check-cfg/no-values.stderr12
-rw-r--r--src/test/ui/check-cfg/well-known-values.stderr4
4 files changed, 22 insertions, 4 deletions
diff --git a/src/test/ui/check-cfg/empty-values.stderr b/src/test/ui/check-cfg/empty-values.stderr
index 834b28f1244..10dab503489 100644
--- a/src/test/ui/check-cfg/empty-values.stderr
+++ b/src/test/ui/check-cfg/empty-values.stderr
@@ -2,7 +2,9 @@ warning: unexpected `cfg` condition value
   --> $DIR/empty-values.rs:6:7
    |
 LL | #[cfg(test = "value")]
-   |       ^^^^^^^^^^^^^^
+   |       ^^^^----------
+   |           |
+   |           help: remove the value
    |
    = note: `#[warn(unexpected_cfgs)]` on by default
    = note: no expected value for `test`
diff --git a/src/test/ui/check-cfg/no-values.rs b/src/test/ui/check-cfg/no-values.rs
index 2440757e52d..8c80f56cb5a 100644
--- a/src/test/ui/check-cfg/no-values.rs
+++ b/src/test/ui/check-cfg/no-values.rs
@@ -1,10 +1,14 @@
 // Check that we detect unexpected value when none are allowed
 //
 // check-pass
-// compile-flags: --check-cfg=values(feature) -Z unstable-options
+// compile-flags: --check-cfg=values(test) --check-cfg=values(feature) -Z unstable-options
 
 #[cfg(feature = "foo")]
 //~^ WARNING unexpected `cfg` condition value
 fn do_foo() {}
 
+#[cfg(test = "foo")]
+//~^ WARNING unexpected `cfg` condition value
+fn do_foo() {}
+
 fn main() {}
diff --git a/src/test/ui/check-cfg/no-values.stderr b/src/test/ui/check-cfg/no-values.stderr
index ea1c9107d4c..7025b4cd7ba 100644
--- a/src/test/ui/check-cfg/no-values.stderr
+++ b/src/test/ui/check-cfg/no-values.stderr
@@ -7,5 +7,15 @@ LL | #[cfg(feature = "foo")]
    = note: `#[warn(unexpected_cfgs)]` on by default
    = note: no expected value for `feature`
 
-warning: 1 warning emitted
+warning: unexpected `cfg` condition value
+  --> $DIR/no-values.rs:10:7
+   |
+LL | #[cfg(test = "foo")]
+   |       ^^^^--------
+   |           |
+   |           help: remove the value
+   |
+   = note: no expected value for `test`
+
+warning: 2 warnings emitted
 
diff --git a/src/test/ui/check-cfg/well-known-values.stderr b/src/test/ui/check-cfg/well-known-values.stderr
index 05b2a8af0ee..8eefd6aaf35 100644
--- a/src/test/ui/check-cfg/well-known-values.stderr
+++ b/src/test/ui/check-cfg/well-known-values.stderr
@@ -23,7 +23,9 @@ warning: unexpected `cfg` condition value
   --> $DIR/well-known-values.rs:21:7
    |
 LL | #[cfg(unix = "aa")]
-   |       ^^^^^^^^^^^
+   |       ^^^^-------
+   |           |
+   |           help: remove the value
    |
    = note: no expected value for `unix`