From 1b41eb10c6b73e552ca57bad7e77eb99ba41ce6e Mon Sep 17 00:00:00 2001 From: Richard Carson Date: Tue, 17 Oct 2023 11:00:26 -0400 Subject: [PATCH] Fix some clippy --- src/decorators/mod.rs | 2 +- src/decorators/string.rs | 2 +- src/extensions/function.rs | 7 +++---- src/extensions/runtime.rs | 2 +- src/functions/builtins/str.rs | 2 +- src/functions/function_definition.rs | 8 ++++---- src/handlers/boolean.rs | 2 +- src/handlers/errors.rs | 14 +++++++------- src/handlers/math.rs | 10 +++++----- src/token.rs | 2 +- 10 files changed, 25 insertions(+), 26 deletions(-) diff --git a/src/decorators/mod.rs b/src/decorators/mod.rs index bd1668d..cbcb5c5 100644 --- a/src/decorators/mod.rs +++ b/src/decorators/mod.rs @@ -168,7 +168,7 @@ impl DecoratorDefinition { /// Return the decorator's argument type pub fn arg(&self) -> ExpectedTypes { - self.argument.clone() + self.argument } /// Return the decorator's signature diff --git a/src/decorators/string.rs b/src/decorators/string.rs index a82a644..b0931b9 100644 --- a/src/decorators/string.rs +++ b/src/decorators/string.rs @@ -46,7 +46,7 @@ pub const ROMAN: DecoratorDefinition = DecoratorDefinition { if decorator.arg().strict_matches(input) { let mut value = input.as_int().unwrap(); if value > 3999 { - return Err(Error::Overflow(token.clone()).into()); + return Err(Error::Overflow(token.clone())); } let roman_numerals = vec![ diff --git a/src/extensions/function.rs b/src/extensions/function.rs index 7ab3b87..825034b 100644 --- a/src/extensions/function.rs +++ b/src/extensions/function.rs @@ -20,8 +20,7 @@ impl ExtensionFunction { "[{}] @{}", self.argument_types .get(0) - .or(Some(&"Any".to_string().to_lowercase())) - .unwrap(), + .unwrap_or(&"Any".to_string().to_lowercase()), self.fname ) } @@ -55,7 +54,7 @@ impl ExtensionFunction { ExtensionsRuntime::with(|runtime| match runtime.load_module(module) { Ok(module_context) => { let mut _args = serde_json::to_value(args)?; - runtime.call_function::(&module_context, &name, &[_args]) + runtime.call_function::(&module_context, name, &[_args]) } Err(e) => Err(e), }) @@ -69,7 +68,7 @@ impl ExtensionFunction { ExtensionsRuntime::with(|runtime| match runtime.load_module(module) { Ok(module_context) => { let mut _arg = serde_json::to_value(arg.clone())?; - runtime.call_function::(&module_context, &name, &[_arg]) + runtime.call_function::(&module_context, name, &[_arg]) } Err(e) => Err(e), }) diff --git a/src/extensions/runtime.rs b/src/extensions/runtime.rs index 22c49b9..ee81288 100644 --- a/src/extensions/runtime.rs +++ b/src/extensions/runtime.rs @@ -66,7 +66,7 @@ impl ExtensionsRuntime { where T: serde::de::DeserializeOwned, { - self.0.call_function(&context, function, args) + self.0.call_function(context, function, args) } pub fn load_extension(path: &str) -> Result { diff --git a/src/functions/builtins/str.rs b/src/functions/builtins/str.rs index 8d707ba..aef7cd3 100644 --- a/src/functions/builtins/str.rs +++ b/src/functions/builtins/str.rs @@ -143,7 +143,7 @@ const REGEX: FunctionDefinition = FunctionDefinition { }; let re = Regex::new(&pattern); - if let Err(_) = re { + if re.is_err() { return Err(Error::StringFormat { expected_format: "regex".to_string(), token: token.clone(), diff --git a/src/functions/function_definition.rs b/src/functions/function_definition.rs index ffdcc7b..811e62e 100644 --- a/src/functions/function_definition.rs +++ b/src/functions/function_definition.rs @@ -29,19 +29,19 @@ pub mod function_macros { #[macro_export] macro_rules! function_arg { ($name:literal:$type:ident) => { - $crate::FunctionArgument::new($name, crate::ExpectedTypes::$type, false) + $crate::FunctionArgument::new($name, $crate::ExpectedTypes::$type, false) }; ("plural", $name:literal:$type:ident) => { - $crate::FunctionArgument::new_plural($name, crate::ExpectedTypes::$type, false) + $crate::FunctionArgument::new_plural($name, $crate::ExpectedTypes::$type, false) }; ("optional", $name:literal:$type:ident) => { - $crate::FunctionArgument::new($name, crate::ExpectedTypes::$type, true) + $crate::FunctionArgument::new($name, $crate::ExpectedTypes::$type, true) }; ("plural+optional", $name:literal:$type:ident) => { - $crate::FunctionArgument::new_plural($name, crate::ExpectedTypes::$type, true) + $crate::FunctionArgument::new_plural($name, $crate::ExpectedTypes::$type, true) }; } diff --git a/src/handlers/boolean.rs b/src/handlers/boolean.rs index d074a71..0104d3e 100644 --- a/src/handlers/boolean.rs +++ b/src/handlers/boolean.rs @@ -41,7 +41,7 @@ fn rule_bool_cmp_expression(token: &mut Token, _state: &mut ParserState) -> Opti Rule::ne => l.ne(&r), Rule::ge => l.ge(&r), Rule::le => l.le(&r), - _ => return Some(Error::Internal(token.clone()).into()), + _ => return Some(Error::Internal(token.clone())), })); i += 2; diff --git a/src/handlers/errors.rs b/src/handlers/errors.rs index df2ac6a..9d76d0c 100644 --- a/src/handlers/errors.rs +++ b/src/handlers/errors.rs @@ -42,37 +42,37 @@ pub fn handler_table() -> HashMap { /// Catches unterminated string literals fn rule_error_unterminated_literal(token: &mut Token, _state: &mut ParserState) -> Option { - Some(Error::UnterminatedLiteral(token.clone()).into()) + Some(Error::UnterminatedLiteral(token.clone())) } /// Catches unterminated linebreaks fn rule_error_unterminated_linebreak(token: &mut Token, _state: &mut ParserState) -> Option { - Some(Error::UnterminatedLinebreak(token.clone()).into()) + Some(Error::UnterminatedLinebreak(token.clone())) } /// Catches unterminated arrays fn rule_error_unterminated_array(token: &mut Token, _state: &mut ParserState) -> Option { - Some(Error::UnterminatedArray(token.clone()).into()) + Some(Error::UnterminatedArray(token.clone())) } /// Catches unterminated objects fn rule_error_unterminated_object(token: &mut Token, _state: &mut ParserState) -> Option { - Some(Error::UnterminatedObject(token.clone()).into()) + Some(Error::UnterminatedObject(token.clone())) } /// Catches unterminated parens fn rule_error_unterminated_paren(token: &mut Token, _state: &mut ParserState) -> Option { - Some(Error::UnterminatedParen(token.clone()).into()) + Some(Error::UnterminatedParen(token.clone())) } /// Catches decorator errors fn rule_error_unexpected_decorator(token: &mut Token, _state: &mut ParserState) -> Option { - Some(Error::UnexpectedDecorator(token.clone()).into()) + Some(Error::UnexpectedDecorator(token.clone())) } /// Catches postfix errors fn rule_error_unexpected_postfix(token: &mut Token, _state: &mut ParserState) -> Option { - Some(Error::UnexpectedPostfix(token.clone()).into()) + Some(Error::UnexpectedPostfix(token.clone())) } #[cfg(test)] diff --git a/src/handlers/math.rs b/src/handlers/math.rs index 1660058..52af4d8 100644 --- a/src/handlers/math.rs +++ b/src/handlers/math.rs @@ -53,14 +53,14 @@ pub fn factorial(source: &Token, input: &Value) -> Result { if let Some(acc_) = acc.checked_mul(i as IntegerType) { acc = acc_; } else { - return Err(Error::Overflow(source.clone()).into()); + return Err(Error::Overflow(source.clone())); } } Ok(Value::Integer(acc)) } - _ => Err(Error::Underflow(source.clone()).into()), + _ => Err(Error::Underflow(source.clone())), } } else if input.is_array() { let mut out = input.as_array(); @@ -121,7 +121,7 @@ fn unary_minus(expression: &Token, value: Value) -> Result { Ok(Value::Array(ra)) } _ => Err(Error::ValueType { - value: value, + value, expected_type: ExpectedTypes::IntOrFloat, token: expression.clone(), }), @@ -139,7 +139,7 @@ fn unary_not(expression: &Token, value: Value) -> Result { Value::Integer(n) => match trim_binary(Value::Integer(!n), n) { Some(v) => Ok(v), None => Err(Error::ValueType { - value: value, + value, expected_type: ExpectedTypes::Int, token: expression.clone(), }), @@ -155,7 +155,7 @@ fn unary_not(expression: &Token, value: Value) -> Result { Ok(Value::Array(ra)) } _ => Err(Error::ValueType { - value: value, + value, expected_type: ExpectedTypes::Int, token: expression.clone(), }), diff --git a/src/token.rs b/src/token.rs index 225e4f0..51bc298 100644 --- a/src/token.rs +++ b/src/token.rs @@ -157,7 +157,7 @@ impl Token { Ok(token) } }, - Err(e) => Err(Error::Pest(e, Token::dummy(input)).into()), + Err(e) => Err(Error::Pest(e, Token::dummy(input))), } }