Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 5bfb9f5

Browse files
committedDec 7, 2023
Strengthen well known check-cfg names and values test
1 parent 568f6a8 commit 5bfb9f5

File tree

7 files changed

+281
-74
lines changed

7 files changed

+281
-74
lines changed
 

‎compiler/rustc_session/src/config.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1422,6 +1422,9 @@ impl CheckCfg {
14221422
};
14231423

14241424
// NOTE: This should be kept in sync with `default_configuration`
1425+
//
1426+
// When adding a new config here you should also update
1427+
// `tests/ui/check-cfg/well-known-values.rs`.
14251428

14261429
let panic_values = &PanicStrategy::all();
14271430

‎tests/ui/check-cfg/compact-values.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#[cfg(target(os = "linux", arch = "arm"))]
99
pub fn expected() {}
1010

11-
#[cfg(target(os = "linux", arch = "X"))]
11+
#[cfg(target(os = "linux", pointer_width = "X"))]
1212
//~^ WARNING unexpected `cfg` condition value
1313
pub fn unexpected() {}
1414

‎tests/ui/check-cfg/compact-values.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
warning: unexpected `cfg` condition value: `X`
22
--> $DIR/compact-values.rs:11:28
33
|
4-
LL | #[cfg(target(os = "linux", arch = "X"))]
5-
| ^^^^^^^^^^
4+
LL | #[cfg(target(os = "linux", pointer_width = "X"))]
5+
| ^^^^^^^^^^^^^^^^^^^
66
|
7-
= note: expected values for `target_arch` are: `aarch64`, `arm`, `avr`, `bpf`, `csky`, `hexagon`, `loongarch64`, `m68k`, `mips`, `mips32r6`, `mips64`, `mips64r6`, `msp430`, `nvptx64`, `powerpc`, `powerpc64`, `riscv32`, `riscv64`, `s390x`, `sparc`, `sparc64`, `wasm32`, `wasm64`, `x86`, `x86_64`
7+
= note: expected values for `target_pointer_width` are: `16`, `32`, `64`
88
= note: `#[warn(unexpected_cfgs)]` on by default
99

1010
warning: 1 warning emitted

‎tests/ui/check-cfg/values-target-json.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@
1010
#[lang = "sized"]
1111
trait Sized {}
1212

13-
#[cfg(target_os = "linuz")]
14-
//~^ WARNING unexpected `cfg` condition value
15-
fn target_os_linux_misspell() {}
16-
1713
#[cfg(target_os = "linux")]
1814
fn target_os_linux() {}
1915

‎tests/ui/check-cfg/values-target-json.stderr

Lines changed: 0 additions & 13 deletions
This file was deleted.

‎tests/ui/check-cfg/well-known-values.rs

Lines changed: 67 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,90 @@
1-
// This test check that we lint on non well known values and that we don't lint on well known
2-
// values
1+
// This test check that we recogniez all the well known config names
2+
// and that we correctly lint on unexpected values.
3+
//
4+
// This test also serve as an "anti-regression" for the well known
5+
// values since the suggestion shows them.
36
//
47
// check-pass
58
// compile-flags: --check-cfg=cfg() -Z unstable-options
69

