Skip to content

Commit 78d2c8e

Browse files
authoredDec 9, 2023
Rollup merge of rust-lang#118702 - Urgau:check-cfg-strengthen-well-known, r=nnethercote
Strengthen well known check-cfg names and values test rust-lang#118494 is changing the implementation of how we expect well known check-cfg names and values, but we currently don't have a test that checks every well known only some of them. This PR therefore strengthen our well known names/values test to include all of the configs to at least avoid unintended regressions and validate new entry. *this PR also contains some drive-by consolidation of unexpected `target_os`, `target_arch` into a single file* r? `@nnethercote` (maybe? feel free to re-assign)
2 parents 546643c + 4c16716 commit 78d2c8e

7 files changed

+298
-77
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/compact-values.rs

+1-1
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

+3-3
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

-4
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

-13
This file was deleted.

‎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

0 commit comments

Comments
 (0)
Please sign in to comment.