@@ -10,8 +10,8 @@ use rustc_data_structures::sync::Lrc;
10
10
use rustc_errors:: registry:: Registry ;
11
11
use rustc_errors:: { ErrorGuaranteed , Handler } ;
12
12
use rustc_lint:: LintStore ;
13
+ use rustc_middle:: ty;
13
14
use rustc_middle:: util:: Providers ;
14
- use rustc_middle:: { bug, ty} ;
15
15
use rustc_parse:: maybe_new_parser_from_source_str;
16
16
use rustc_query_impl:: QueryCtxt ;
17
17
use rustc_query_system:: query:: print_query_stack;
@@ -104,7 +104,6 @@ pub(crate) fn parse_check_cfg(handler: &EarlyErrorHandler, specs: Vec<String>) -
104
104
let exhaustive_values = !specs. is_empty ( ) ;
105
105
let mut check_cfg = CheckCfg { exhaustive_names, exhaustive_values, ..CheckCfg :: default ( ) } ;
106
106
107
- let mut old_syntax = None ;
108
107
for s in specs {
109
108
let sess = ParseSess :: with_silent_emitter ( Some ( format ! (
110
109
"this error occurred on the command line: `--check-cfg={s}`"
@@ -142,174 +141,101 @@ pub(crate) fn parse_check_cfg(handler: &EarlyErrorHandler, specs: Vec<String>) -
142
141
expected_error ( ) ;
143
142
} ;
144
143
145
- let mut set_old_syntax = || {
146
- // defaults are flipped for the old syntax
147
- if old_syntax == None {
148
- check_cfg. exhaustive_names = false ;
149
- check_cfg. exhaustive_values = false ;
150
- }
151
- old_syntax = Some ( true ) ;
152
- } ;
153
-
154
- if meta_item. has_name ( sym:: names) {
155
- set_old_syntax ( ) ;
156
-
157
- check_cfg. exhaustive_names = true ;
158
- for arg in args {
159
- if arg. is_word ( )
160
- && let Some ( ident) = arg. ident ( )
161
- {
162
- check_cfg. expecteds . entry ( ident. name ) . or_insert ( ExpectedValues :: Any ) ;
163
- } else {
164
- error ! ( "`names()` arguments must be simple identifiers" ) ;
165
- }
166
- }
167
- } else if meta_item. has_name ( sym:: values) {
168
- set_old_syntax ( ) ;
169
-
170
- if let Some ( ( name, values) ) = args. split_first ( ) {
171
- if name. is_word ( )
172
- && let Some ( ident) = name. ident ( )
173
- {
174
- let expected_values = check_cfg
175
- . expecteds
176
- . entry ( ident. name )
177
- . and_modify ( |expected_values| match expected_values {
178
- ExpectedValues :: Some ( _) => { }
179
- ExpectedValues :: Any => {
180
- // handle the case where names(...) was done
181
- // before values by changing to a list
182
- * expected_values = ExpectedValues :: Some ( FxHashSet :: default ( ) ) ;
183
- }
184
- } )
185
- . or_insert_with ( || ExpectedValues :: Some ( FxHashSet :: default ( ) ) ) ;
144
+ if !meta_item. has_name ( sym:: cfg) {
145
+ expected_error ( ) ;
146
+ }
186
147
187
- let ExpectedValues :: Some ( expected_values) = expected_values else {
188
- bug ! ( "`expected_values` should be a list a values" )
189
- } ;
148
+ let mut names = Vec :: new ( ) ;
149
+ let mut values: FxHashSet < _ > = Default :: default ( ) ;
190
150
191
- for val in values {
192
- if let Some ( LitKind :: Str ( s, _) ) = val. lit ( ) . map ( |lit| & lit. kind ) {
193
- expected_values. insert ( Some ( * s) ) ;
194
- } else {
195
- error ! ( "`values()` arguments must be string literals" ) ;
196
- }
197
- }
151
+ let mut any_specified = false ;
152
+ let mut values_specified = false ;
153
+ let mut values_any_specified = false ;
198
154
199
- if values. is_empty ( ) {
200
- expected_values. insert ( None ) ;
201
- }
202
- } else {
203
- error ! ( "`values()` first argument must be a simple identifier" ) ;
155
+ for arg in args {
156
+ if arg. is_word ( )
157
+ && let Some ( ident) = arg. ident ( )
158
+ {
159
+ if values_specified {
160
+ error ! ( "`cfg()` names cannot be after values" ) ;
204
161
}
205
- } else if args. is_empty ( ) {
206
- check_cfg. exhaustive_values = true ;
207
- } else {
208
- expected_error ( ) ;
209
- }
210
- } else if meta_item. has_name ( sym:: cfg) {
211
- old_syntax = Some ( false ) ;
212
-
213
- let mut names = Vec :: new ( ) ;
214
- let mut values: FxHashSet < _ > = Default :: default ( ) ;
215
-
216
- let mut any_specified = false ;
217
- let mut values_specified = false ;
218
- let mut values_any_specified = false ;
219
-
220
- for arg in args {
221
- if arg. is_word ( )
222
- && let Some ( ident) = arg. ident ( )
223
- {
224
- if values_specified {
225
- error ! ( "`cfg()` names cannot be after values" ) ;
226
- }
227
- names. push ( ident) ;
228
- } else if arg. has_name ( sym:: any)
229
- && let Some ( args) = arg. meta_item_list ( )
230
- {
231
- if any_specified {
232
- error ! ( "`any()` cannot be specified multiple times" ) ;
233
- }
234
- any_specified = true ;
235
- if !args. is_empty ( ) {
236
- error ! ( "`any()` must be empty" ) ;
237
- }
238
- } else if arg. has_name ( sym:: values)
239
- && let Some ( args) = arg. meta_item_list ( )
240
- {
241
- if names. is_empty ( ) {
242
- error ! ( "`values()` cannot be specified before the names" ) ;
243
- } else if values_specified {
244
- error ! ( "`values()` cannot be specified multiple times" ) ;
245
- }
246
- values_specified = true ;
247
-
248
- for arg in args {
249
- if let Some ( LitKind :: Str ( s, _) ) = arg. lit ( ) . map ( |lit| & lit. kind ) {
250
- values. insert ( Some ( * s) ) ;
251
- } else if arg. has_name ( sym:: any)
252
- && let Some ( args) = arg. meta_item_list ( )
253
- {
254
- if values_any_specified {
255
- error ! ( "`any()` in `values()` cannot be specified multiple times" ) ;
256
- }
257
- values_any_specified = true ;
258
- if !args. is_empty ( ) {
259
- error ! ( "`any()` must be empty" ) ;
260
- }
261
- } else {
262
- error ! ( "`values()` arguments must be string literals or `any()`" ) ;
162
+ names. push ( ident) ;
163
+ } else if arg. has_name ( sym:: any)
164
+ && let Some ( args) = arg. meta_item_list ( )
165
+ {
166
+ if any_specified {
167
+ error ! ( "`any()` cannot be specified multiple times" ) ;
168
+ }
169
+ any_specified = true ;
170
+ if !args. is_empty ( ) {
171
+ error ! ( "`any()` must be empty" ) ;
172
+ }
173
+ } else if arg. has_name ( sym:: values)
174
+ && let Some ( args) = arg. meta_item_list ( )
175
+ {
176
+ if names. is_empty ( ) {
177
+ error ! ( "`values()` cannot be specified before the names" ) ;
178
+ } else if values_specified {
179
+ error ! ( "`values()` cannot be specified multiple times" ) ;
180
+ }
181
+ values_specified = true ;
182
+
183
+ for arg in args {
184
+ if let Some ( LitKind :: Str ( s, _) ) = arg. lit ( ) . map ( |lit| & lit. kind ) {
185
+ values. insert ( Some ( * s) ) ;
186
+ } else if arg. has_name ( sym:: any)
187
+ && let Some ( args) = arg. meta_item_list ( )
188
+ {
189
+ if values_any_specified {
190
+ error ! ( "`any()` in `values()` cannot be specified multiple times" ) ;
191
+ }
192
+ values_any_specified = true ;
193
+ if !args. is_empty ( ) {
194
+ error ! ( "`any()` must be empty" ) ;
263
195
}
196
+ } else {
197
+ error ! ( "`values()` arguments must be string literals or `any()`" ) ;
264
198
}
265
- } else {
266
- error ! (
267
- "`cfg()` arguments must be simple identifiers, `any()` or `values(...)`"
268
- ) ;
269
199
}
200
+ } else {
201
+ error ! ( "`cfg()` arguments must be simple identifiers, `any()` or `values(...)`" ) ;
270
202
}
203
+ }
271
204
272
- if values. is_empty ( ) && !values_any_specified && !any_specified {
273
- values. insert ( None ) ;
274
- } else if !values. is_empty ( ) && values_any_specified {
275
- error ! (
276
- "`values()` arguments cannot specify string literals and `any()` at the same time"
277
- ) ;
278
- }
205
+ if values. is_empty ( ) && !values_any_specified && !any_specified {
206
+ values. insert ( None ) ;
207
+ } else if !values. is_empty ( ) && values_any_specified {
208
+ error ! (
209
+ "`values()` arguments cannot specify string literals and `any()` at the same time"
210
+ ) ;
211
+ }
279
212
280
- if any_specified {
281
- if names. is_empty ( )
282
- && values. is_empty ( )
283
- && !values_specified
284
- && !values_any_specified
285
- {
286
- check_cfg. exhaustive_names = false ;
287
- } else {
288
- error ! ( "`cfg(any())` can only be provided in isolation" ) ;
289
- }
213
+ if any_specified {
214
+ if names. is_empty ( ) && values. is_empty ( ) && !values_specified && !values_any_specified {
215
+ check_cfg. exhaustive_names = false ;
290
216
} else {
291
- for name in names {
292
- check_cfg
293
- . expecteds
294
- . entry ( name. name )
295
- . and_modify ( |v| match v {
296
- ExpectedValues :: Some ( v) if !values_any_specified => {
297
- v. extend ( values. clone ( ) )
298
- }
299
- ExpectedValues :: Some ( _) => * v = ExpectedValues :: Any ,
300
- ExpectedValues :: Any => { }
301
- } )
302
- . or_insert_with ( || {
303
- if values_any_specified {
304
- ExpectedValues :: Any
305
- } else {
306
- ExpectedValues :: Some ( values. clone ( ) )
307
- }
308
- } ) ;
309
- }
217
+ error ! ( "`cfg(any())` can only be provided in isolation" ) ;
310
218
}
311
219
} else {
312
- expected_error ( ) ;
220
+ for name in names {
221
+ check_cfg
222
+ . expecteds
223
+ . entry ( name. name )
224
+ . and_modify ( |v| match v {
225
+ ExpectedValues :: Some ( v) if !values_any_specified => {
226
+ v. extend ( values. clone ( ) )
227
+ }
228
+ ExpectedValues :: Some ( _) => * v = ExpectedValues :: Any ,
229
+ ExpectedValues :: Any => { }
230
+ } )
231
+ . or_insert_with ( || {
232
+ if values_any_specified {
233
+ ExpectedValues :: Any
234
+ } else {
235
+ ExpectedValues :: Some ( values. clone ( ) )
236
+ }
237
+ } ) ;
238
+ }
313
239
}
314
240
}
315
241
0 commit comments