Skip to content

Commit a002814

Browse files
committed
Strengthen well known check-cfg names and values test
1 parent b9540b7 commit a002814

File tree

3 files changed

+294
-56
lines changed

3 files changed

+294
-56
lines changed

compiler/rustc_session/src/config.rs

+3
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/well-known-values.rs

+85-22
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,104 @@
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 recognize 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

7-
#[cfg(target_os = "linuz")]
10+
#![feature(cfg_overflow_checks)]
11+
#![feature(cfg_relocation_model)]
12+
#![feature(cfg_sanitize)]
13+
#![feature(cfg_target_abi)]
14+
#![feature(cfg_target_has_atomic)]
15+
#![feature(cfg_target_has_atomic_equal_alignment)]
16+
#![feature(cfg_target_thread_local)]
17+
18+
// This part makes sure that none of the well known names are
19+
// unexpected.
20+
//
21+
// BUT to make sure that no expected values changes without
22+
// being noticed we pass them a obviously wrong value so the
23+
// diagnostic prints the list of expected values.
24+
#[cfg(any(
25+
// tidy-alphabetical-start
26+
debug_assertions = "_UNEXPECTED_VALUE",
27+
//~^ WARN unexpected `cfg` condition value
28+
doc = "_UNEXPECTED_VALUE",
29+
//~^ WARN unexpected `cfg` condition value
30+
doctest = "_UNEXPECTED_VALUE",
31+
//~^ WARN unexpected `cfg` condition value
32+
miri = "_UNEXPECTED_VALUE",
33+
//~^ WARN unexpected `cfg` condition value
34+
overflow_checks = "_UNEXPECTED_VALUE",
35+
//~^ WARN unexpected `cfg` condition value
36+
panic = "_UNEXPECTED_VALUE",
37+
//~^ WARN unexpected `cfg` condition value
38+
proc_macro = "_UNEXPECTED_VALUE",
39+
//~^ WARN unexpected `cfg` condition value
40+
relocation_model = "_UNEXPECTED_VALUE",
41+
//~^ WARN unexpected `cfg` condition value
42+
sanitize = "_UNEXPECTED_VALUE",
43+
//~^ WARN unexpected `cfg` condition value
44+
target_abi = "_UNEXPECTED_VALUE",
45+
//~^ WARN unexpected `cfg` condition value
46+
target_arch = "_UNEXPECTED_VALUE",
47+
//~^ WARN unexpected `cfg` condition value
48+
target_endian = "_UNEXPECTED_VALUE",
49+
//~^ WARN unexpected `cfg` condition value
50+
target_env = "_UNEXPECTED_VALUE",
51+
//~^ WARN unexpected `cfg` condition value
52+
target_family = "_UNEXPECTED_VALUE",
53+
//~^ WARN unexpected `cfg` condition value
54+
target_feature = "_UNEXPECTED_VALUE", // currently *any* values are "expected"
55+
target_has_atomic = "_UNEXPECTED_VALUE",
56+
//~^ WARN unexpected `cfg` condition value
57+
target_has_atomic_equal_alignment = "_UNEXPECTED_VALUE",
58+
//~^ WARN unexpected `cfg` condition value
59+
target_has_atomic_load_store = "_UNEXPECTED_VALUE",
60+
//~^ WARN unexpected `cfg` condition value
61+
target_os = "_UNEXPECTED_VALUE",
62+
//~^ WARN unexpected `cfg` condition value
63+
target_pointer_width = "_UNEXPECTED_VALUE",
64+
//~^ WARN unexpected `cfg` condition value
65+
target_thread_local = "_UNEXPECTED_VALUE",
66+
//~^ WARN unexpected `cfg` condition value
67+
target_vendor = "_UNEXPECTED_VALUE",
68+
//~^ WARN unexpected `cfg` condition value
69+
test = "_UNEXPECTED_VALUE",
70+
//~^ WARN unexpected `cfg` condition value
71+
unix = "_UNEXPECTED_VALUE",
72+
//~^ WARN unexpected `cfg` condition value
73+
windows = "_UNEXPECTED_VALUE",
74+
//~^ WARN unexpected `cfg` condition value
75+
// tidy-alphabetical-end
76+
))]
77+
fn unexpected_values() {}
78+
79+
#[cfg(target_os = "linuz")] // testing that we suggest `linux`
880
//~^ WARNING unexpected `cfg` condition value
981
fn target_os_linux_misspell() {}
1082

83+
// The #[cfg]s below serve as a safeguard to make sure we
84+
// don't lint when using an expected well-known name and
85+
// value, only a small subset of all possible expected
86+
// configs are tested, since we already test the names
87+
// above and don't need to test all values, just different
88+
// combinations (without value, with value, both...).
89+
1190
#[cfg(target_os = "linux")]
1291
fn target_os_linux() {}
1392

