@@ -10,8 +10,8 @@ use rustc_data_structures::sync::Lrc;
1010use rustc_errors:: registry:: Registry ;
1111use rustc_errors:: { ErrorGuaranteed , Handler } ;
1212use rustc_lint:: LintStore ;
13+ use rustc_middle:: ty;
1314use rustc_middle:: util:: Providers ;
14- use rustc_middle:: { bug, ty} ;
1515use rustc_parse:: maybe_new_parser_from_source_str;
1616use rustc_query_impl:: QueryCtxt ;
1717use rustc_query_system:: query:: print_query_stack;
@@ -126,7 +126,6 @@ pub(crate) fn parse_check_cfg(handler: &EarlyErrorHandler, specs: Vec<String>) -
126126 let exhaustive_values = !specs. is_empty ( ) ;
127127 let mut check_cfg = CheckCfg { exhaustive_names, exhaustive_values, ..CheckCfg :: default ( ) } ;
128128
129- let mut old_syntax = None ;
130129 for s in specs {
131130 let sess = ParseSess :: with_silent_emitter ( Some ( format ! (
132131 "this error occurred on the command line: `--check-cfg={s}`"
@@ -164,174 +163,101 @@ pub(crate) fn parse_check_cfg(handler: &EarlyErrorHandler, specs: Vec<String>) -
164163 expected_error ( ) ;
165164 } ;
166165
167- let mut set_old_syntax = || {
168- // defaults are flipped for the old syntax
169- if old_syntax == None {
170- check_cfg. exhaustive_names = false ;
171- check_cfg. exhaustive_values = false ;
172- }
173- old_syntax = Some ( true ) ;
174- } ;
175-
176- if meta_item. has_name ( sym:: names) {
177- set_old_syntax ( ) ;
178-
179- check_cfg. exhaustive_names = true ;
180- for arg in args {
181- if arg. is_word ( )
182- && let Some ( ident) = arg. ident ( )
183- {
184- check_cfg. expecteds . entry ( ident. name ) . or_insert ( ExpectedValues :: Any ) ;
185- } else {
186- error ! ( "`names()` arguments must be simple identifiers" ) ;
187- }
188- }
189- } else if meta_item. has_name ( sym:: values) {
190- set_old_syntax ( ) ;
191-
192- if let Some ( ( name, values) ) = args. split_first ( ) {
193- if name. is_word ( )
194- && let Some ( ident) = name. ident ( )
195- {
196- let expected_values = check_cfg
197- . expecteds
198- . entry ( ident. name )
199- . and_modify ( |expected_values| match expected_values {
200- ExpectedValues :: Some ( _) => { }
201- ExpectedValues :: Any => {
202- // handle the case where names(...) was done
203- // before values by changing to a list
204- * expected_values = ExpectedValues :: Some ( FxHashSet :: default ( ) ) ;
205- }
206- } )
207- . or_insert_with ( || ExpectedValues :: Some ( FxHashSet :: default ( ) ) ) ;
166+ if !meta_item. has_name ( sym:: cfg) {
167+ expected_error ( ) ;
168+ }
208169
209- let ExpectedValues :: Some ( expected_values) = expected_values else {
210- bug ! ( "`expected_values` should be a list a values" )
211- } ;
170+ let mut names = Vec :: new ( ) ;
171+ let mut values: FxHashSet < _ > = Default :: default ( ) ;
212172
213- for val in values {
214- if let Some ( LitKind :: Str ( s, _) ) = val. lit ( ) . map ( |lit| & lit. kind ) {
215- expected_values. insert ( Some ( * s) ) ;
216- } else {
217- error ! ( "`values()` arguments must be string literals" ) ;
218- }
219- }
173+ let mut any_specified = false ;
174+ let mut values_specified = false ;
175+ let mut values_any_specified = false ;
220176
221- if values. is_empty ( ) {
222- expected_values. insert ( None ) ;
223- }
224- } else {
225- error ! ( "`values()` first argument must be a simple identifier" ) ;
177+ for arg in args {
178+ if arg. is_word ( )
179+ && let Some ( ident) = arg. ident ( )
180+ {
181+ if values_specified {
182+ error ! ( "`cfg()` names cannot be after values" ) ;
226183 }
227- } else if args. is_empty ( ) {
228- check_cfg. exhaustive_values = true ;
229- } else {
230- expected_error ( ) ;
231- }
232- } else if meta_item. has_name ( sym:: cfg) {
233- old_syntax = Some ( false ) ;
234-
235- let mut names = Vec :: new ( ) ;
236- let mut values: FxHashSet < _ > = Default :: default ( ) ;
237-
238- let mut any_specified = false ;
239- let mut values_specified = false ;
240- let mut values_any_specified = false ;
241-
242- for arg in args {
243- if arg. is_word ( )
244- && let Some ( ident) = arg. ident ( )
245- {
246- if values_specified {
247- error ! ( "`cfg()` names cannot be after values" ) ;
248- }
249- names. push ( ident) ;
250- } else if arg. has_name ( sym:: any)
251- && let Some ( args) = arg. meta_item_list ( )
252- {
253- if any_specified {
254- error ! ( "`any()` cannot be specified multiple times" ) ;
255- }
256- any_specified = true ;
257- if !args. is_empty ( ) {
258- error ! ( "`any()` must be empty" ) ;
259- }
260- } else if arg. has_name ( sym:: values)
261- && let Some ( args) = arg. meta_item_list ( )
262- {
263- if names. is_empty ( ) {
264- error ! ( "`values()` cannot be specified before the names" ) ;
265- } else if values_specified {
266- error ! ( "`values()` cannot be specified multiple times" ) ;
267- }
268- values_specified = true ;
269-
270- for arg in args {
271- if let Some ( LitKind :: Str ( s, _) ) = arg. lit ( ) . map ( |lit| & lit. kind ) {
272- values. insert ( Some ( * s) ) ;
273- } else if arg. has_name ( sym:: any)
274- && let Some ( args) = arg. meta_item_list ( )
275- {
276- if values_any_specified {
277- error ! ( "`any()` in `values()` cannot be specified multiple times" ) ;
278- }
279- values_any_specified = true ;
280- if !args. is_empty ( ) {
281- error ! ( "`any()` must be empty" ) ;
282- }
283- } else {
284- error ! ( "`values()` arguments must be string literals or `any()`" ) ;
184+ names. push ( ident) ;
185+ } else if arg. has_name ( sym:: any)
186+ && let Some ( args) = arg. meta_item_list ( )
187+ {
188+ if any_specified {
189+ error ! ( "`any()` cannot be specified multiple times" ) ;
190+ }
191+ any_specified = true ;
192+ if !args. is_empty ( ) {
193+ error ! ( "`any()` must be empty" ) ;
194+ }
195+ } else if arg. has_name ( sym:: values)
196+ && let Some ( args) = arg. meta_item_list ( )
197+ {
198+ if names. is_empty ( ) {
199+ error ! ( "`values()` cannot be specified before the names" ) ;
200+ } else if values_specified {
201+ error ! ( "`values()` cannot be specified multiple times" ) ;
202+ }
203+ values_specified = true ;
204+
205+ for arg in args {
206+ if let Some ( LitKind :: Str ( s, _) ) = arg. lit ( ) . map ( |lit| & lit. kind ) {
207+ values. insert ( Some ( * s) ) ;
208+ } else if arg. has_name ( sym:: any)
209+ && let Some ( args) = arg. meta_item_list ( )
210+ {
211+ if values_any_specified {
212+ error ! ( "`any()` in `values()` cannot be specified multiple times" ) ;
213+ }
214+ values_any_specified = true ;
215+ if !args. is_empty ( ) {
216+ error ! ( "`any()` must be empty" ) ;
285217 }
218+ } else {
219+ error ! ( "`values()` arguments must be string literals or `any()`" ) ;
286220 }
287- } else {
288- error ! (
289- "`cfg()` arguments must be simple identifiers, `any()` or `values(...)`"
290- ) ;
291221 }
222+ } else {
223+ error ! ( "`cfg()` arguments must be simple identifiers, `any()` or `values(...)`" ) ;
292224 }
225+ }
293226
294- if values. is_empty ( ) && !values_any_specified && !any_specified {
295- values. insert ( None ) ;
296- } else if !values. is_empty ( ) && values_any_specified {
297- error ! (
298- "`values()` arguments cannot specify string literals and `any()` at the same time"
299- ) ;
300- }
227+ if values. is_empty ( ) && !values_any_specified && !any_specified {
228+ values. insert ( None ) ;
229+ } else if !values. is_empty ( ) && values_any_specified {
230+ error ! (
231+ "`values()` arguments cannot specify string literals and `any()` at the same time"
232+ ) ;
233+ }
301234
302- if any_specified {
303- if names. is_empty ( )
304- && values. is_empty ( )
305- && !values_specified
306- && !values_any_specified
307- {
308- check_cfg. exhaustive_names = false ;
309- } else {
310- error ! ( "`cfg(any())` can only be provided in isolation" ) ;
311- }
235+ if any_specified {
236+ if names. is_empty ( ) && values. is_empty ( ) && !values_specified && !values_any_specified {
237+ check_cfg. exhaustive_names = false ;
312238 } else {
313- for name in names {
314- check_cfg
315- . expecteds
316- . entry ( name. name )
317- . and_modify ( |v| match v {
318- ExpectedValues :: Some ( v) if !values_any_specified => {
319- v. extend ( values. clone ( ) )
320- }
321- ExpectedValues :: Some ( _) => * v = ExpectedValues :: Any ,
322- ExpectedValues :: Any => { }
323- } )
324- . or_insert_with ( || {
325- if values_any_specified {
326- ExpectedValues :: Any
327- } else {
328- ExpectedValues :: Some ( values. clone ( ) )
329- }
330- } ) ;
331- }
239+ error ! ( "`cfg(any())` can only be provided in isolation" ) ;
332240 }
333241 } else {
334- expected_error ( ) ;
242+ for name in names {
243+ check_cfg
244+ . expecteds
245+ . entry ( name. name )
246+ . and_modify ( |v| match v {
247+ ExpectedValues :: Some ( v) if !values_any_specified => {
248+ v. extend ( values. clone ( ) )
249+ }
250+ ExpectedValues :: Some ( _) => * v = ExpectedValues :: Any ,
251+ ExpectedValues :: Any => { }
252+ } )
253+ . or_insert_with ( || {
254+ if values_any_specified {
255+ ExpectedValues :: Any
256+ } else {
257+ ExpectedValues :: Some ( values. clone ( ) )
258+ }
259+ } ) ;
260+ }
335261 }
336262 }
337263
0 commit comments