10+
#![feature(cfg_overflow_checks)]
11+
#![feature(cfg_target_has_atomic)]
12+
#![feature(cfg_target_has_atomic_equal_alignment)]
13+
#![feature(cfg_target_abi)]
14+
#![feature(cfg_relocation_model)]
15+
#![feature(cfg_sanitize)]
16+
#![feature(cfg_target_thread_local)]
17+
18+
#[cfg(any(
19+
doc = "_UNEXPECTED_VALUE",
20+
//~^ WARN unexpected `cfg` condition value
21+
miri = "_UNEXPECTED_VALUE",
22+
//~^ WARN unexpected `cfg` condition value
23+
unix = "_UNEXPECTED_VALUE",
24+
//~^ WARN unexpected `cfg` condition value
25+
test = "_UNEXPECTED_VALUE",
26+
//~^ WARN unexpected `cfg` condition value
27+
doctest = "_UNEXPECTED_VALUE",
28+
//~^ WARN unexpected `cfg` condition value
29+
windows = "_UNEXPECTED_VALUE",
30+
//~^ WARN unexpected `cfg` condition value
31+
proc_macro = "_UNEXPECTED_VALUE",
32+
//~^ WARN unexpected `cfg` condition value
33+
panic = "_UNEXPECTED_VALUE",
34+
//~^ WARN unexpected `cfg` condition value
35+
sanitize = "_UNEXPECTED_VALUE",
36+
//~^ WARN unexpected `cfg` condition value
37+
relocation_model = "_UNEXPECTED_VALUE",
38+
//~^ WARN unexpected `cfg` condition value
39+
debug_assertions = "_UNEXPECTED_VALUE",
40+
//~^ WARN unexpected `cfg` condition value
41+
overflow_checks = "_UNEXPECTED_VALUE",
42+
//~^ WARN unexpected `cfg` condition value
43+
target_thread_local = "_UNEXPECTED_VALUE",
44+
//~^ WARN unexpected `cfg` condition value
45+
target_feature = "_UNEXPECTED_VALUE", // currently no values are checked
46+
target_os = "_UNEXPECTED_VALUE",
47+
//~^ WARN unexpected `cfg` condition value
48+
target_family = "_UNEXPECTED_VALUE",
49+
//~^ WARN unexpected `cfg` condition value
50+
target_arch = "_UNEXPECTED_VALUE",
51+
//~^ WARN unexpected `cfg` condition value
52+
target_endian = "_UNEXPECTED_VALUE",
53+
//~^ WARN unexpected `cfg` condition value
54+
target_env = "_UNEXPECTED_VALUE",
55+
//~^ WARN unexpected `cfg` condition value
56+
target_abi = "_UNEXPECTED_VALUE",
57+
//~^ WARN unexpected `cfg` condition value
58+
target_vendor = "_UNEXPECTED_VALUE",
59+
//~^ WARN unexpected `cfg` condition value
60+
target_pointer_width = "_UNEXPECTED_VALUE",
61+
//~^ WARN unexpected `cfg` condition value
62+
target_has_atomic = "_UNEXPECTED_VALUE",
63+
//~^ WARN unexpected `cfg` condition value
64+
target_has_atomic_load_store = "_UNEXPECTED_VALUE",
65+
//~^ WARN unexpected `cfg` condition value
66+
target_has_atomic_equal_alignment = "_UNEXPECTED_VALUE"
67+
//~^ WARN unexpected `cfg` condition value
68+
))]
69+
fn unexpected_values() {}
70+
71+
// testing that we suggest `linux`
772
#[cfg(target_os = "linuz")]
873
//~^ WARNING unexpected `cfg` condition value
974
fn target_os_linux_misspell() {}
1075

1176
#[cfg(target_os = "linux")]
1277
fn target_os_linux() {}
1378

14-
#[cfg(target_has_atomic = "0")]
15-
//~^ WARNING unexpected `cfg` condition value
16-
fn target_has_atomic_invalid() {}
17-
1879
#[cfg(target_has_atomic = "8")]
1980
fn target_has_atomic() {}
2081

21-
#[cfg(unix = "aa")]
22-
//~^ WARNING unexpected `cfg` condition value
23-
fn unix_with_value() {}
24-
2582
#[cfg(unix)]
2683
fn unix() {}
2784

28-
#[cfg(miri = "miri")]
29-
//~^ WARNING unexpected `cfg` condition value
30-
fn miri_with_value() {}
31-
3285
#[cfg(miri)]
3386
fn miri() {}
3487

35-
#[cfg(doc = "linux")]
36-
//~^ WARNING unexpected `cfg` condition value
37-
fn doc_with_value() {}
38-
3988
#[cfg(doc)]
4089
fn doc() {}
4190

