Skip to content

Commit e2122e7

Browse files
committed
Better guard against wrong input with check-cfg any()
1 parent 351ca15 commit e2122e7

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
@@ -324,11 +324,15 @@ pub fn parse_check_cfg(handler: &EarlyErrorHandler, specs: Vec<String>) -> Check
324324
}
325325

326326
if any_specified {
327-
if !names.is_empty() || !values.is_empty() || values_any_specified {
327+
if names.is_empty()
328+
&& values.is_empty()
329+
&& !values_specified
330+
&& !values_any_specified
331+
{
332+
check_cfg.exhaustive_names = false;
333+
} else {
328334
error!("`cfg(any())` can only be provided in isolation");
329335
}
330-
331-
check_cfg.exhaustive_names = false;
332336
} else {
333337
for name in names {
334338
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)