summaryrefslogtreecommitdiffstats
path: root/tests/ui/check-cfg/well-known-values.rs
blob: 21268bf10d5c0cfe92dbc8672a34dcdb71fc2b3c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// This test check that we recognize all the well known config names
// and that we correctly lint on unexpected values.
//
// This test also serve as an "anti-regression" for the well known
// values since the suggestion shows them.
//
// check-pass
// compile-flags: --check-cfg=cfg() -Z unstable-options

#![feature(cfg_overflow_checks)]
#![feature(cfg_relocation_model)]
#![feature(cfg_sanitize)]
#![feature(cfg_target_abi)]
#![feature(cfg_target_has_atomic)]
#![feature(cfg_target_has_atomic_equal_alignment)]
#![feature(cfg_target_thread_local)]

// This part makes sure that none of the well known names are
// unexpected.
//
// BUT to make sure that no expected values changes without
// being noticed we pass them a obviously wrong value so the
// diagnostic prints the list of expected values.
#[cfg(any(
    // tidy-alphabetical-start
    debug_assertions = "_UNEXPECTED_VALUE",
    //~^ WARN unexpected `cfg` condition value
    doc = "_UNEXPECTED_VALUE",
    //~^ WARN unexpected `cfg` condition value
    doctest = "_UNEXPECTED_VALUE",
    //~^ WARN unexpected `cfg` condition value
    miri = "_UNEXPECTED_VALUE",
    //~^ WARN unexpected `cfg` condition value
    overflow_checks = "_UNEXPECTED_VALUE",
    //~^ WARN unexpected `cfg` condition value
    panic = "_UNEXPECTED_VALUE",
    //~^ WARN unexpected `cfg` condition value
    proc_macro = "_UNEXPECTED_VALUE",
    //~^ WARN unexpected `cfg` condition value
    relocation_model = "_UNEXPECTED_VALUE",
    //~^ WARN unexpected `cfg` condition value
    sanitize = "_UNEXPECTED_VALUE",
    //~^ WARN unexpected `cfg` condition value
    target_abi = "_UNEXPECTED_VALUE",
    //~^ WARN unexpected `cfg` condition value
    target_arch = "_UNEXPECTED_VALUE",
    //~^ WARN unexpected `cfg` condition value
    target_endian = "_UNEXPECTED_VALUE",
    //~^ WARN unexpected `cfg` condition value
    target_env = "_UNEXPECTED_VALUE",
    //~^ WARN unexpected `cfg` condition value
    target_family = "_UNEXPECTED_VALUE",
    //~^ WARN unexpected `cfg` condition value
    target_feature = "_UNEXPECTED_VALUE",
    //~^ WARN unexpected `cfg` condition value
    target_has_atomic = "_UNEXPECTED_VALUE",
    //~^ WARN unexpected `cfg` condition value
    target_has_atomic_equal_alignment = "_UNEXPECTED_VALUE",
    //~^ WARN unexpected `cfg` condition value
    target_has_atomic_load_store = "_UNEXPECTED_VALUE",
    //~^ WARN unexpected `cfg` condition value
    target_os = "_UNEXPECTED_VALUE",
    //~^ WARN unexpected `cfg` condition value
    target_pointer_width = "_UNEXPECTED_VALUE",
    //~^ WARN unexpected `cfg` condition value
    target_thread_local = "_UNEXPECTED_VALUE",
    //~^ WARN unexpected `cfg` condition value
    target_vendor = "_UNEXPECTED_VALUE",
    //~^ WARN unexpected `cfg` condition value
    test = "_UNEXPECTED_VALUE",
    //~^ WARN unexpected `cfg` condition value
    unix = "_UNEXPECTED_VALUE",
    //~^ WARN unexpected `cfg` condition value
    windows = "_UNEXPECTED_VALUE",
    //~^ WARN unexpected `cfg` condition value
    // tidy-alphabetical-end
))]
fn unexpected_values() {}

#[cfg(target_os = "linuz")] // testing that we suggest `linux`
//~^ WARNING unexpected `cfg` condition value
fn target_os_linux_misspell() {}

// The #[cfg]s below serve as a safeguard to make sure we
// don't lint when using an expected well-known name and
// value, only a small subset of all possible expected
// configs are tested, since we already test the names
// above and don't need to test all values, just different
// combinations (without value, with value, both...).

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

#[cfg(target_feature = "crt-static")] // pure rustc feature
fn target_feature() {}

#[cfg(target_has_atomic = "8")]
fn target_has_atomic_8() {}

#[cfg(target_has_atomic)]
fn target_has_atomic() {}

#[cfg(unix)]
fn unix() {}

#[cfg(doc)]
fn doc() {}

fn main() {}