-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
Expand file tree
/
Copy pathcfg_select.rs
More file actions
204 lines (177 loc) · 3.56 KB
/
cfg_select.rs
File metadata and controls
204 lines (177 loc) · 3.56 KB
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#![crate_type = "lib"]
#![warn(unreachable_cfg_select_predicates)] // Unused warnings are disabled by default in UI tests.
fn print() {
println!(cfg_select! {
unix => { "unix" }
_ => { "not unix" }
});
}
fn print_2() {
println!(cfg_select! {
unix => "unix",
_ => "not unix",
});
}
fn arm_rhs_expr_1() -> i32 {
cfg_select! {
true => 1
}
}
fn arm_rhs_expr_2() -> i32 {
cfg_select! {
false => 2,
true => 1
}
}
fn arm_rhs_expr_3() -> i32 {
cfg_select! {
any(true) => 1,
any(false) => 2,
any(true) => { 42 }
any(true) => { 42 },
any(false) => -1 as i32,
any(true) => 2 + 2,
any(false) => "",
any(true) => if true { 42 } else { 84 }
any(false) => if true { 42 } else { 84 },
any(true) => return 42,
any(false) => loop {}
any(true) => (1, 2),
any(false) => (1, 2,),
any(true) => todo!(),
any(false) => println!("hello"),
}
}
fn expand_to_statements() -> i32 {
cfg_select! {
false => {
let b = 2;
b + 1
}
true => {
let a = 1;
a + 1
}
}
}
type ExpandToType = cfg_select! {
unix => { u32 },
_ => i32,
};
fn expand_to_pattern(x: Option<i32>) -> bool {
match x {
(cfg_select! {
unix => Some(n),
_ => None,
}) => true,
_ => false,
}
}
cfg_select! {
false => {
fn foo() {}
}
_ => {
fn bar() {}
}
}
struct S;
impl S {
cfg_select! {
false => {
fn foo() {}
}
_ => {
fn bar() {}
}
}
}
trait T {
cfg_select! {
false => {
fn a();
}
_ => {
fn b();
}
}
}
impl T for S {
cfg_select! {
false => {
fn a() {}
},
_ => {
fn b() {}
}
}
}
extern "C" {
cfg_select! {
false => {
fn puts(s: *const i8) -> i32;
}
_ => {
fn printf(fmt: *const i8, ...) -> i32;
}
}
}
cfg_select! {
_ => {}
true => {}
//~^ WARN unreachable configuration predicate
}
cfg_select! {
true => {}
_ => {}
//~^ WARN unreachable configuration predicate
}
cfg_select! {
unix => {}
not(unix) => {},
_ => {}
//~^ WARN unreachable configuration predicate
}
cfg_select! {
test => {}
test => {}
//~^ WARN unreachable configuration predicate
_ => {}
//~^ WARN unreachable configuration predicate
}
cfg_select! {
//~^ ERROR none of the predicates in this `cfg_select` evaluated to true
false => {}
}
cfg_select! {}
//~^ ERROR none of the predicates in this `cfg_select` evaluated to true
cfg_select! {
=> {}
//~^ ERROR expected a literal (`1u8`, `1.0f32`, `"string"`, etc.) here, found `=>`
}
cfg_select! {
() => {}
//~^ ERROR expected a literal (`1u8`, `1.0f32`, `"string"`, etc.) here, found expression
}
cfg_select! {
"str" => {}
//~^ ERROR malformed `cfg_select` macro input [E0539]
}
cfg_select! {
a::b => {}
//~^ ERROR malformed `cfg_select` macro input [E0539]
}
cfg_select! {
a() => {}
//~^ ERROR invalid predicate `a` [E0537]
}
cfg_select! {
a + 1 => {}
//~^ ERROR expected one of `(`, `::`, `=>`, or `=`, found `+`
//~| WARN unexpected `cfg` condition name
}
cfg_select! {
cfg!() => {}
//~^ ERROR expected one of `(`, `::`, `=>`, or `=`, found `!`
//~| WARN unexpected `cfg` condition name
}