Better guard against wrong input with check-cfg any()
This commit is contained in:
parent
1ef96a9e06
commit
84a1a689cc
@ -311,11 +311,15 @@ pub fn parse_check_cfg(handler: &EarlyErrorHandler, specs: Vec<String>) -> Check
|
||||
}
|
||||
|
||||
if any_specified {
|
||||
if !names.is_empty() || !values.is_empty() || values_any_specified {
|
||||
if names.is_empty()
|
||||
&& values.is_empty()
|
||||
&& !values_specified
|
||||
&& !values_any_specified
|
||||
{
|
||||
check_cfg.exhaustive_names = false;
|
||||
} else {
|
||||
error!("`cfg(any())` can only be provided in isolation");
|
||||
}
|
||||
|
||||
check_cfg.exhaustive_names = false;
|
||||
} else {
|
||||
for name in names {
|
||||
check_cfg
|
||||
|
2
tests/ui/check-cfg/invalid-arguments.any_values.stderr
Normal file
2
tests/ui/check-cfg/invalid-arguments.any_values.stderr
Normal file
@ -0,0 +1,2 @@
|
||||
error: invalid `--check-cfg` argument: `cfg(any(),values())` (`values()` cannot be specified before the names)
|
||||
|
@ -6,7 +6,7 @@
|
||||
// revisions: multiple_values_any not_empty_any not_empty_values_any
|
||||
// revisions: values_any_missing_values values_any_before_ident ident_in_values_1
|
||||
// revisions: ident_in_values_2 unknown_meta_item_1 unknown_meta_item_2 unknown_meta_item_3
|
||||
// revisions: mixed_values_any mixed_any giberich
|
||||
// revisions: mixed_values_any mixed_any any_values giberich unterminated
|
||||
//
|
||||
// compile-flags: -Z unstable-options
|
||||
// [anything_else]compile-flags: --check-cfg=anything_else(...)
|
||||
@ -29,6 +29,8 @@
|
||||
// [unknown_meta_item_3]compile-flags: --check-cfg=cfg(foo,values(test()))
|
||||
// [mixed_values_any]compile-flags: --check-cfg=cfg(foo,values("bar",any()))
|
||||
// [mixed_any]compile-flags: --check-cfg=cfg(any(),values(any()))
|
||||
// [any_values]compile-flags: --check-cfg=cfg(any(),values())
|
||||
// [giberich]compile-flags: --check-cfg=cfg(...)
|
||||
// [unterminated]compile-flags: --check-cfg=cfg(
|
||||
|
||||
fn main() {}
|
||||
|
2
tests/ui/check-cfg/invalid-arguments.unterminated.stderr
Normal file
2
tests/ui/check-cfg/invalid-arguments.unterminated.stderr
Normal file
@ -0,0 +1,2 @@
|
||||
error: invalid `--check-cfg` argument: `cfg(` (expected `cfg(name, values("value1", "value2", ... "valueN"))`)
|
||||
|
Loading…
x
Reference in New Issue
Block a user