about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorLoïc BRANSTETT <lolo.branstett@numericable.fr>2022-02-25 16:10:26 +0100
committerLoïc BRANSTETT <lolo.branstett@numericable.fr>2022-03-04 11:15:38 +0100
commit4aa92aff054c8e89c61ac06551a405af828ade70 (patch)
tree235f21bc54f473d06d767eae22b7ab74d41ec2ba /src/test
parent50e61a1a667929d0db91132246e61c1a67ab07af (diff)
downloadrust-4aa92aff054c8e89c61ac06551a405af828ade70.tar.gz
rust-4aa92aff054c8e89c61ac06551a405af828ade70.zip
Add well known values to --check-cfg implementation
Diffstat (limited to 'src/test')
-rw-r--r--src/test/ui/check-cfg/empty-values.rs6
-rw-r--r--src/test/ui/check-cfg/empty-values.stderr11
-rw-r--r--src/test/ui/check-cfg/well-known-values.rs28
-rw-r--r--src/test/ui/check-cfg/well-known-values.stderr31
4 files changed, 75 insertions, 1 deletions
diff --git a/src/test/ui/check-cfg/empty-values.rs b/src/test/ui/check-cfg/empty-values.rs
index 5464846409a..9bda42e5d15 100644
--- a/src/test/ui/check-cfg/empty-values.rs
+++ b/src/test/ui/check-cfg/empty-values.rs
@@ -1,6 +1,10 @@
-// Check that a an empty values() pass
+// Check warning for unexpected cfg value
 //
 // check-pass
 // compile-flags: --check-cfg=values() -Z unstable-options
 
+#[cfg(test = "value")]
+//~^ WARNING unexpected `cfg` condition value
+pub fn f() {}
+
 fn main() {}
diff --git a/src/test/ui/check-cfg/empty-values.stderr b/src/test/ui/check-cfg/empty-values.stderr
new file mode 100644
index 00000000000..834b28f1244
--- /dev/null
+++ b/src/test/ui/check-cfg/empty-values.stderr
@@ -0,0 +1,11 @@
+warning: unexpected `cfg` condition value
+  --> $DIR/empty-values.rs:6:7
+   |
+LL | #[cfg(test = "value")]
+   |       ^^^^^^^^^^^^^^
+   |
+   = note: `#[warn(unexpected_cfgs)]` on by default
+   = note: no expected value for `test`
+
+warning: 1 warning emitted
+
diff --git a/src/test/ui/check-cfg/well-known-values.rs b/src/test/ui/check-cfg/well-known-values.rs
new file mode 100644
index 00000000000..46004be43d8
--- /dev/null
+++ b/src/test/ui/check-cfg/well-known-values.rs
@@ -0,0 +1,28 @@
+// This test check that we lint on non well known values and that we don't lint on well known
+// values
+//
+// check-pass
+// compile-flags: --check-cfg=values() -Z unstable-options
+
+#[cfg(target_os = "linuz")]
+//~^ WARNING unexpected `cfg` condition value
+fn target_os_linux_misspell() {}
+
+#[cfg(target_os = "linux")]
+fn target_os_linux() {}
+
+#[cfg(target_has_atomic = "0")]
+//~^ WARNING unexpected `cfg` condition value
+fn target_has_atomic_invalid() {}
+
+#[cfg(target_has_atomic = "8")]
+fn target_has_atomic() {}
+
+#[cfg(unix = "aa")]
+//~^ WARNING unexpected `cfg` condition value
+fn unix_with_value() {}
+
+#[cfg(unix)]
+fn unix() {}
+
+fn main() {}
diff --git a/src/test/ui/check-cfg/well-known-values.stderr b/src/test/ui/check-cfg/well-known-values.stderr
new file mode 100644
index 00000000000..05b2a8af0ee
--- /dev/null
+++ b/src/test/ui/check-cfg/well-known-values.stderr
@@ -0,0 +1,31 @@
+warning: unexpected `cfg` condition value
+  --> $DIR/well-known-values.rs:7:7
+   |
+LL | #[cfg(target_os = "linuz")]
+   |       ^^^^^^^^^^^^-------
+   |                   |
+   |                   help: did you mean: `"linux"`
+   |
+   = note: `#[warn(unexpected_cfgs)]` on by default
+   = note: expected values for `target_os` are: android, cuda, dragonfly, emscripten, espidf, freebsd, fuchsia, haiku, hermit, horizon, illumos, ios, l4re, linux, macos, netbsd, none, openbsd, psp, redox, solaris, solid_asp3, tvos, uefi, unknown, vxworks, wasi, windows
+
+warning: unexpected `cfg` condition value
+  --> $DIR/well-known-values.rs:14:7
+   |
+LL | #[cfg(target_has_atomic = "0")]
+   |       ^^^^^^^^^^^^^^^^^^^^---
+   |                           |
+   |                           help: did you mean: `"8"`
+   |
+   = note: expected values for `target_has_atomic` are: 128, 16, 32, 64, 8, ptr
+
+warning: unexpected `cfg` condition value
+  --> $DIR/well-known-values.rs:21:7
+   |
+LL | #[cfg(unix = "aa")]
+   |       ^^^^^^^^^^^
+   |
+   = note: no expected value for `unix`
+
+warning: 3 warnings emitted
+