Skip to content

Commit b59a383

Browse files
committed
Remove deprecated --check-cfg names() and values() syntax
1 parent 78efca8 commit b59a383

39 files changed

+171
-657
lines changed

compiler/rustc_interface/src/interface.rs

Lines changed: 83 additions & 157 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ use rustc_data_structures::sync::Lrc;
1010
use rustc_errors::registry::Registry;
1111
use rustc_errors::{ErrorGuaranteed, Handler};
1212
use rustc_lint::LintStore;
13+
use rustc_middle::ty;
1314
use rustc_middle::util::Providers;
14-
use rustc_middle::{bug, ty};
1515
use rustc_parse::maybe_new_parser_from_source_str;
1616
use rustc_query_impl::QueryCtxt;
1717
use rustc_query_system::query::print_query_stack;
@@ -122,7 +122,6 @@ pub(crate) fn parse_check_cfg(handler: &EarlyErrorHandler, specs: Vec<String>) -
122122
let exhaustive_values = !specs.is_empty();
123123
let mut check_cfg = CheckCfg { exhaustive_names, exhaustive_values, ..CheckCfg::default() };
124124

125-
let mut old_syntax = None;
126125
for s in specs {
127126
let sess = ParseSess::with_silent_emitter(Some(format!(
128127
"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>) -
160159
expected_error();
161160
};
162161

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+
}
204165

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();
208168

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;
216172

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");
222179
}
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");
281213
}
214+
} else {
215+
error!("`values()` arguments must be string literals or `any()`");
282216
}
283-
} else {
284-
error!(
285-
"`cfg()` arguments must be simple identifiers, `any()` or `values(...)`"
286-
);
287217
}
218+
} else {
219+
error!("`cfg()` arguments must be simple identifiers, `any()` or `values(...)`");
288220
}
221+
}
289222

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+
}
297230

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;
308234
} 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");
328236
}
329237
} 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+
}
331257
}
332258
}
333259

src/doc/unstable-book/src/compiler-flags/check-cfg.md

Lines changed: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -187,70 +187,3 @@ fn shoot_lasers() {}
187187
// the cfg(feature) list
188188
fn write_shakespeare() {}
189189
```
190-
191-
## The deprecated `names(...)` form
192-
193-
The `names(...)` form enables checking the names. This form uses a named list:
194-
195-
```bash
196-
rustc --check-cfg 'names(name1, name2, ... nameN)'
197-
```
198-
199-
where each `name` is a bare identifier (has no quotes). The order of the names is not significant.
200-
201-
If `--check-cfg names(...)` is specified at least once, then `rustc` will check all references to
202-
condition names. `rustc` will check every `#[cfg]` attribute, `#[cfg_attr]` attribute, `cfg` clause
203-
inside `#[link]` attribute and `cfg!(...)` call against the provided list of expected condition
204-
names. If a name is not present in this list, then `rustc` will report an `unexpected_cfgs` lint
205-
diagnostic. The default diagnostic level for this lint is `Warn`.
206-
207-
If `--check-cfg names(...)` is not specified, then `rustc` will not check references to condition
208-
names.
209-
210-
`--check-cfg names(...)` may be specified more than once. The result is that the list of valid
211-
condition names is merged across all options. It is legal for a condition name to be specified
212-
more than once; redundantly specifying a condition name has no effect.
213-
214-
To enable checking condition names with an empty set of valid condition names, use the following
215-
form. The parentheses are required.
216-
217-
```bash
218-
rustc --check-cfg 'names()'
219-
```
220-
221-
Note that `--check-cfg 'names()'` is _not_ equivalent to omitting the option entirely.
222-
The first form enables checking condition names, while specifying that there are no valid
223-
condition names (outside of the set of well-known names defined by `rustc`). Omitting the
224-
`--check-cfg 'names(...)'` option does not enable checking condition names.
225-
226-
## The deprecated `values(...)` form
227-
228-
The `values(...)` form enables checking the values within list-valued conditions. It has this
229-
form:
230-
231-
```bash
232-
rustc --check-cfg `values(name, "value1", "value2", ... "valueN")'
233-
```
234-
235-
where `name` is a bare identifier (has no quotes) and each `"value"` term is a quoted literal
236-
string. `name` specifies the name of the condition, such as `feature` or `target_os`.
237-
238-
When the `values(...)` option is specified, `rustc` will check every `#[cfg(name = "value")]`
239-
attribute, `#[cfg_attr(name = "value")]` attribute, `#[link(name = "a", cfg(name = "value"))]`
240-
and `cfg!(name = "value")` call. It will check that the `"value"` specified is present in the
241-
list of expected values. If `"value"` is not in it, then `rustc` will report an `unexpected_cfgs`
242-
lint diagnostic. The default diagnostic level for this lint is `Warn`.
243-
244-
To enable checking of values, but to provide an empty set of valid values, use this form:
245-
246-
```bash
247-
rustc --check-cfg `values(name)`
248-
```
249-
250-
The `--check-cfg values(...)` option can be repeated, both for the same condition name and for
251-
different names. If it is repeated for the same condition name, then the sets of values for that
252-
condition are merged together.
253-
254-
If `values()` is specified, then `rustc` will enable the checking of well-known values defined
255-
by itself. Note that it's necessary to specify the `values()` form to enable the checking of
256-
well known values, specifying the other forms doesn't implicitly enable it.

tests/ui/check-cfg/exhaustive-names-values.empty_cfg.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
warning: unexpected `cfg` condition name: `unknown_key`
2-
--> $DIR/exhaustive-names-values.rs:12:7
2+
--> $DIR/exhaustive-names-values.rs:11:7
33
|
44
LL | #[cfg(unknown_key = "value")]
55
| ^^^^^^^^^^^^^^^^^^^^^
@@ -8,7 +8,7 @@ LL | #[cfg(unknown_key = "value")]
88
= note: `#[warn(unexpected_cfgs)]` on by default
99

1010
warning: unexpected `cfg` condition value: `value`
11-
--> $DIR/exhaustive-names-values.rs:16:7
11+
--> $DIR/exhaustive-names-values.rs:15:7
1212
|
1313
LL | #[cfg(test = "value")]
1414
| ^^^^----------

tests/ui/check-cfg/exhaustive-names-values.empty_names_values.stderr

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)