Remove most indentation in check-cfg impl
This commit is contained in:
parent
c716f180e8
commit
828f069c12
1 changed files with 189 additions and 208 deletions
|
@ -147,13 +147,28 @@ pub fn parse_check_cfg(handler: &EarlyErrorHandler, specs: Vec<String>) -> Check
|
|||
};
|
||||
}
|
||||
|
||||
let expected_error =
|
||||
|| error!("expected `cfg(name, values(\"value1\", \"value2\", ... \"valueN\"))`");
|
||||
let expected_error = || -> ! {
|
||||
error!("expected `cfg(name, values(\"value1\", \"value2\", ... \"valueN\"))`")
|
||||
};
|
||||
|
||||
let Ok(mut parser) = maybe_new_parser_from_source_str(&sess, filename, s.to_string())
|
||||
else {
|
||||
expected_error();
|
||||
};
|
||||
|
||||
let meta_item = match parser.parse_meta_item() {
|
||||
Ok(meta_item) if parser.token == token::Eof => meta_item,
|
||||
Ok(..) => expected_error(),
|
||||
Err(err) => {
|
||||
err.cancel();
|
||||
expected_error();
|
||||
}
|
||||
};
|
||||
|
||||
let Some(args) = meta_item.meta_item_list() else {
|
||||
expected_error();
|
||||
};
|
||||
|
||||
match maybe_new_parser_from_source_str(&sess, filename, s.to_string()) {
|
||||
Ok(mut parser) => match parser.parse_meta_item() {
|
||||
Ok(meta_item) if parser.token == token::Eof => {
|
||||
if let Some(args) = meta_item.meta_item_list() {
|
||||
if meta_item.has_name(sym::names) {
|
||||
// defaults are flipped for the old syntax
|
||||
if old_syntax == None {
|
||||
|
@ -193,28 +208,20 @@ pub fn parse_check_cfg(handler: &EarlyErrorHandler, specs: Vec<String>) -> Check
|
|||
ExpectedValues::Any => {
|
||||
// handle the case where names(...) was done
|
||||
// before values by changing to a list
|
||||
*expected_values =
|
||||
ExpectedValues::Some(FxHashSet::default());
|
||||
*expected_values = ExpectedValues::Some(FxHashSet::default());
|
||||
}
|
||||
})
|
||||
.or_insert_with(|| {
|
||||
ExpectedValues::Some(FxHashSet::default())
|
||||
});
|
||||
.or_insert_with(|| ExpectedValues::Some(FxHashSet::default()));
|
||||
|
||||
let ExpectedValues::Some(expected_values) = expected_values
|
||||
else {
|
||||
let ExpectedValues::Some(expected_values) = expected_values else {
|
||||
bug!("`expected_values` should be a list a values")
|
||||
};
|
||||
|
||||
for val in values {
|
||||
if let Some(LitKind::Str(s, _)) =
|
||||
val.lit().map(|lit| &lit.kind)
|
||||
{
|
||||
if let Some(LitKind::Str(s, _)) = val.lit().map(|lit| &lit.kind) {
|
||||
expected_values.insert(Some(s.to_string()));
|
||||
} else {
|
||||
error!(
|
||||
"`values()` arguments must be string literals"
|
||||
);
|
||||
error!("`values()` arguments must be string literals");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -222,9 +229,7 @@ pub fn parse_check_cfg(handler: &EarlyErrorHandler, specs: Vec<String>) -> Check
|
|||
expected_values.insert(None);
|
||||
}
|
||||
} else {
|
||||
error!(
|
||||
"`values()` first argument must be a simple identifier"
|
||||
);
|
||||
error!("`values()` first argument must be a simple identifier");
|
||||
}
|
||||
} else if args.is_empty() {
|
||||
check_cfg.exhaustive_values = true;
|
||||
|
@ -261,13 +266,9 @@ pub fn parse_check_cfg(handler: &EarlyErrorHandler, specs: Vec<String>) -> Check
|
|||
&& let Some(args) = arg.meta_item_list()
|
||||
{
|
||||
if names.is_empty() {
|
||||
error!(
|
||||
"`values()` cannot be specified before the names"
|
||||
);
|
||||
error!("`values()` cannot be specified before the names");
|
||||
} else if values_specified {
|
||||
error!(
|
||||
"`values()` cannot be specified multiple times"
|
||||
);
|
||||
error!("`values()` cannot be specified multiple times");
|
||||
}
|
||||
values_specified = true;
|
||||
|
||||
|
@ -310,10 +311,7 @@ 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_any_specified {
|
||||
error!("`cfg(any())` can only be provided in isolation");
|
||||
}
|
||||
|
||||
|
@ -324,9 +322,7 @@ pub fn parse_check_cfg(handler: &EarlyErrorHandler, specs: Vec<String>) -> Check
|
|||
.expecteds
|
||||
.entry(name.to_string())
|
||||
.and_modify(|v| match v {
|
||||
ExpectedValues::Some(v)
|
||||
if !values_any_specified =>
|
||||
{
|
||||
ExpectedValues::Some(v) if !values_any_specified => {
|
||||
v.extend(values.clone())
|
||||
}
|
||||
ExpectedValues::Some(_) => *v = ExpectedValues::Any,
|
||||
|
@ -344,21 +340,6 @@ pub fn parse_check_cfg(handler: &EarlyErrorHandler, specs: Vec<String>) -> Check
|
|||
} else {
|
||||
expected_error();
|
||||
}
|
||||
} else {
|
||||
expected_error();
|
||||
}
|
||||
}
|
||||
Ok(..) => expected_error(),
|
||||
Err(err) => {
|
||||
err.cancel();
|
||||
expected_error();
|
||||
}
|
||||
},
|
||||
Err(errs) => {
|
||||
drop(errs);
|
||||
expected_error();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
check_cfg
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue