Clippy on reduced_ast.rs

This commit is contained in:
Greg Shuflin 2021-10-19 20:56:52 -07:00
parent 49a50deb04
commit f8c2e57b37

View File

@ -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<Stmt> {
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<FormalParam>, 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<String>, Expression)>) -> Expr {
fn reduce_named_struct(&mut self, name: &QualifiedName, fields: &[(Rc<String>, 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<InvocationArgument>) -> 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<Pattern>, 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 {