about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLoïc BRANSTETT <lolo.branstett@numericable.fr>2022-04-25 12:07:21 +0200
committerUrgau <urgau@numericable.fr>2022-05-24 13:51:36 +0200
commitb9ae3db4ac47c80ecfb647920ceda77c22dd648c (patch)
tree14a3e5de93c17c95d9dbf0f6391bb9ae88707f9a
parent8345571cd07a00c780f5c156dd2d20a84b432807 (diff)
downloadrust-b9ae3db4ac47c80ecfb647920ceda77c22dd648c.tar.gz
rust-b9ae3db4ac47c80ecfb647920ceda77c22dd648c.zip
RFC3239: Add tests for compact `cfg(target(..))`
-rw-r--r--src/test/ui/cfg/cfg-target-compact-errors.rs17
-rw-r--r--src/test/ui/cfg/cfg-target-compact-errors.stderr22
-rw-r--r--src/test/ui/cfg/cfg-target-compact.rs10
-rw-r--r--src/test/ui/check-cfg/compact-names.rs15
-rw-r--r--src/test/ui/check-cfg/compact-names.stderr10
-rw-r--r--src/test/ui/check-cfg/compact-values.rs15
-rw-r--r--src/test/ui/check-cfg/compact-values.stderr11
-rw-r--r--src/test/ui/feature-gates/feature-gate-cfg-target-compact.rs13
-rw-r--r--src/test/ui/feature-gates/feature-gate-cfg-target-compact.stderr39
9 files changed, 152 insertions, 0 deletions
diff --git a/src/test/ui/cfg/cfg-target-compact-errors.rs b/src/test/ui/cfg/cfg-target-compact-errors.rs
new file mode 100644
index 00000000000..bca2275b1a9
--- /dev/null
+++ b/src/test/ui/cfg/cfg-target-compact-errors.rs
@@ -0,0 +1,17 @@
+// check-fail
+
+#![feature(cfg_target_compact)]
+
+#[cfg(target(o::o))]
+//~^ ERROR `cfg` predicate key must be an identifier
+fn one() {}
+
+#[cfg(target(os = 8))]
+//~^ ERROR literal in `cfg` predicate value must be a string
+fn two() {}
+
+#[cfg(target(os = "linux", pointer(width = "64")))]
+//~^ ERROR invalid predicate `target_pointer`
+fn three() {}
+
+fn main() {}
diff --git a/src/test/ui/cfg/cfg-target-compact-errors.stderr b/src/test/ui/cfg/cfg-target-compact-errors.stderr
new file mode 100644
index 00000000000..bb858301eb5
--- /dev/null
+++ b/src/test/ui/cfg/cfg-target-compact-errors.stderr
@@ -0,0 +1,22 @@
+error: `cfg` predicate key must be an identifier
+  --> $DIR/cfg-target-compact-errors.rs:5:14
+   |
+LL | #[cfg(target(o::o))]
+   |              ^^^^
+
+error[E0565]: literal in `cfg` predicate value must be a string
+  --> $DIR/cfg-target-compact-errors.rs:9:19
+   |
+LL | #[cfg(target(os = 8))]
+   |                   ^
+
+error[E0537]: invalid predicate `target_pointer`
+  --> $DIR/cfg-target-compact-errors.rs:13:28
+   |
+LL | #[cfg(target(os = "linux", pointer(width = "64")))]
+   |                            ^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to 3 previous errors
+
+Some errors have detailed explanations: E0537, E0565.
+For more information about an error, try `rustc --explain E0537`.
diff --git a/src/test/ui/cfg/cfg-target-compact.rs b/src/test/ui/cfg/cfg-target-compact.rs
new file mode 100644
index 00000000000..dc95a80915c
--- /dev/null
+++ b/src/test/ui/cfg/cfg-target-compact.rs
@@ -0,0 +1,10 @@
+// run-pass
+#![feature(cfg_target_compact)]
+
+#[cfg(target(os = "linux", pointer_width = "64"))]
+pub fn main() {
+}
+
+#[cfg(not(target(os = "linux", pointer_width = "64")))]
+pub fn main() {
+}
diff --git a/src/test/ui/check-cfg/compact-names.rs b/src/test/ui/check-cfg/compact-names.rs
new file mode 100644
index 00000000000..bff80740039
--- /dev/null
+++ b/src/test/ui/check-cfg/compact-names.rs
@@ -0,0 +1,15 @@
+// This test check that we correctly emit an warning for compact cfg
+//
+// check-pass
+// compile-flags:--check-cfg=names() -Z unstable-options
+
+#![feature(cfg_target_compact)]
+
+#[cfg(target(os = "linux", arch = "arm"))]
+pub fn expected() {}
+
+#[cfg(target(os = "linux", architecture = "arm"))]
+//~^ WARNING unexpected `cfg` condition name
+pub fn unexpected() {}
+
+fn main() {}
diff --git a/src/test/ui/check-cfg/compact-names.stderr b/src/test/ui/check-cfg/compact-names.stderr
new file mode 100644
index 00000000000..f1fc4285a71
--- /dev/null
+++ b/src/test/ui/check-cfg/compact-names.stderr
@@ -0,0 +1,10 @@
+warning: unexpected `cfg` condition name
+  --> $DIR/compact-names.rs:11:28
+   |
+LL | #[cfg(target(os = "linux", architecture = "arm"))]
+   |                            ^^^^^^^^^^^^^^^^^^^^
+   |
+   = note: `#[warn(unexpected_cfgs)]` on by default
+
+warning: 1 warning emitted
+
diff --git a/src/test/ui/check-cfg/compact-values.rs b/src/test/ui/check-cfg/compact-values.rs
new file mode 100644
index 00000000000..1f17057840c
--- /dev/null
+++ b/src/test/ui/check-cfg/compact-values.rs
@@ -0,0 +1,15 @@
+// This test check that we correctly emit an warning for compact cfg
+//
+// check-pass
+// compile-flags:--check-cfg=values() -Z unstable-options
+
+#![feature(cfg_target_compact)]
+
+#[cfg(target(os = "linux", arch = "arm"))]
+pub fn expected() {}
+
+#[cfg(target(os = "linux", arch = "X"))]
+//~^ WARNING unexpected `cfg` condition value
+pub fn unexpected() {}
+
+fn main() {}
diff --git a/src/test/ui/check-cfg/compact-values.stderr b/src/test/ui/check-cfg/compact-values.stderr
new file mode 100644
index 00000000000..a196e1537df
--- /dev/null
+++ b/src/test/ui/check-cfg/compact-values.stderr
@@ -0,0 +1,11 @@
+warning: unexpected `cfg` condition value
+  --> $DIR/compact-values.rs:11:28
+   |
+LL | #[cfg(target(os = "linux", arch = "X"))]
+   |                            ^^^^^^^^^^
+   |
+   = note: `#[warn(unexpected_cfgs)]` on by default
+   = note: expected values for `target_arch` are: aarch64, arm, avr, bpf, hexagon, m68k, mips, mips64, msp430, nvptx64, powerpc, powerpc64, riscv32, riscv64, s390x, sparc, sparc64, wasm32, wasm64, x86, x86_64
+
+warning: 1 warning emitted
+
diff --git a/src/test/ui/feature-gates/feature-gate-cfg-target-compact.rs b/src/test/ui/feature-gates/feature-gate-cfg-target-compact.rs
new file mode 100644
index 00000000000..df81b7d2297
--- /dev/null
+++ b/src/test/ui/feature-gates/feature-gate-cfg-target-compact.rs
@@ -0,0 +1,13 @@
+#[cfg(target(os = "x"))] //~ ERROR compact `cfg(target(..))` is experimental
+struct Foo(u64, u64);
+
+#[cfg_attr(target(os = "x"), x)] //~ ERROR compact `cfg(target(..))` is experimental
+struct Bar(u64, u64);
+
+#[cfg(not(any(all(target(os = "x")))))] //~ ERROR compact `cfg(target(..))` is experimental
+fn foo() {}
+
+fn main() {
+    cfg!(target(os = "x"));
+    //~^ ERROR compact `cfg(target(..))` is experimental and subject to change
+}
diff --git a/src/test/ui/feature-gates/feature-gate-cfg-target-compact.stderr b/src/test/ui/feature-gates/feature-gate-cfg-target-compact.stderr
new file mode 100644
index 00000000000..be6fe23ded1
--- /dev/null
+++ b/src/test/ui/feature-gates/feature-gate-cfg-target-compact.stderr
@@ -0,0 +1,39 @@
+error[E0658]: compact `cfg(target(..))` is experimental and subject to change
+  --> $DIR/feature-gate-cfg-target-compact.rs:1:7
+   |
+LL | #[cfg(target(os = "x"))]
+   |       ^^^^^^^^^^^^^^^^
+   |
+   = note: see issue #96901 <https://github.com/rust-lang/rust/issues/96901> for more information
+   = help: add `#![feature(cfg_target_compact)]` to the crate attributes to enable
+
+error[E0658]: compact `cfg(target(..))` is experimental and subject to change
+  --> $DIR/feature-gate-cfg-target-compact.rs:4:12
+   |
+LL | #[cfg_attr(target(os = "x"), x)]
+   |            ^^^^^^^^^^^^^^^^
+   |
+   = note: see issue #96901 <https://github.com/rust-lang/rust/issues/96901> for more information
+   = help: add `#![feature(cfg_target_compact)]` to the crate attributes to enable
+
+error[E0658]: compact `cfg(target(..))` is experimental and subject to change
+  --> $DIR/feature-gate-cfg-target-compact.rs:7:19
+   |
+LL | #[cfg(not(any(all(target(os = "x")))))]
+   |                   ^^^^^^^^^^^^^^^^
+   |
+   = note: see issue #96901 <https://github.com/rust-lang/rust/issues/96901> for more information
+   = help: add `#![feature(cfg_target_compact)]` to the crate attributes to enable
+
+error[E0658]: compact `cfg(target(..))` is experimental and subject to change
+  --> $DIR/feature-gate-cfg-target-compact.rs:11:10
+   |
+LL |     cfg!(target(os = "x"));
+   |          ^^^^^^^^^^^^^^^^
+   |
+   = note: see issue #96901 <https://github.com/rust-lang/rust/issues/96901> for more information
+   = help: add `#![feature(cfg_target_compact)]` to the crate attributes to enable
+
+error: aborting due to 4 previous errors
+
+For more information about this error, try `rustc --explain E0658`.