Skip to content

Commit

Permalink
Fix some clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
rscarson committed Oct 17, 2023
1 parent 44fe10f commit 1b41eb1
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/decorators/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/decorators/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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![
Expand Down
7 changes: 3 additions & 4 deletions src/extensions/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}
Expand Down Expand Up @@ -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::<Value>(&module_context, &name, &[_args])
runtime.call_function::<Value>(&module_context, name, &[_args])
}
Err(e) => Err(e),
})
Expand All @@ -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::<String>(&module_context, &name, &[_arg])
runtime.call_function::<String>(&module_context, name, &[_arg])
}
Err(e) => Err(e),
})
Expand Down
2 changes: 1 addition & 1 deletion src/extensions/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Extension, rustyscript::Error> {
Expand Down
2 changes: 1 addition & 1 deletion src/functions/builtins/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
8 changes: 4 additions & 4 deletions src/functions/function_definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/handlers/boolean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 7 additions & 7 deletions src/handlers/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,37 +42,37 @@ pub fn handler_table() -> HashMap<Rule, RuleHandler> {

/// Catches unterminated string literals
fn rule_error_unterminated_literal(token: &mut Token, _state: &mut ParserState) -> Option<Error> {
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<Error> {
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<Error> {
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<Error> {
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<Error> {
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<Error> {
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<Error> {
Some(Error::UnexpectedPostfix(token.clone()).into())
Some(Error::UnexpectedPostfix(token.clone()))
}

#[cfg(test)]
Expand Down
10 changes: 5 additions & 5 deletions src/handlers/math.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ pub fn factorial(source: &Token, input: &Value) -> Result<Value, Error> {
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();
Expand Down Expand Up @@ -121,7 +121,7 @@ fn unary_minus(expression: &Token, value: Value) -> Result<Value, Error> {
Ok(Value::Array(ra))
}
_ => Err(Error::ValueType {
value: value,
value,
expected_type: ExpectedTypes::IntOrFloat,
token: expression.clone(),
}),
Expand All @@ -139,7 +139,7 @@ fn unary_not(expression: &Token, value: Value) -> Result<Value, Error> {
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(),
}),
Expand All @@ -155,7 +155,7 @@ fn unary_not(expression: &Token, value: Value) -> Result<Value, Error> {
Ok(Value::Array(ra))
}
_ => Err(Error::ValueType {
value: value,
value,
expected_type: ExpectedTypes::Int,
token: expression.clone(),
}),
Expand Down
2 changes: 1 addition & 1 deletion src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))),
}
}

Expand Down

0 comments on commit 1b41eb1

Please sign in to comment.