From f8c2e57b37394e8a31ceaf18b5081f263ee6c472 Mon Sep 17 00:00:00 2001 From: Greg Shuflin Date: Tue, 19 Oct 2021 20:56:52 -0700 Subject: [PATCH] Clippy on reduced_ast.rs --- schala-lang/language/src/reduced_ast.rs | 33 ++++++++++++++----------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/schala-lang/language/src/reduced_ast.rs b/schala-lang/language/src/reduced_ast.rs index 228eb2b..2329488 100644 --- a/schala-lang/language/src/reduced_ast.rs +++ b/schala-lang/language/src/reduced_ast.rs @@ -12,6 +12,9 @@ //! then ReducedAST shouldn't be duplicating information that can be queried at runtime from the //! symbol table. But I think the former might make sense since ultimately the bytecode will be //! built from the ReducedAST. + +#![allow(clippy::enum_variant_names)] + use std::rc::Rc; use std::str::FromStr; use std::convert::TryFrom; @@ -141,6 +144,7 @@ impl<'a> Reducer<'a> { } } + #[allow(clippy::ptr_arg)] fn block(&mut self, block: &Block) -> Vec { block.iter().map(|stmt| self.statement(stmt)).collect() } @@ -189,11 +193,11 @@ impl<'a> Reducer<'a> { }; match spec { - SymbolSpec::RecordConstructor { .. } => Expr::ReductionError(format!("AST reducer doesn't expect a RecordConstructor here")), + SymbolSpec::RecordConstructor { .. } => Expr::ReductionError("AST reducer doesn't expect a RecordConstructor here".to_string()), SymbolSpec::DataConstructor { index, arity, type_name } => Expr::Constructor { type_name: type_name.clone(), name: local_name.clone(), - tag: index.clone(), + tag: *index, arity: *arity, }, SymbolSpec::Func(_) => Expr::Sym(local_name.clone()), @@ -201,7 +205,8 @@ impl<'a> Reducer<'a> { } } - fn reduce_lambda(&mut self, params: &Vec, body: &Block) -> Expr { + #[allow(clippy::ptr_arg)] + fn reduce_lambda(&mut self, params: &[FormalParam], body: &Block) -> Expr { Expr::Func(Func::UserDefined { name: None, params: params.iter().map(|param| param.name.clone()).collect(), @@ -209,7 +214,7 @@ impl<'a> Reducer<'a> { }) } - fn reduce_named_struct(&mut self, name: &QualifiedName, fields: &Vec<(Rc, Expression)>) -> Expr { + fn reduce_named_struct(&mut self, name: &QualifiedName, fields: &[(Rc, Expression)]) -> Expr { let symbol = match self.symbol_table.lookup_symbol(&name.id) { Some(fqsn) => fqsn, None => return Expr::ReductionError(format!("FQSN lookup for name {:?} failed", name)), @@ -236,7 +241,7 @@ impl<'a> Reducer<'a> { Expr::Call { f, args } } - fn reduce_call_expression(&mut self, func: &Expression, arguments: &Vec) -> Expr { + fn reduce_call_expression(&mut self, func: &Expression, arguments: &[ InvocationArgument ]) -> Expr { Expr::Call { f: Box::new(self.expression(func)), args: arguments.iter().map(|arg| self.invocation_argument(arg)).collect(), @@ -246,23 +251,23 @@ impl<'a> Reducer<'a> { fn reduce_if_expression(&mut self, discriminator: Option<&Expression>, body: &IfExpressionBody) -> Expr { let cond = Box::new(match discriminator { Some(expr) => self.expression(expr), - None => return Expr::ReductionError(format!("blank cond if-expr not supported")), + None => return Expr::ReductionError("blank cond if-expr not supported".to_string()), }); match body { IfExpressionBody::SimpleConditional { then_case, else_case } => { - let then_clause = self.block(&then_case); + let then_clause = self.block(then_case); let else_clause = match else_case.as_ref() { None => vec![], - Some(stmts) => self.block(&stmts), + Some(stmts) => self.block(stmts), }; Expr::Conditional { cond, then_clause, else_clause } }, IfExpressionBody::SimplePatternMatch { pattern, then_case, else_case } => { - let then_clause = self.block(&then_case); + let then_clause = self.block(then_case); let else_clause = match else_case.as_ref() { None => vec![], - Some(stmts) => self.block(&stmts), + Some(stmts) => self.block(stmts), }; let alternatives = vec![ @@ -368,7 +373,7 @@ impl<'a> Reducer<'a> { * x is SomeBigOldEnum(_, x, Some(t)) */ -fn handle_symbol(symbol: Option<&Symbol>, inner_patterns: &Vec, symbol_table: &SymbolTable) -> Subpattern { +fn handle_symbol(symbol: Option<&Symbol>, inner_patterns: &[Pattern], symbol_table: &SymbolTable) -> Subpattern { use self::Pattern::*; let tag = symbol.map(|symbol| match symbol.spec { SymbolSpec::DataConstructor { index, .. } => index, @@ -451,7 +456,7 @@ impl Pattern { // if symbol is Some, treat this as a symbol pattern. If it's None, treat it // as a variable. match symbol_table.lookup_symbol(id) { - Some(symbol) => handle_symbol(Some(symbol), &vec![], symbol_table), + Some(symbol) => handle_symbol(Some(symbol), &[], symbol_table), None => { println!("Components: {:?}", components); let name = if components.len() == 1 { @@ -480,8 +485,8 @@ impl PatternLiteral { let comparison = Expr::Lit(match (neg, num) { (false, ExpressionKind::NatLiteral(n)) => Lit::Nat(*n), (false, ExpressionKind::FloatLiteral(f)) => Lit::Float(*f), - (true, ExpressionKind::NatLiteral(n)) => Lit::Int(-1*(*n as i64)), - (true, ExpressionKind::FloatLiteral(f)) => Lit::Float(-1.0*f), + (true, ExpressionKind::NatLiteral(n)) => Lit::Int(-(*n as i64)), + (true, ExpressionKind::FloatLiteral(f)) => Lit::Float(-f), _ => panic!("This should never happen") }); let guard = Some(Expr::Call {