Skip to content

Commit 84a1a68

Browse files
committed
Better guard against wrong input with check-cfg any()
1 parent 1ef96a9 commit 84a1a68

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed

compiler/rustc_interface/src/interface.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -311,11 +311,15 @@ pub fn parse_check_cfg(handler: &EarlyErrorHandler, specs: Vec<String>) -> Check
311311
}
312312

313313
if any_specified {
314-
if !names.is_empty() || !values.is_empty() || values_any_specified {
314+
if names.is_empty()
315+
&& values.is_empty()
316+
&& !values_specified
317+
&& !values_any_specified
318+
{
319+
check_cfg.exhaustive_names = false;
320+
} else {
315321
error!("`cfg(any())` can only be provided in isolation");
316322
}
317-
318-
check_cfg.exhaustive_names = false;
319323
} else {
320324
for name in names {
321325
check_cfg
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
error: invalid `--check-cfg` argument: `cfg(any(),values())` (`values()` cannot be specified before the names)
2+

tests/ui/check-cfg/invalid-arguments.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// revisions: multiple_values_any not_empty_any not_empty_values_any
77
// revisions: values_any_missing_values values_any_before_ident ident_in_values_1
88
// revisions: ident_in_values_2 unknown_meta_item_1 unknown_meta_item_2 unknown_meta_item_3
9-
// revisions: mixed_values_any mixed_any giberich
9+
// revisions: mixed_values_any mixed_any any_values giberich unterminated
1010
//
1111
// compile-flags: -Z unstable-options
1212
// [anything_else]compile-flags: --check-cfg=anything_else(...)
@@ -29,6 +29,8 @@
2929
// [unknown_meta_item_3]compile-flags: --check-cfg=cfg(foo,values(test()))
3030
// [mixed_values_any]compile-flags: --check-cfg=cfg(foo,values("bar",any()))
3131
// [mixed_any]compile-flags: --check-cfg=cfg(any(),values(any()))
32+
// [any_values]compile-flags: --check-cfg=cfg(any(),values())
3233
// [giberich]compile-flags: --check-cfg=cfg(...)
34+
// [unterminated]compile-flags: --check-cfg=cfg(
3335

3436
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
error: invalid `--check-cfg` argument: `cfg(` (expected `cfg(name, values("value1", "value2", ... "valueN"))`)
2+

0 commit comments

Comments
 (0)