chore: use let-else 🤯

This commit is contained in:
rvcas 2023-03-17 17:50:41 -04:00
parent a4c7337df2
commit d753b57c1b
No known key found for this signature in database
GPG Key ID: C09B64E263F7D68C
1 changed files with 65 additions and 67 deletions

View File

@ -262,14 +262,17 @@ fn infer_definition(
let temp_params = params.iter().cloned().chain(fun.arguments); let temp_params = params.iter().cloned().chain(fun.arguments);
fun.arguments = temp_params.collect(); fun.arguments = temp_params.collect();
if let Definition::Fn(mut typed_fun) = infer_definition( let Definition::Fn(mut typed_fun) = infer_definition(
Definition::Fn(fun), Definition::Fn(fun),
module_name, module_name,
hydrators, hydrators,
environment, environment,
tracing, tracing,
kind, kind,
)? { )? else {
unreachable!("validator definition inferred as something other than a function?")
};
if !typed_fun.return_type.is_bool() { if !typed_fun.return_type.is_bool() {
return Err(Error::ValidatorMustReturnBool { return Err(Error::ValidatorMustReturnBool {
return_type: typed_fun.return_type.clone(), return_type: typed_fun.return_type.clone(),
@ -291,14 +294,19 @@ fn infer_definition(
let params = params.into_iter().chain(other.arguments); let params = params.into_iter().chain(other.arguments);
other.arguments = params.collect(); other.arguments = params.collect();
if let Definition::Fn(mut other_typed_fun) = infer_definition( let Definition::Fn(mut other_typed_fun) = infer_definition(
Definition::Fn(other), Definition::Fn(other),
module_name, module_name,
hydrators, hydrators,
environment, environment,
tracing, tracing,
kind, kind,
)? { )? else {
unreachable!(
"validator definition inferred as something other than a function?"
)
};
if !other_typed_fun.return_type.is_bool() { if !other_typed_fun.return_type.is_bool() {
return Err(Error::ValidatorMustReturnBool { return Err(Error::ValidatorMustReturnBool {
return_type: other_typed_fun.return_type.clone(), return_type: other_typed_fun.return_type.clone(),
@ -308,9 +316,7 @@ fn infer_definition(
other_typed_fun.arguments.drain(0..params_length); other_typed_fun.arguments.drain(0..params_length);
if other_typed_fun.arguments.len() < 2 if other_typed_fun.arguments.len() < 2 || other_typed_fun.arguments.len() > 3 {
|| other_typed_fun.arguments.len() > 3
{
return Err(Error::IncorrectValidatorArity { return Err(Error::IncorrectValidatorArity {
count: other_typed_fun.arguments.len() as u32, count: other_typed_fun.arguments.len() as u32,
location: other_typed_fun.location, location: other_typed_fun.location,
@ -318,11 +324,6 @@ fn infer_definition(
} }
Ok(other_typed_fun) Ok(other_typed_fun)
} else {
unreachable!(
"validator definition inferred as something other than a function?"
)
}
}) })
.transpose(); .transpose();
@ -334,9 +335,6 @@ fn infer_definition(
location, location,
params: typed_params, params: typed_params,
})) }))
} else {
unreachable!("validator definition inferred as something other than a function?")
}
} }
Definition::Test(f) => { Definition::Test(f) => {