Apply clippy suggestions and fixes

This commit is contained in:
Jeff 2023-12-29 22:39:50 -05:00
parent 42e0ef366f
commit 507082209f
10 changed files with 31 additions and 35 deletions

View File

@ -33,12 +33,10 @@ impl AbstractTree for Assignment {
Some(TypeDefinition::from_syntax_node(
source, type_node, context,
)?)
} else if let Some((_, r#type)) = context.variables()?.get(identifier.inner()) {
Some(TypeDefinition::new(r#type.clone()))
} else {
if let Some((_, r#type)) = context.variables()?.get(identifier.inner()) {
Some(TypeDefinition::new(r#type.clone()))
} else {
None
}
None
};
let operator_node = node.child(child_count - 2).unwrap().child(0).unwrap();

View File

@ -59,10 +59,10 @@ impl AbstractTree for Block {
.enumerate()
.find_map_first(|(index, statement)| {
if let Statement::Return(expression) = statement {
return Some(expression.run(source, &mut context.clone()));
return Some(expression.run(source, context));
}
let result = statement.run(source, &mut context.clone());
let result = statement.run(source, context);
if result.is_err() {
Some(result)

View File

@ -55,11 +55,11 @@ impl AbstractTree for For {
if self.is_async {
values.par_iter().try_for_each(|value| {
let mut iter_context = Map::clone_from(context)?;
let iter_context = Map::clone_from(context)?;
iter_context.set(key.clone(), value.clone(), None)?;
self.block.run(source, &mut iter_context).map(|_value| ())
self.block.run(source, &iter_context).map(|_value| ())
})?;
} else {
let loop_context = Map::clone_from(context)?;
@ -67,7 +67,7 @@ impl AbstractTree for For {
for value in values.iter() {
loop_context.set(key.clone(), value.clone(), None)?;
self.block.run(source, &mut loop_context.clone())?;
self.block.run(source, &loop_context)?;
}
}

View File

@ -51,7 +51,7 @@ impl AbstractTree for IndexAssignment {
fn run(&self, source: &str, context: &Map) -> Result<Value> {
let index_collection = self.index.collection.run(source, context)?;
let index_context = index_collection.as_map().unwrap_or(&context);
let index_context = index_collection.as_map().unwrap_or(context);
let index_key = if let crate::Expression::Identifier(identifier) = &self.index.index {
identifier.inner()
} else {
@ -60,7 +60,7 @@ impl AbstractTree for IndexAssignment {
));
};
let value = self.statement.run(source, &mut context.clone())?;
let value = self.statement.run(source, context)?;
let new_value = match self.operator {
AssignmentOperator::PlusEqual => {

View File

@ -99,7 +99,7 @@ impl Type {
}
(Type::Option(_), Type::None) | (Type::None, Type::Option(_)) => Ok(()),
(Type::List(self_item_type), Type::List(other_item_type)) => {
if self_item_type.check(&other_item_type).is_err() {
if self_item_type.check(other_item_type).is_err() {
Err(Error::TypeCheck {
expected: self.clone(),
actual: other.clone(),
@ -123,7 +123,7 @@ impl Type {
.zip(other_parameter_types.iter());
for (self_parameter_type, other_parameter_type) in parameter_type_pairs {
if self_parameter_type.check(&other_parameter_type).is_err() {
if self_parameter_type.check(other_parameter_type).is_err() {
return Err(Error::TypeCheck {
expected: self.clone(),
actual: other.clone(),
@ -149,7 +149,7 @@ impl Type {
}
impl AbstractTree for Type {
fn from_syntax_node(source: &str, node: Node, context: &Map) -> Result<Self> {
fn from_syntax_node(source: &str, node: Node, _context: &Map) -> Result<Self> {
Error::expect_syntax_node(source, "type", node)?;
let type_node = node.child(0).unwrap();
@ -157,7 +157,7 @@ impl AbstractTree for Type {
let r#type = match type_node.kind() {
"[" => {
let item_type_node = node.child(1).unwrap();
let item_type = Type::from_syntax_node(source, item_type_node, context)?;
let item_type = Type::from_syntax_node(source, item_type_node, _context)?;
Type::List(Box::new(item_type))
}
@ -172,7 +172,7 @@ impl AbstractTree for Type {
let child = node.child(index).unwrap();
if child.is_named() {
let parameter_type = Type::from_syntax_node(source, child, context)?;
let parameter_type = Type::from_syntax_node(source, child, _context)?;
parameter_types.push(parameter_type);
}
@ -180,7 +180,7 @@ impl AbstractTree for Type {
let final_node = node.child(child_count - 1).unwrap();
let return_type = if final_node.is_named() {
Type::from_syntax_node(source, final_node, context)?
Type::from_syntax_node(source, final_node, _context)?
} else {
Type::None
};
@ -197,7 +197,7 @@ impl AbstractTree for Type {
"str" => Type::String,
"option" => {
let inner_type_node = node.child(2).unwrap();
let inner_type = Type::from_syntax_node(source, inner_type_node, context)?;
let inner_type = Type::from_syntax_node(source, inner_type_node, _context)?;
Type::Option(Box::new(inner_type))
}

View File

@ -11,7 +11,7 @@ impl BuiltInFunction for FromJson {
Error::expect_argument_amount(self, 1, arguments.len())?;
let json_string = arguments.first().unwrap().as_string()?;
let value = serde_json::from_str(&json_string)?;
let value = serde_json::from_str(json_string)?;
Ok(value)
}

View File

@ -15,7 +15,7 @@ impl BuiltInFunction for InstallPackages {
let mut command = Command::new("sudo");
let argument_list = arguments.first().unwrap().as_list()?;
command.args(&["dnf", "-y", "install"]);
command.args(["dnf", "-y", "install"]);
for argument in argument_list.items().iter() {
command.arg(argument.as_string()?);

View File

@ -8,6 +8,12 @@ use crate::Value;
#[derive(Debug, Clone)]
pub struct List(Arc<RwLock<Vec<Value>>>);
impl Default for List {
fn default() -> Self {
Self::new()
}
}
impl List {
pub fn new() -> Self {
List(Arc::new(RwLock::new(Vec::new())))
@ -52,9 +58,6 @@ impl Ord for List {
impl PartialOrd for List {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
let left = self.0.read().unwrap().clone().into_iter();
let right = other.0.read().unwrap().clone().into_iter();
left.partial_cmp(right)
Some(self.cmp(other))
}
}

View File

@ -99,10 +99,7 @@ impl Ord for Map {
impl PartialOrd for Map {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
let left = self.variables.read().unwrap().clone().into_iter();
let right = other.variables.read().unwrap().clone().into_iter();
left.partial_cmp(right)
Some(self.cmp(other))
}
}

View File

@ -291,14 +291,12 @@ impl Sub for Value {
type Output = Result<Self>;
fn sub(self, other: Self) -> Self::Output {
match (self.as_integer(), other.as_integer()) {
(Ok(left), Ok(right)) => return Ok(Value::Integer(left - right)),
_ => {}
if let (Ok(left), Ok(right)) = (self.as_integer(), other.as_integer()) {
return Ok(Value::Integer(left - right));
}
match (self.as_number(), other.as_number()) {
(Ok(left), Ok(right)) => return Ok(Value::Float(left - right)),
_ => {}
if let (Ok(left), Ok(right)) = (self.as_number(), other.as_number()) {
return Ok(Value::Float(left - right));
}
let non_number = if !self.is_number() { self } else { other };