|
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. |
3 | 6 | //
|
4 | 7 | // check-pass
|
5 | 8 | // compile-flags: --check-cfg=cfg() -Z unstable-options
|
6 | 9 |
|
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` |
8 | 80 | //~^ WARNING unexpected `cfg` condition value
|
9 | 81 | fn target_os_linux_misspell() {}
|
10 | 82 |
|
| 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 | + |
11 | 90 | #[cfg(target_os = "linux")]
|
12 | 91 | fn target_os_linux() {}
|
13 | 92 |
|
14 |
| -#[cfg(target_has_atomic = "0")] |
15 |
| -//~^ WARNING unexpected `cfg` condition value |
16 |
| -fn target_has_atomic_invalid() {} |
17 |
| - |
18 | 93 | #[cfg(target_has_atomic = "8")]
|
19 |
| -fn target_has_atomic() {} |
| 94 | +fn target_has_atomic_8() {} |
20 | 95 |
|
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() {} |
24 | 98 |
|
25 | 99 | #[cfg(unix)]
|
26 | 100 | fn unix() {}
|
27 | 101 |
|
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 |
| - |
39 | 102 | #[cfg(doc)]
|
40 | 103 | fn doc() {}
|
41 | 104 |
|
|
0 commit comments