1
0

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( Some(TypeDefinition::from_syntax_node(
source, type_node, context, source, type_node, context,
)?) )?)
} else { } else if let Some((_, r#type)) = context.variables()?.get(identifier.inner()) {
if let Some((_, r#type)) = context.variables()?.get(identifier.inner()) {
Some(TypeDefinition::new(r#type.clone())) Some(TypeDefinition::new(r#type.clone()))
} else { } else {
None None
}
}; };
let operator_node = node.child(child_count - 2).unwrap().child(0).unwrap(); let operator_node = node.child(child_count - 2).unwrap().child(0).unwrap();

View File

@ -59,10 +59,10 @@ impl AbstractTree for Block {
.enumerate() .enumerate()
.find_map_first(|(index, statement)| { .find_map_first(|(index, statement)| {
if let Statement::Return(expression) = 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() { if result.is_err() {
Some(result) Some(result)

View File

@ -55,11 +55,11 @@ impl AbstractTree for For {
if self.is_async { if self.is_async {
values.par_iter().try_for_each(|value| { 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)?; 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 { } else {
let loop_context = Map::clone_from(context)?; let loop_context = Map::clone_from(context)?;
@ -67,7 +67,7 @@ impl AbstractTree for For {
for value in values.iter() { for value in values.iter() {
loop_context.set(key.clone(), value.clone(), None)?; 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> { fn run(&self, source: &str, context: &Map) -> Result<Value> {
let index_collection = self.index.collection.run(source, context)?; 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 { let index_key = if let crate::Expression::Identifier(identifier) = &self.index.index {
identifier.inner() identifier.inner()
} else { } 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 { let new_value = match self.operator {
AssignmentOperator::PlusEqual => { AssignmentOperator::PlusEqual => {

View File

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

View File

@ -11,7 +11,7 @@ impl BuiltInFunction for FromJson {
Error::expect_argument_amount(self, 1, arguments.len())?; Error::expect_argument_amount(self, 1, arguments.len())?;
let json_string = arguments.first().unwrap().as_string()?; 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) Ok(value)
} }

View File

@ -15,7 +15,7 @@ impl BuiltInFunction for InstallPackages {
let mut command = Command::new("sudo"); let mut command = Command::new("sudo");
let argument_list = arguments.first().unwrap().as_list()?; 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() { for argument in argument_list.items().iter() {
command.arg(argument.as_string()?); command.arg(argument.as_string()?);

View File

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

View File

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

View File

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