From b451503a2748721aab066930dcb8740e02738b6d Mon Sep 17 00:00:00 2001 From: Erin Date: Thu, 29 Jul 2021 23:22:38 +0200 Subject: [PATCH] Obeyed clippy --- src/error.rs | 2 -- src/interpret.rs | 16 ++++++++-------- src/repl.rs | 2 +- src/variables.rs | 6 +++--- 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/error.rs b/src/error.rs index 24cd96d0..bc0ea39d 100644 --- a/src/error.rs +++ b/src/error.rs @@ -10,7 +10,6 @@ pub struct Error { #[derive(Debug)] pub enum ErrorKind { - SyntaxError(String), UnexpectedEof, UnexpectedToken(Token), UnknownVariable(String), @@ -48,7 +47,6 @@ impl std::error::Error for Error {} impl Display for ErrorKind { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - ErrorKind::SyntaxError(desc) => write!(f, "syntax error: {}", desc), ErrorKind::UnexpectedEof => write!(f, "unexpected end of file"), ErrorKind::UnexpectedToken(token) => write!(f, "unexpected token {:?}", token), ErrorKind::UnknownVariable(name) => write!(f, "unknown identifier \"{}\"", name), diff --git a/src/interpret.rs b/src/interpret.rs index b0b5049d..f4052ab6 100644 --- a/src/interpret.rs +++ b/src/interpret.rs @@ -138,8 +138,8 @@ impl ExecEnv { Ok(match &expr.kind { BinOp { lhs, rhs, kind } => { - let lhs = self.eval_expr(&lhs)?; - let rhs = self.eval_expr(&rhs)?; + let lhs = self.eval_expr(lhs)?; + let rhs = self.eval_expr(rhs)?; match kind { // Arithmetic operators. Add | Subtract | Multiply | Divide => { @@ -193,7 +193,7 @@ impl ExecEnv { } } } - Not(expr) => Bool(!self.eval_expr(&expr)?.into_bool()), + Not(expr) => Bool(!self.eval_expr(expr)?.into_bool()), Literal(value) => value.clone(), ExprKind::Cart(members) => Value::Cart( members @@ -268,10 +268,10 @@ impl ExecEnv { } } StmtKind::Call { iden, args } => { - let func = self.get_var(&iden)?; + let func = self.get_var(iden)?; if let Value::Functio(func) = func { - self.fn_call(func, &args, &stmt.span)?; + self.fn_call(func, args, &stmt.span)?; } else { // Fail silently for now. } @@ -286,7 +286,7 @@ impl ExecEnv { }, StmtKind::Assign { iden, value } => { let value = self.eval_expr(value)?; - self.get_var_mut(&iden)?.value.replace(value); + self.get_var_mut(iden)?.value.replace(value); } StmtKind::Break => { return Ok(HaltStatus::Break(stmt.span.clone())); @@ -295,7 +295,7 @@ impl ExecEnv { return Ok(HaltStatus::Hopback(stmt.span.clone())); } StmtKind::Melo(iden) => { - self.get_var_mut(&iden)?.melo = true; + self.get_var_mut(iden)?.melo = true; } StmtKind::Rlyeh => { // Maybe print a creepy error message or something @@ -314,7 +314,7 @@ impl ExecEnv { value += self.get_bit()? as i32; } - self.get_var_mut(&iden)?.value.replace(Value::Int(value)); + self.get_var_mut(iden)?.value.replace(Value::Int(value)); } } diff --git a/src/repl.rs b/src/repl.rs index a8afae09..af084b54 100644 --- a/src/repl.rs +++ b/src/repl.rs @@ -21,7 +21,7 @@ pub fn repl(ast_print: bool) { break; } - let mut parser = Parser::new(&line); + let mut parser = Parser::new(line); let value = parser.init().and_then(|ast| { if ast_print { println!("{:#?}", &ast); diff --git a/src/variables.rs b/src/variables.rs index 6a213c56..3fda15dc 100644 --- a/src/variables.rs +++ b/src/variables.rs @@ -122,7 +122,7 @@ impl Value { /// Coerce a Value to a boolean. The conversion cannot fail. pub fn into_bool(&self) -> bool { match self { - Value::Abool(b) => b.clone().into(), + Value::Abool(b) => (*b).into(), Value::Bool(b) => *b, Value::Functio(_) => true, Value::Int(x) => *x != 0, @@ -138,13 +138,13 @@ impl Value { Value::Nul => Value::Nul, Value::Str(s) => Value::Int(s.as_bytes()[index.into_i32() as usize] as i32), Value::Int(i) => Value::Int( - (format!("{}", i).as_bytes()[index.into_i32() as usize] - ('0' as u8)) as i32, + (format!("{}", i).as_bytes()[index.into_i32() as usize] - b'0') as i32, ), Value::Bool(b) => Value::Int( format!("{}", b) .chars() .nth(index.into_i32() as usize) - .unwrap_or_else(|| '?') as i32, + .unwrap_or('?') as i32, ), Value::Abool(b) => Value::Int(*b as i32), Value::Functio(_) => Value::Int(42),