Lines changed: 207 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,225 @@
1-
warning: unexpected `cfg` condition value: `linuz`
2-
--> $DIR/well-known-values.rs:7:7
1+
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
2+
--> $DIR/well-known-values.rs:19:5
33
|
4-
LL | #[cfg(target_os = "linuz")]
5-
| ^^^^^^^^^^^^-------
6-
| |
7-
| help: there is a expected value with a similar name: `"linux"`
4+
LL | doc = "_UNEXPECTED_VALUE",
5+
| ^^^----------------------
6+
| |
7+
| help: remove the value
88
|
9-
= note: expected values for `target_os` are: `aix`, `android`, `cuda`, `dragonfly`, `emscripten`, `espidf`, `freebsd`, `fuchsia`, `haiku`, `hermit`, `horizon`, `hurd`, `illumos`, `ios`, `l4re`, `linux`, `macos`, `netbsd`, `none`, `nto`, `openbsd`, `psp`, `redox`, `solaris`, `solid_asp3`, `teeos`, `tvos`, `uefi`, `unknown`, `vita`, `vxworks`, `wasi`, `watchos`, `windows`, `xous`
9+
= note: no expected value for `doc`
1010
= note: `#[warn(unexpected_cfgs)]` on by default
1111

12-
warning: unexpected `cfg` condition value: `0`
13-
--> $DIR/well-known-values.rs:14:7
12+
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
13+
--> $DIR/well-known-values.rs:21:5
1414
|
15-
LL | #[cfg(target_has_atomic = "0")]
16-
| ^^^^^^^^^^^^^^^^^^^^---
17-
| |
18-
| help: there is a expected value with a similar name: `"8"`
15+
LL | miri = "_UNEXPECTED_VALUE",
16+
| ^^^^----------------------
17+
| |
18+
| help: remove the value
1919
|
20-
= note: expected values for `target_has_atomic` are: (none), `128`, `16`, `32`, `64`, `8`, `ptr`
20+
= note: no expected value for `miri`
2121

22-
warning: unexpected `cfg` condition value: `aa`
23-
--> $DIR/well-known-values.rs:21:7
22+
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
23+
--> $DIR/well-known-values.rs:23:5
2424
|
25-
LL | #[cfg(unix = "aa")]
26-
| ^^^^-------
27-
| |
28-
| help: remove the value
25+
LL | unix = "_UNEXPECTED_VALUE",
26+
| ^^^^----------------------
27+
| |
28+
| help: remove the value
2929
|
3030
= note: no expected value for `unix`
3131

32-
warning: unexpected `cfg` condition value: `miri`
33-
--> $DIR/well-known-values.rs:28:7
32+
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
33+
--> $DIR/well-known-values.rs:25:5
3434
|
35-
LL | #[cfg(miri = "miri")]
36-
| ^^^^---------
37-
| |
38-
| help: remove the value
35+
LL | test = "_UNEXPECTED_VALUE",
36+
| ^^^^----------------------
37+
| |
38+
| help: remove the value
3939
|
40-
= note: no expected value for `miri`
40+
= note: no expected value for `test`
4141

