From 113554428fee0b0350f149a449abfd32cd37e27d Mon Sep 17 00:00:00 2001 From: Erin Date: Wed, 1 Sep 2021 17:46:17 +0200 Subject: [PATCH] Clippy --- ablescript/src/interpret.rs | 5 ++--- ablescript/src/variables.rs | 28 ++++++---------------------- 2 files changed, 8 insertions(+), 25 deletions(-) diff --git a/ablescript/src/interpret.rs b/ablescript/src/interpret.rs index b22eedc6..61a50658 100644 --- a/ablescript/src/interpret.rs +++ b/ablescript/src/interpret.rs @@ -21,7 +21,7 @@ use rand::random; use crate::{ ast::{Expr, ExprKind, Iden, Stmt, StmtKind}, base_55, - consts::{self, ablescript_consts}, + consts::ablescript_consts, error::{Error, ErrorKind}, variables::{Functio, Value, Variable}, }; @@ -134,7 +134,6 @@ impl ExecEnv { fn eval_expr(&self, expr: &Expr) -> Result { use crate::ast::BinOpKind::*; use crate::ast::ExprKind::*; - use Value::*; Ok(match &expr.kind { BinOp { lhs, rhs, kind } => { @@ -345,7 +344,7 @@ impl ExecEnv { res?; } Functio::Eval(code) => { - if args.len() != 0 { + if !args.is_empty() { return Err(Error { kind: ErrorKind::MismatchedArgumentError, span: span.to_owned(), diff --git a/ablescript/src/variables.rs b/ablescript/src/variables.rs index ee0bc875..23fb17a0 100644 --- a/ablescript/src/variables.rs +++ b/ablescript/src/variables.rs @@ -1,14 +1,6 @@ use std::{ - cell::RefCell, - collections::HashMap, - convert::{TryFrom, TryInto}, - fmt::Display, - hash::Hash, - io::Write, - mem::discriminant, - ops, - rc::Rc, - vec, + cell::RefCell, collections::HashMap, fmt::Display, hash::Hash, io::Write, mem::discriminant, + ops, rc::Rc, vec, }; use rand::Rng; @@ -424,9 +416,7 @@ impl ops::Div for Value { .map(|(k, v)| { ( Value::Int(k as i32 + 1), - Rc::new(RefCell::new(Value::Cart( - v.into_iter().cloned().collect(), - ))), + Rc::new(RefCell::new(Value::Cart(v.iter().cloned().collect()))), ) }) .collect(), @@ -465,13 +455,7 @@ impl PartialEq for Value { let other = other.clone(); match self { - Value::Nul => { - if let Value::Nul = other { - true - } else { - false - } - } + Value::Nul => matches!(other, Value::Nul), Value::Str(s) => *s == other.to_string(), Value::Int(i) => *i == other.into_i32(), Value::Bool(b) => *b == other.into_bool(), @@ -542,8 +526,8 @@ impl Display for Value { }, Value::Cart(c) => { write!(f, "[")?; - let mut cart_vec = c.into_iter().collect::>(); - cart_vec.sort_by(|x, y| x.0.partial_cmp(&y.0).unwrap_or(std::cmp::Ordering::Less)); + let mut cart_vec = c.iter().collect::>(); + cart_vec.sort_by(|x, y| x.0.partial_cmp(y.0).unwrap_or(std::cmp::Ordering::Less)); for (key, value) in cart_vec { write!(f, "{} <= {}, ", value.borrow(), key)?;