14-
#[cfg(target_has_atomic = "0")]
15-
//~^ WARNING unexpected `cfg` condition value
16-
fn target_has_atomic_invalid() {}
17-
1893
#[cfg(target_has_atomic = "8")]
19-
fn target_has_atomic() {}
94+
fn target_has_atomic_8() {}
2095

21-
#[cfg(unix = "aa")]
22-
//~^ WARNING unexpected `cfg` condition value
23-
fn unix_with_value() {}
96+
#[cfg(target_has_atomic)]
97+
fn target_has_atomic() {}
2498

2599
#[cfg(unix)]
26100
fn unix() {}
27101

28-
#[cfg(miri = "miri")]
29-
//~^ WARNING unexpected `cfg` condition value
30-
fn miri_with_value() {}
31-
32-
#[cfg(miri)]
33-
fn miri() {}
34-
35-
#[cfg(doc = "linux")]
36-
//~^ WARNING unexpected `cfg` condition value
37-
fn doc_with_value() {}
38-
39102
#[cfg(doc)]
40103
fn doc() {}
41104

+206-34
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:26:5
33
|
4-
LL | #[cfg(target_os = "linuz")]
5-
| ^^^^^^^^^^^^-------
6-
| |
7-
| help: there is a expected value with a similar name: `"linux"`
4+
LL | debug_assertions = "_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 `debug_assertions`
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:28:5
14+
|
15+
LL | doc = "_UNEXPECTED_VALUE",
16+
| ^^^----------------------
17+
| |
18+
| help: remove the value
19+
|
20+
= note: no expected value for `doc`
21+
22+
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
23+
--> $DIR/well-known-values.rs:30:5
24+
|
25+
LL | doctest = "_UNEXPECTED_VALUE",
26+
| ^^^^^^^----------------------
27+
| |
28+
| help: remove the value
29+
|
30+
= note: no expected value for `doctest`
31+
32+
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
33+
--> $DIR/well-known-values.rs:32:5
34+
|
35+
LL | miri = "_UNEXPECTED_VALUE",
36+
| ^^^^----------------------
37+
| |
38+
| help: remove the value
39+
|
40+
= note: no expected value for `miri`
41+
42+
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
43+
--> $DIR/well-known-values.rs:34:5
44+
|
45+
LL | overflow_checks = "_UNEXPECTED_VALUE",
46+
| ^^^^^^^^^^^^^^^----------------------
47+
| |
48+
| help: remove the value
49+
|
50+
= note: no expected value for `overflow_checks`
51+
52+
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
53+
--> $DIR/well-known-values.rs:36:5
1454
|
15-
LL | #[cfg(target_has_atomic = "0")]
16-
| ^^^^^^^^^^^^^^^^^^^^---
17-
| |
18-
| help: there is a expected value with a similar name: `"8"`
55+
LL | panic = "_UNEXPECTED_VALUE",
56+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
57+
|
58+
= note: expected values for `panic` are: `abort`, `unwind`
59+
60+
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
61+
--> $DIR/well-known-values.rs:38:5
62+
|
63+
LL | proc_macro = "_UNEXPECTED_VALUE",
64+
| ^^^^^^^^^^----------------------
65+
| |
66+
| help: remove the value
67+
|
68+
= note: no expected value for `proc_macro`
69+
70+
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
71+
--> $DIR/well-known-values.rs:40:5
72+
|
73+
LL | relocation_model = "_UNEXPECTED_VALUE",
74+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
75+
|
76+
= note: expected values for `relocation_model` are: `dynamic-no-pic`, `pic`, `pie`, `ropi`, `ropi-rwpi`, `rwpi`, `static`
77+
78+
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
79+
--> $DIR/well-known-values.rs:42:5
80+
|
81+
LL | sanitize = "_UNEXPECTED_VALUE",
82+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
83+
|
84+
= note: expected values for `sanitize` are: `address`, `cfi`, `hwaddress`, `kcfi`, `kernel-address`, `leak`, `memory`, `memtag`, `safestack`, `shadow-call-stack`, `thread`
85+
86+
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
87+
--> $DIR/well-known-values.rs:44:5
88+
|
89+
LL | target_abi = "_UNEXPECTED_VALUE",
90+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
91+
|
92+
= note: expected values for `target_abi` are: ``, `abi64`, `abiv2`, `abiv2hf`, `eabi`, `eabihf`, `elf`, `fortanix`, `ilp32`, `llvm`, `macabi`, `sim`, `softfloat`, `spe`, `uwp`, `vec-extabi`, `x32`
93+
94+
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
95+
--> $DIR/well-known-values.rs:46:5
96+
|
97+
LL | target_arch = "_UNEXPECTED_VALUE",
98+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
99+
|
100+
= 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`
101+
102+
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
103+
--> $DIR/well-known-values.rs:48:5
104+
|
105+
LL | target_endian = "_UNEXPECTED_VALUE",
106+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
107+
|
108+
= note: expected values for `target_endian` are: `big`, `little`
109+
110+
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
111+
--> $DIR/well-known-values.rs:50:5
112+
|
113+
LL | target_env = "_UNEXPECTED_VALUE",
114+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
115+
|
116+
= note: expected values for `target_env` are: ``, `eabihf`, `gnu`, `gnueabihf`, `msvc`, `musl`, `newlib`, `nto70`, `nto71`, `ohos`, `psx`, `relibc`, `sgx`, `uclibc`
117+
118+
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
119+
--> $DIR/well-known-values.rs:52:5
120+
|
121+
LL | target_family = "_UNEXPECTED_VALUE",
122+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
123+
|
124+
= note: expected values for `target_family` are: `unix`, `wasm`, `windows`
125+
126+
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
127+
--> $DIR/well-known-values.rs:55:5
128+
|
129+
LL | target_has_atomic = "_UNEXPECTED_VALUE",
130+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19131
|
20132
= note: expected values for `target_has_atomic` are: (none), `128`, `16`, `32`, `64`, `8`, `ptr`
21133

22-
warning: unexpected `cfg` condition value: `aa`
23-
--> $DIR/well-known-values.rs:21:7
134+
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
135+
--> $DIR/well-known-values.rs:57:5
24136
|
25-
LL | #[cfg(unix = "aa")]
26-
| ^^^^-------
27-
| |
28-
| help: remove the value
137+
LL | target_has_atomic_equal_alignment = "_UNEXPECTED_VALUE",
138+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
139+
|
140+
= note: expected values for `target_has_atomic_equal_alignment` are: (none), `128`, `16`, `32`, `64`, `8`, `ptr`
141+
142+
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
143+
--> $DIR/well-known-values.rs:59:5
144+
|
145+
LL | target_has_atomic_load_store = "_UNEXPECTED_VALUE",
146+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
147+
|
148+
= note: expected values for `target_has_atomic_load_store` are: (none), `128`, `16`, `32`, `64`, `8`, `ptr`
149+
150+
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
151+
--> $DIR/well-known-values.rs:61:5
152+
|
153+
LL | target_os = "_UNEXPECTED_VALUE",
154+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
155+
|
156+
= 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`
157+
158+
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
159+
--> $DIR/well-known-values.rs:63:5
160+
|
161+
LL | target_pointer_width = "_UNEXPECTED_VALUE",
162+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
163+
|
164+
= note: expected values for `target_pointer_width` are: `16`, `32`, `64`
165+
166+
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
167+
--> $DIR/well-known-values.rs:65:5
168+
|
169+
LL | target_thread_local = "_UNEXPECTED_VALUE",
170+
| ^^^^^^^^^^^^^^^^^^^----------------------
171+
| |
172+
| help: remove the value
173+
|
174+
= note: no expected value for `target_thread_local`
175+
176+
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
177+
--> $DIR/well-known-values.rs:67:5
178+
|
179+
LL | target_vendor = "_UNEXPECTED_VALUE",
180+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
181+
|
182+
= note: expected values for `target_vendor` are: `apple`, `espressif`, `fortanix`, `ibm`, `kmc`, `nintendo`, `nvidia`, `pc`, `sony`, `sun`, `unikraft`, `unknown`, `uwp`, `wrs`
183+
184+
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
185+
--> $DIR/well-known-values.rs:69:5
186+
|
187+
LL | test = "_UNEXPECTED_VALUE",
188+
| ^^^^----------------------
189+
| |
190+
| help: remove the value
191+
|
192+
= note: no expected value for `test`
193+
194+
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
195+
--> $DIR/well-known-values.rs:71:5
196+
|
197+
LL | unix = "_UNEXPECTED_VALUE",
198+
| ^^^^----------------------
199+
| |
200+
| help: remove the value
29201
|
30202
= note: no expected value for `unix`
31203

32-
warning: unexpected `cfg` condition value: `miri`
33-
--> $DIR/well-known-values.rs:28:7
204+
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
205+
--> $DIR/well-known-values.rs:73:5
34206
|
35-
LL | #[cfg(miri = "miri")]
36-
| ^^^^---------
37-
| |
38-
| help: remove the value
207+
LL | windows = "_UNEXPECTED_VALUE",
208+
| ^^^^^^^----------------------
209+
| |
210+
| help: remove the value
39211
|
40-
= note: no expected value for `miri`
212+
= note: no expected value for `windows`
41213

42-
warning: unexpected `cfg` condition value: `linux`
43-
--> $DIR/well-known-values.rs:35:7
214+
warning: unexpected `cfg` condition value: `linuz`
215+
--> $DIR/well-known-values.rs:79:7
44216
|
45-
LL | #[cfg(doc = "linux")]
46-
| ^^^----------
47-
| |
48-
| help: remove the value
217+
LL | #[cfg(target_os = "linuz")] // testing that we suggest `linux`
218+
| ^^^^^^^^^^^^-------
219+
| |
220+
| help: there is a expected value with a similar name: `"linux"`
49221
|
50-
= note: no expected value for `doc`
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)