42-
warning: unexpected `cfg` condition value: `linux`
43-
--> $DIR/well-known-values.rs:35:7
42+
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
43+
--> $DIR/well-known-values.rs:27:5
4444
|
45-
LL | #[cfg(doc = "linux")]
46-
| ^^^----------
47-
| |
48-
| help: remove the value
45+
LL | doctest = "_UNEXPECTED_VALUE",
46+
| ^^^^^^^----------------------
47+
| |
48+
| help: remove the value
4949
|
50-
= note: no expected value for `doc`
50+
= note: no expected value for `doctest`
51+
52+
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
53+
--> $DIR/well-known-values.rs:29:5
54+
|
55+
LL | windows = "_UNEXPECTED_VALUE",
56+
| ^^^^^^^----------------------
57+
| |
58+
| help: remove the value
59+
|
60+
= note: no expected value for `windows`
61+
62+
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
63+
--> $DIR/well-known-values.rs:31:5
64+
|
65+
LL | proc_macro = "_UNEXPECTED_VALUE",
66+
| ^^^^^^^^^^----------------------
67+
| |
68+
| help: remove the value
69+
|
70+
= note: no expected value for `proc_macro`
71+
72+
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
73+
--> $DIR/well-known-values.rs:33:5
74+
|
75+
LL | panic = "_UNEXPECTED_VALUE",
76+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
77+
|
78+
= note: expected values for `panic` are: `abort`, `unwind`
79+
80+
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
81+
--> $DIR/well-known-values.rs:35:5
82+
|
83+
LL | sanitize = "_UNEXPECTED_VALUE",
84+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
85+
|
86+
= note: expected values for `sanitize` are: `address`, `cfi`, `hwaddress`, `kcfi`, `kernel-address`, `leak`, `memory`, `memtag`, `safestack`, `shadow-call-stack`, `thread`
87+
88+
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
89+
--> $DIR/well-known-values.rs:37:5
90+
|
91+
LL | relocation_model = "_UNEXPECTED_VALUE",
92+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
93+
|
94+
= note: expected values for `relocation_model` are: `dynamic-no-pic`, `pic`, `pie`, `ropi`, `ropi-rwpi`, `rwpi`, `static`
95+
96+
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
97+
--> $DIR/well-known-values.rs:39:5
98+
|
99+
LL | debug_assertions = "_UNEXPECTED_VALUE",
100+
| ^^^^^^^^^^^^^^^^----------------------
101+
| |
102+
| help: remove the value
103+
|
104+
= note: no expected value for `debug_assertions`
105+
106+
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
107+
--> $DIR/well-known-values.rs:41:5
108+
|
109+
LL | overflow_checks = "_UNEXPECTED_VALUE",
110+
| ^^^^^^^^^^^^^^^----------------------
111+
| |
112+
| help: remove the value
113+
|
114+
= note: no expected value for `overflow_checks`
115+
116+
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
117+
--> $DIR/well-known-values.rs:43:5
118+
|
119+
LL | target_thread_local = "_UNEXPECTED_VALUE",
120+
| ^^^^^^^^^^^^^^^^^^^----------------------
121+
| |
122+
| help: remove the value
123+
|
124+
= note: no expected value for `target_thread_local`
125+
126+
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
127+
--> $DIR/well-known-values.rs:46:5
128+
|
129+
LL | target_os = "_UNEXPECTED_VALUE",
130+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
131+
|
132+
= note: expected values for `target_os` are: `aix`, `android`, `cuda`, `dragonfly`, `emscripten`, `espidf`, `freebsd`, `fuchsia`, `haiku`, `hermit`, `horizon`, `hurd`, `illumos`, `ios`, `l4re`, `linux`, `macos`, `netbsd`, `none`, `nto`, `openbsd`, `psp`, `redox`, `solaris`, `solid_asp3`, `teeos`, `tvos`, `uefi`, `unknown`, `vita`, `vxworks`, `wasi`, `watchos`, `windows`, `xous`
133+
134+
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
135+
--> $DIR/well-known-values.rs:48:5
136+
|
137+
LL | target_family = "_UNEXPECTED_VALUE",
138+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
139+
|
140+
= note: expected values for `target_family` are: `unix`, `wasm`, `windows`
141+
142+
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
143+
--> $DIR/well-known-values.rs:50:5
144+
|
145+
LL | target_arch = "_UNEXPECTED_VALUE",
146+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
147+
|
148+
= note: expected values for `target_arch` are: `aarch64`, `arm`, `avr`, `bpf`, `csky`, `hexagon`, `loongarch64`, `m68k`, `mips`, `mips32r6`, `mips64`, `mips64r6`, `msp430`, `nvptx64`, `powerpc`, `powerpc64`, `riscv32`, `riscv64`, `s390x`, `sparc`, `sparc64`, `wasm32`, `wasm64`, `x86`, `x86_64`
149+
150+
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
151+
--> $DIR/well-known-values.rs:52:5
152+
|
153+
LL | target_endian = "_UNEXPECTED_VALUE",
154+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
155+
|
156+
= note: expected values for `target_endian` are: `big`, `little`
157+
158+
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
159+
--> $DIR/well-known-values.rs:54:5
160+
|
161+
LL | target_env = "_UNEXPECTED_VALUE",
162+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
163+
|
164+
= note: expected values for `target_env` are: ``, `eabihf`, `gnu`, `gnueabihf`, `msvc`, `musl`, `newlib`, `nto70`, `nto71`, `ohos`, `psx`, `relibc`, `sgx`, `uclibc`
165+
166+
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
167+
--> $DIR/well-known-values.rs:56:5
168+
|
169+
LL | target_abi = "_UNEXPECTED_VALUE",
170+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
171+
|
172+
= note: expected values for `target_abi` are: ``, `abi64`, `abiv2`, `abiv2hf`, `eabi`, `eabihf`, `elf`, `fortanix`, `ilp32`, `llvm`, `macabi`, `sim`, `softfloat`, `spe`, `uwp`, `vec-extabi`, `x32`
173+
174+
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
175+
--> $DIR/well-known-values.rs:58:5
176+
|
177+
LL | target_vendor = "_UNEXPECTED_VALUE",
178+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
179+
|
180+
= note: expected values for `target_vendor` are: `apple`, `espressif`, `fortanix`, `ibm`, `kmc`, `nintendo`, `nvidia`, `pc`, `sony`, `sun`, `unikraft`, `unknown`, `uwp`, `wrs`
181+
182+
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
183+
--> $DIR/well-known-values.rs:60:5
184+
|
185+
LL | target_pointer_width = "_UNEXPECTED_VALUE",
186+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
187+
|
188+
= note: expected values for `target_pointer_width` are: `16`, `32`, `64`
189+
190+
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
191+
--> $DIR/well-known-values.rs:62:5
192+
|
193+
LL | target_has_atomic = "_UNEXPECTED_VALUE",
194+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
195+
|
196+
= note: expected values for `target_has_atomic` are: (none), `128`, `16`, `32`, `64`, `8`, `ptr`
197+
198+
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
199+
--> $DIR/well-known-values.rs:64:5
200+
|
201+
LL | target_has_atomic_load_store = "_UNEXPECTED_VALUE",
202+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
203+
|
204+
= note: expected values for `target_has_atomic_load_store` are: (none), `128`, `16`, `32`, `64`, `8`, `ptr`
205+
206+
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
207+
--> $DIR/well-known-values.rs:66:5
208+
|
209+
LL | target_has_atomic_equal_alignment = "_UNEXPECTED_VALUE"
210+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
211+
|
212+
= note: expected values for `target_has_atomic_equal_alignment` are: (none), `128`, `16`, `32`, `64`, `8`, `ptr`
213+
214+
warning: unexpected `cfg` condition value: `linuz`
215+
--> $DIR/well-known-values.rs:72:7
216+
|
217+
LL | #[cfg(target_os = "linuz")]
218+
| ^^^^^^^^^^^^-------
219+
| |
220+
| help: there is a expected value with a similar name: `"linux"`
221+
|
222+
= note: expected values for `target_os` are: `aix`, `android`, `cuda`, `dragonfly`, `emscripten`, `espidf`, `freebsd`, `fuchsia`, `haiku`, `hermit`, `horizon`, `hurd`, `illumos`, `ios`, `l4re`, `linux`, `macos`, `netbsd`, `none`, `nto`, `openbsd`, `psp`, `redox`, `solaris`, `solid_asp3`, `teeos`, `tvos`, `uefi`, `unknown`, `vita`, `vxworks`, `wasi`, `watchos`, `windows`, `xous`
51223

52-
warning: 5 warnings emitted
224+
warning: 25 warnings emitted
53225

0 commit comments

Comments
 (0)
Please sign in to comment.