@@ -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;
@@ -122,7 +122,6 @@ pub(crate) fn parse_check_cfg(handler: &EarlyErrorHandler, specs: Vec<String>) -
122
122
let exhaustive_values = !specs. is_empty ( ) ;
123
123
let mut check_cfg = CheckCfg { exhaustive_names, exhaustive_values, ..CheckCfg :: default ( ) } ;
124
124
125
- let mut old_syntax = None ;
126
125
for s in specs {
127
126
let sess = ParseSess :: with_silent_emitter ( Some ( format ! (
128
127
"this error occurred on the command line: `--check-cfg={s}`"
@@ -160,174 +159,101 @@ pub(crate) fn parse_check_cfg(handler: &EarlyErrorHandler, specs: Vec<String>) -
160
159
expected_error ( ) ;
161
160
} ;
162
161
163
- let mut set_old_syntax = || {
164
- // defaults are flipped for the old syntax
165
- if old_syntax == None {
166
- check_cfg. exhaustive_names = false ;
167
- check_cfg. exhaustive_values = false ;
168
- }
169
- old_syntax = Some ( true ) ;
170
- } ;
171
-
172
- if meta_item. has_name ( sym:: names) {
173
- set_old_syntax ( ) ;
174
-
175
- check_cfg. exhaustive_names = true ;
176
- for arg in args {
177
- if arg. is_word ( )
178
- && let Some ( ident) = arg. ident ( )
179
- {
180
- check_cfg. expecteds . entry ( ident. name ) . or_insert ( ExpectedValues :: Any ) ;
181
- } else {
182
- error ! ( "`names()` arguments must be simple identifiers" ) ;
183
- }
184
- }
185
- } else if meta_item. has_name ( sym:: values) {
186
- set_old_syntax ( ) ;
187
-
188
- if let Some ( ( name, values) ) = args. split_first ( ) {
189
- if name. is_word ( )
190
- && let Some ( ident) = name. ident ( )
191
- {
192
- let expected_values = check_cfg
193
- . expecteds
194
- . entry ( ident. name )
195
- . and_modify ( |expected_values| match expected_values {
196
- ExpectedValues :: Some ( _) => { }
197
- ExpectedValues :: Any => {
198
- // handle the case where names(...) was done
199
- // before values by changing to a list
200
- * expected_values = ExpectedValues :: Some ( FxHashSet :: default ( ) ) ;
201
- }
202
- } )
203
- . or_insert_with ( || ExpectedValues :: Some ( FxHashSet :: default ( ) ) ) ;
162
+ if !meta_item. has_name ( sym:: cfg) {
163
+ expected_error ( ) ;
164
+ }
204
165
205
- let ExpectedValues :: Some ( expected_values) = expected_values else {
206
- bug ! ( "`expected_values` should be a list a values" )
207
- } ;
166
+ let mut names = Vec :: new ( ) ;
167
+ let mut values: FxHashSet < _ > = Default :: default ( ) ;
208
168
209
- for val in values {
210
- if let Some ( LitKind :: Str ( s, _) ) = val. lit ( ) . map ( |lit| & lit. kind ) {
211
- expected_values. insert ( Some ( * s) ) ;
212
- } else {
213
- error ! ( "`values()` arguments must be string literals" ) ;
214
- }
215
- }
169
+ let mut any_specified = false ;
170
+ let mut values_specified = false ;
171
+ let mut values_any_specified = false ;
216
172
217
- if values. is_empty ( ) {
218
- expected_values. insert ( None ) ;
219
- }
220
- } else {
221
- error ! ( "`values()` first argument must be a simple identifier" ) ;
173
+ for arg in args {
174
+ if arg. is_word ( )
175
+ && let Some ( ident) = arg. ident ( )
176
+ {
177
+ if values_specified {
178
+ error ! ( "`cfg()` names cannot be after values" ) ;
222
179
}
223
- } else if args. is_empty ( ) {
224
- check_cfg. exhaustive_values = true ;
225
- } else {
226
- expected_error ( ) ;
227
- }
228
- } else if meta_item. has_name ( sym:: cfg) {
229
- old_syntax = Some ( false ) ;
230
-
231
- let mut names = Vec :: new ( ) ;
232
- let mut values: FxHashSet < _ > = Default :: default ( ) ;
233
-
234
- let mut any_specified = false ;
235
- let mut values_specified = false ;
236
- let mut values_any_specified = false ;
237
-
238
- for arg in args {
239
- if arg. is_word ( )
240
- && let Some ( ident) = arg. ident ( )
241
- {
242
- if values_specified {
243
- error ! ( "`cfg()` names cannot be after values" ) ;
244
- }
245
- names. push ( ident) ;
246
- } else if arg. has_name ( sym:: any)
247
- && let Some ( args) = arg. meta_item_list ( )
248
- {
249
- if any_specified {
250
- error ! ( "`any()` cannot be specified multiple times" ) ;
251
- }
252
- any_specified = true ;
253
- if !args. is_empty ( ) {
254
- error ! ( "`any()` must be empty" ) ;
255
- }
256
- } else if arg. has_name ( sym:: values)
257
- && let Some ( args) = arg. meta_item_list ( )
258
- {
259
- if names. is_empty ( ) {
260
- error ! ( "`values()` cannot be specified before the names" ) ;
261
- } else if values_specified {
262
- error ! ( "`values()` cannot be specified multiple times" ) ;
263
- }
264
- values_specified = true ;
265
-
266
- for arg in args {
267
- if let Some ( LitKind :: Str ( s, _) ) = arg. lit ( ) . map ( |lit| & lit. kind ) {
268
- values. insert ( Some ( * s) ) ;
269
- } else if arg. has_name ( sym:: any)
270
- && let Some ( args) = arg. meta_item_list ( )
271
- {
272
- if values_any_specified {
273
- error ! ( "`any()` in `values()` cannot be specified multiple times" ) ;
274
- }
275
- values_any_specified = true ;
276
- if !args. is_empty ( ) {
277
- error ! ( "`any()` must be empty" ) ;
278
- }
279
- } else {
280
- error ! ( "`values()` arguments must be string literals or `any()`" ) ;
180
+ names. push ( ident) ;
181
+ } else if arg. has_name ( sym:: any)
182
+ && let Some ( args) = arg. meta_item_list ( )
183
+ {
184
+ if any_specified {
185
+ error ! ( "`any()` cannot be specified multiple times" ) ;
186
+ }
187
+ any_specified = true ;
188
+ if !args. is_empty ( ) {
189
+ error ! ( "`any()` must be empty" ) ;
190
+ }
191
+ } else if arg. has_name ( sym:: values)
192
+ && let Some ( args) = arg. meta_item_list ( )
193
+ {
194
+ if names. is_empty ( ) {
195
+ error ! ( "`values()` cannot be specified before the names" ) ;
196
+ } else if values_specified {
197
+ error ! ( "`values()` cannot be specified multiple times" ) ;
198
+ }
199
+ values_specified = true ;
200
+
201
+ for arg in args {
202
+ if let Some ( LitKind :: Str ( s, _) ) = arg. lit ( ) . map ( |lit| & lit. kind ) {
203
+ values. insert ( Some ( * s) ) ;
204
+ } else if arg. has_name ( sym:: any)
205
+ && let Some ( args) = arg. meta_item_list ( )
206
+ {
207
+ if values_any_specified {
208
+ error ! ( "`any()` in `values()` cannot be specified multiple times" ) ;
209
+ }
210
+ values_any_specified = true ;
211
+ if !args. is_empty ( ) {
212
+ error ! ( "`any()` must be empty" ) ;
281
213
}
214
+ } else {
215
+ error ! ( "`values()` arguments must be string literals or `any()`" ) ;
282
216
}
283
- } else {
284
- error ! (
285
- "`cfg()` arguments must be simple identifiers, `any()` or `values(...)`"
286
- ) ;
287
217
}
218
+ } else {
219
+ error ! ( "`cfg()` arguments must be simple identifiers, `any()` or `values(...)`" ) ;
288
220
}
221
+ }
289
222
290
- if values. is_empty ( ) && !values_any_specified && !any_specified {
291
- values. insert ( None ) ;
292
- } else if !values. is_empty ( ) && values_any_specified {
293
- error ! (
294
- "`values()` arguments cannot specify string literals and `any()` at the same time"
295
- ) ;
296
- }
223
+ if values. is_empty ( ) && !values_any_specified && !any_specified {
224
+ values. insert ( None ) ;
225
+ } else if !values. is_empty ( ) && values_any_specified {
226
+ error ! (
227
+ "`values()` arguments cannot specify string literals and `any()` at the same time"
228
+ ) ;
229
+ }
297
230
298
- if any_specified {
299
- if names. is_empty ( )
300
- && values. is_empty ( )
301
- && !values_specified
302
- && !values_any_specified
303
- {
304
- check_cfg. exhaustive_names = false ;
305
- } else {
306
- error ! ( "`cfg(any())` can only be provided in isolation" ) ;
307
- }
231
+ if any_specified {
232
+ if names. is_empty ( ) && values. is_empty ( ) && !values_specified && !values_any_specified {
233
+ check_cfg. exhaustive_names = false ;
308
234
} else {
309
- for name in names {
310
- check_cfg
311
- . expecteds
312
- . entry ( name. name )
313
- . and_modify ( |v| match v {
314
- ExpectedValues :: Some ( v) if !values_any_specified => {
315
- v. extend ( values. clone ( ) )
316
- }
317
- ExpectedValues :: Some ( _) => * v = ExpectedValues :: Any ,
318
- ExpectedValues :: Any => { }
319
- } )
320
- . or_insert_with ( || {
321
- if values_any_specified {
322
- ExpectedValues :: Any
323
- } else {
324
- ExpectedValues :: Some ( values. clone ( ) )
325
- }
326
- } ) ;
327
- }
235
+ error ! ( "`cfg(any())` can only be provided in isolation" ) ;
328
236
}
329
237
} else {
330
- expected_error ( ) ;
238
+ for name in names {
239
+ check_cfg
240
+ . expecteds
241
+ . entry ( name. name )
242
+ . and_modify ( |v| match v {
243
+ ExpectedValues :: Some ( v) if !values_any_specified => {
244
+ v. extend ( values. clone ( ) )
245
+ }
246
+ ExpectedValues :: Some ( _) => * v = ExpectedValues :: Any ,
247
+ ExpectedValues :: Any => { }
248
+ } )
249
+ . or_insert_with ( || {
250
+ if values_any_specified {
251
+ ExpectedValues :: Any
252
+ } else {
253
+ ExpectedValues :: Some ( values. clone ( ) )
254
+ }
255
+ } ) ;
256
+ }
331
257
}
332
258
}
333
259
0 commit comments