From f4cb91c7ddf4fb64143967c3ae1599ee5f88ae62 Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Tue, 1 Nov 2022 21:23:46 +0900 Subject: [PATCH] revset: remove pre-calculation of arguments count --- lib/src/revset.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/src/revset.rs b/lib/src/revset.rs index 3b69f0502..0a9771a1d 100644 --- a/lib/src/revset.rs +++ b/lib/src/revset.rs @@ -594,7 +594,6 @@ fn parse_function_expression( argument_pairs: Pairs, workspace_ctx: Option<&RevsetWorkspaceContext>, ) -> Result, RevsetParseError> { - let arg_count = argument_pairs.clone().count(); match name.as_str() { "parents" => { let arg = expect_one_argument(&name, argument_pairs)?; @@ -684,12 +683,6 @@ fn parse_function_expression( } } "file" => { - if arg_count < 1 { - return Err(RevsetParseError::InvalidFunctionArguments { - name, - message: "Expected at least 1 argument".to_string(), - }); - } if let Some(ctx) = workspace_ctx { let paths = argument_pairs .map(|arg| { @@ -698,7 +691,14 @@ fn parse_function_expression( Ok(path) }) .collect::, RevsetParseError>>()?; - Ok(RevsetExpression::all().with_file(paths)) + if paths.is_empty() { + Err(RevsetParseError::InvalidFunctionArguments { + name, + message: "Expected at least 1 argument".to_string(), + }) + } else { + Ok(RevsetExpression::all().with_file(paths)) + } } else { Err(RevsetParseError::FsPathWithoutWorkspace) }