about summary refs log tree commit diff
diff options
context:
space:
mode:
authorclubby789 <jamie@hill-daniel.co.uk>2025-03-18 13:06:25 +0000
committerclubby789 <jamie@hill-daniel.co.uk>2025-04-03 18:10:48 +0000
commitd83f4153251ad3e85e975fa3e613378eba913c0b (patch)
treeb259640ed3bbed1b86e5fbcec61b3f1939e700f4
parent984c51f6a1d93fa244829f488d2945e7fc06b880 (diff)
downloadrust-d83f4153251ad3e85e975fa3e613378eba913c0b.tar.gz
rust-d83f4153251ad3e85e975fa3e613378eba913c0b.zip
Add more tests for `cfg_boolean_literals`
-rw-r--r--tests/ui/cfg/both-true-false.rs14
-rw-r--r--tests/ui/cfg/both-true-false.stderr9
-rw-r--r--tests/ui/cfg/cmdline-false.rs9
-rw-r--r--tests/ui/cfg/cmdline-false.stderr9
4 files changed, 41 insertions, 0 deletions
diff --git a/tests/ui/cfg/both-true-false.rs b/tests/ui/cfg/both-true-false.rs
new file mode 100644
index 00000000000..5fca8f654ad
--- /dev/null
+++ b/tests/ui/cfg/both-true-false.rs
@@ -0,0 +1,14 @@
+/// Test that placing a `cfg(true)` and `cfg(false)` on the same item result in
+//. it being disabled.`
+
+#[cfg(false)]
+#[cfg(true)]
+fn foo() {}
+
+#[cfg(true)]
+#[cfg(false)]
+fn foo() {}
+
+fn main() {
+    foo();  //~ ERROR cannot find function `foo` in this scope
+}
diff --git a/tests/ui/cfg/both-true-false.stderr b/tests/ui/cfg/both-true-false.stderr
new file mode 100644
index 00000000000..1526cc2b707
--- /dev/null
+++ b/tests/ui/cfg/both-true-false.stderr
@@ -0,0 +1,9 @@
+error[E0425]: cannot find function `foo` in this scope
+  --> $DIR/both-true-false.rs:13:5
+   |
+LL |     foo();
+   |     ^^^ not found in this scope
+
+error: aborting due to 1 previous error
+
+For more information about this error, try `rustc --explain E0425`.
diff --git a/tests/ui/cfg/cmdline-false.rs b/tests/ui/cfg/cmdline-false.rs
new file mode 100644
index 00000000000..d4b7d3bbfdc
--- /dev/null
+++ b/tests/ui/cfg/cmdline-false.rs
@@ -0,0 +1,9 @@
+/// Test that `--cfg false` doesn't cause `cfg(false)` to evaluate to `true`
+//@ compile-flags: --cfg false
+
+#[cfg(false)]
+fn foo() {}
+
+fn main() {
+    foo();  //~ ERROR cannot find function `foo` in this scope
+}
diff --git a/tests/ui/cfg/cmdline-false.stderr b/tests/ui/cfg/cmdline-false.stderr
new file mode 100644
index 00000000000..5f57c754c40
--- /dev/null
+++ b/tests/ui/cfg/cmdline-false.stderr
@@ -0,0 +1,9 @@
+error[E0425]: cannot find function `foo` in this scope
+  --> $DIR/cmdline-false.rs:8:5
+   |
+LL |     foo();
+   |     ^^^ not found in this scope
+
+error: aborting due to 1 previous error
+
+For more information about this error, try `rustc --explain E0425`.