RFC3239: Add tests for compact cfg(target(..)) · rust-lang/rust@b9ae3db (original) (raw)

9 files changed

lines changed

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
1 +// check-fail
2 +
3 +#![feature(cfg_target_compact)]
4 +
5 +#[cfg(target(o::o))]
6 +//~^ ERROR `cfg` predicate key must be an identifier
7 +fn one() {}
8 +
9 +#[cfg(target(os = 8))]
10 +//~^ ERROR literal in `cfg` predicate value must be a string
11 +fn two() {}
12 +
13 +#[cfg(target(os = "linux", pointer(width = "64")))]
14 +//~^ ERROR invalid predicate `target_pointer`
15 +fn three() {}
16 +
17 +fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
1 +error: `cfg` predicate key must be an identifier
2 + --> $DIR/cfg-target-compact-errors.rs:5:14
3 + |
4 +LL | #[cfg(target(o::o))]
5 + | ^^^^
6 +
7 +error[E0565]: literal in `cfg` predicate value must be a string
8 + --> $DIR/cfg-target-compact-errors.rs:9:19
9 + |
10 +LL | #[cfg(target(os = 8))]
11 + | ^
12 +
13 +error[E0537]: invalid predicate `target_pointer`
14 + --> $DIR/cfg-target-compact-errors.rs:13:28
15 + |
16 +LL | #[cfg(target(os = "linux", pointer(width = "64")))]
17 + | ^^^^^^^^^^^^^^^^^^^^^
18 +
19 +error: aborting due to 3 previous errors
20 +
21 +Some errors have detailed explanations: E0537, E0565.
22 +For more information about an error, try `rustc --explain E0537`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
1 +// run-pass
2 +#![feature(cfg_target_compact)]
3 +
4 +#[cfg(target(os = "linux", pointer_width = "64"))]
5 +pub fn main() {
6 +}
7 +
8 +#[cfg(not(target(os = "linux", pointer_width = "64")))]
9 +pub fn main() {
10 +}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
1 +// This test check that we correctly emit an warning for compact cfg
2 +//
3 +// check-pass
4 +// compile-flags:--check-cfg=names() -Z unstable-options
5 +
6 +#![feature(cfg_target_compact)]
7 +
8 +#[cfg(target(os = "linux", arch = "arm"))]
9 +pub fn expected() {}
10 +
11 +#[cfg(target(os = "linux", architecture = "arm"))]
12 +//~^ WARNING unexpected `cfg` condition name
13 +pub fn unexpected() {}
14 +
15 +fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
1 +warning: unexpected `cfg` condition name
2 + --> $DIR/compact-names.rs:11:28
3 + |
4 +LL | #[cfg(target(os = "linux", architecture = "arm"))]
5 + | ^^^^^^^^^^^^^^^^^^^^
6 + |
7 + = note: `#[warn(unexpected_cfgs)]` on by default
8 +
9 +warning: 1 warning emitted
10 +
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
1 +// This test check that we correctly emit an warning for compact cfg
2 +//
3 +// check-pass
4 +// compile-flags:--check-cfg=values() -Z unstable-options
5 +
6 +#![feature(cfg_target_compact)]
7 +
8 +#[cfg(target(os = "linux", arch = "arm"))]
9 +pub fn expected() {}
10 +
11 +#[cfg(target(os = "linux", arch = "X"))]
12 +//~^ WARNING unexpected `cfg` condition value
13 +pub fn unexpected() {}
14 +
15 +fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
1 +warning: unexpected `cfg` condition value
2 + --> $DIR/compact-values.rs:11:28
3 + |
4 +LL | #[cfg(target(os = "linux", arch = "X"))]
5 + | ^^^^^^^^^^
6 + |
7 + = note: `#[warn(unexpected_cfgs)]` on by default
8 + = 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
9 +
10 +warning: 1 warning emitted
11 +
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
1 +#[cfg(target(os = "x"))] //~ ERROR compact `cfg(target(..))` is experimental
2 +struct Foo(u64, u64);
3 +
4 +#[cfg_attr(target(os = "x"), x)] //~ ERROR compact `cfg(target(..))` is experimental
5 +struct Bar(u64, u64);
6 +
7 +#[cfg(not(any(all(target(os = "x")))))] //~ ERROR compact `cfg(target(..))` is experimental
8 +fn foo() {}
9 +
10 +fn main() {
11 +cfg!(target(os = "x"));
12 +//~^ ERROR compact `cfg(target(..))` is experimental and subject to change
13 +}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
1 +error[E0658]: compact `cfg(target(..))` is experimental and subject to change
2 + --> $DIR/feature-gate-cfg-target-compact.rs:1:7
3 + |
4 +LL | #[cfg(target(os = "x"))]
5 + | ^^^^^^^^^^^^^^^^
6 + |
7 + = note: see issue #96901 https://github.com/rust-lang/rust/issues/96901 for more information
8 + = help: add `#![feature(cfg_target_compact)]` to the crate attributes to enable
9 +
10 +error[E0658]: compact `cfg(target(..))` is experimental and subject to change
11 + --> $DIR/feature-gate-cfg-target-compact.rs:4:12
12 + |
13 +LL | #[cfg_attr(target(os = "x"), x)]
14 + | ^^^^^^^^^^^^^^^^
15 + |
16 + = note: see issue #96901 https://github.com/rust-lang/rust/issues/96901 for more information
17 + = help: add `#![feature(cfg_target_compact)]` to the crate attributes to enable
18 +
19 +error[E0658]: compact `cfg(target(..))` is experimental and subject to change
20 + --> $DIR/feature-gate-cfg-target-compact.rs:7:19
21 + |
22 +LL | #[cfg(not(any(all(target(os = "x")))))]
23 + | ^^^^^^^^^^^^^^^^
24 + |
25 + = note: see issue #96901 https://github.com/rust-lang/rust/issues/96901 for more information
26 + = help: add `#![feature(cfg_target_compact)]` to the crate attributes to enable
27 +
28 +error[E0658]: compact `cfg(target(..))` is experimental and subject to change
29 + --> $DIR/feature-gate-cfg-target-compact.rs:11:10
30 + |
31 +LL | cfg!(target(os = "x"));
32 + | ^^^^^^^^^^^^^^^^
33 + |
34 + = note: see issue #96901 https://github.com/rust-lang/rust/issues/96901 for more information
35 + = help: add `#![feature(cfg_target_compact)]` to the crate attributes to enable
36 +
37 +error: aborting due to 4 previous errors
38 +
39 +For more information about this error, try `rustc --explain E0658`.