Automatically apply clippy to various util modules

This commit is contained in:
Greg Shuflin 2021-10-19 21:57:14 -07:00
parent c9c65b050c
commit 36f06b38de
4 changed files with 32 additions and 32 deletions

View File

@ -39,12 +39,12 @@ fn declaration<V: ASTVisitor>(v: &mut V, decl: &Declaration) {
use Declaration::*;
match decl {
FuncSig(sig) => {
v.signature(&sig);
signature(v, &sig);
v.signature(sig);
signature(v, sig);
},
FuncDecl(sig, block) => {
v.signature(&sig);
v.block(&block);
v.signature(sig);
v.block(block);
walk_block(v, block);
},
TypeDecl { name, body, mutable } => v.type_declaration(name, body, *mutable),
@ -52,8 +52,8 @@ fn declaration<V: ASTVisitor>(v: &mut V, decl: &Declaration) {
Binding { name, constant, type_anno, expr } => {
v.binding(name, *constant, type_anno.as_ref(), expr);
v.type_annotation(type_anno.as_ref());
v.expression(&expr);
expression(v, &expr);
v.expression(expr);
expression(v, expr);
},
Impl { type_name, interface_name, block } => {
v.implemention(type_name, interface_name.as_ref(), block);
@ -172,7 +172,7 @@ fn expression_kind<V: ASTVisitor>(v: &mut V, expression_kind: &ExpressionKind) {
},
IfExpression { discriminator, body } => {
v.if_expression(deref_optional_box(discriminator), body);
discriminator.as_ref().map(|d| expression(v, d));
if let Some(d) = discriminator.as_ref() { expression(v, d) }
if_expression_body(v, body);
},
WhileExpression { condition, body } => v.while_expression(deref_optional_box(condition), body),
@ -195,13 +195,13 @@ fn if_expression_body<V: ASTVisitor>(v: &mut V, body: &IfExpressionBody) {
match body {
SimpleConditional { then_case, else_case } => {
walk_block(v, then_case);
else_case.as_ref().map(|block| walk_block(v, block));
if let Some(block) = else_case.as_ref() { walk_block(v, block) }
},
SimplePatternMatch { pattern, then_case, else_case } => {
v.pattern(pattern);
walk_pattern(v, pattern);
walk_block(v, then_case);
else_case.as_ref().map(|block| walk_block(v, block));
if let Some(block) = else_case.as_ref() { walk_block(v, block) }
},
CondList(arms) => {
for arm in arms {

View File

@ -13,15 +13,15 @@ fn evaluate_all_outputs(input: &str) -> Vec<Result<String, String>> {
let reduced = reduce(&ast, &symbol_table);
let mut state = State::new();
let all_output = state.evaluate(reduced, true);
all_output
state.evaluate(reduced, true)
}
macro_rules! test_in_fresh_env {
($string:expr, $correct:expr) => {
{
let all_output = evaluate_all_outputs($string);
let ref output = all_output.last().unwrap();
let output = &all_output.last().unwrap();
assert_eq!(**output, Ok($correct.to_string()));
}
}

View File

@ -83,13 +83,13 @@ impl TypeConst {
pub fn to_string(&self) -> String {
use self::TypeConst::*;
match self {
Unit => format!("()"),
Nat => format!("Nat"),
Int => format!("Int"),
Float => format!("Float"),
StringT => format!("String"),
Bool => format!("Bool"),
Ordering => format!("Ordering"),
Unit => "()".to_string(),
Nat => "Nat".to_string(),
Int => "Int".to_string(),
Float => "Float".to_string(),
StringT => "String".to_string(),
Bool => "Bool".to_string(),
Ordering => "Ordering".to_string(),
}
}
}
@ -117,7 +117,7 @@ impl Type {
Const(c) => c.to_string(),
Var(v) => format!("t_{}", v.0),
Arrow { params, box ref ret } => {
if params.len() == 0 {
if params.is_empty() {
format!("-> {}", ret.to_string())
} else {
let mut buf = String::new();
@ -128,7 +128,7 @@ impl Type {
buf
}
},
Compound { .. } => format!("<some compound type>")
Compound { .. } => "<some compound type>".to_string()
}
}
@ -256,7 +256,7 @@ impl<'a> TypeContext<'a> {
use self::TypeIdentifier::*;
Ok(match name {
Singleton(TypeSingletonName { name,.. }) => {
match Type::from_string(&name) {
match Type::from_string(name) {
Some(ty) => ty,
None => return TypeError::new(format!("Unknown type name: {}", name))
}
@ -279,7 +279,7 @@ impl<'a> TypeContext<'a> {
fn statement(&mut self, statement: &Statement) -> InferResult<Type> {
match &statement.kind {
StatementKind::Expression(e) => self.expr(e),
StatementKind::Declaration(decl) => self.decl(&decl),
StatementKind::Declaration(decl) => self.decl(decl),
StatementKind::Import(_) => Ok(ty!(Unit)),
StatementKind::Module(_) => Ok(ty!(Unit)),
}
@ -361,7 +361,7 @@ impl<'a> TypeContext<'a> {
use self::IfExpressionBody::*;
match (discriminator, body) {
(Some(expr), SimpleConditional{ then_case, else_case }) => self.handle_simple_if(expr, then_case, else_case),
_ => TypeError::new(format!("Complex conditionals not supported"))
_ => TypeError::new("Complex conditionals not supported".to_string())
}
}
@ -410,7 +410,7 @@ impl<'a> TypeContext<'a> {
t_ret.clone()
},
Type::Arrow { .. } => return TypeError::new("Wrong length"),
_ => return TypeError::new(format!("Not a function"))
_ => return TypeError::new("Not a function".to_string())
})
}
@ -438,26 +438,26 @@ impl<'a> TypeContext<'a> {
(Const(ref c1), Const(ref c2)) if c1 == c2 => Ok(Const(c1.clone())), //choice of c1 is arbitrary I *think*
(a @ Var(_), b @ Const(_)) => self.unify(b, a),
(Const(ref c1), Var(ref v2)) => {
self.unification_table.unify_var_value(v2.clone(), Some(c1.clone()))
self.unification_table.unify_var_value(*v2, Some(c1.clone()))
.or_else(|_| TypeError::new(format!("Couldn't unify {:?} and {:?}", Const(c1.clone()), Var(*v2))))?;
Ok(Const(c1.clone()))
},
(Var(v1), Var(v2)) => {
//TODO add occurs check
self.unification_table.unify_var_var(v1.clone(), v2.clone())
self.unification_table.unify_var_var(v1, v2)
.or_else(|e| {
println!("Unify error: {:?}", e);
TypeError::new(format!("Two type variables {:?} and {:?} couldn't unify", v1, v2))
})?;
Ok(Var(v1.clone())) //arbitrary decision I think
Ok(Var(v1)) //arbitrary decision I think
},
(a, b) => TypeError::new(format!("{:?} and {:?} do not unify", a, b)),
}
}
fn fresh_type_variable(&mut self) -> TypeVar {
let new_type_var = self.unification_table.new_key(None);
new_type_var
self.unification_table.new_key(None)
}
}
@ -468,7 +468,7 @@ mod typechecking_tests {
macro_rules! assert_type_in_fresh_context {
($string:expr, $type:expr) => {
let mut tc = TypeContext::new();
let ref ast = crate::util::quick_ast($string);
let ast = &crate::util::quick_ast($string);
let ty = tc.typecheck(ast).unwrap();
assert_eq!(ty, $type)
}

View File

@ -4,7 +4,7 @@ use std::cmp::Eq;
use std::ops::Deref;
pub fn deref_optional_box<T>(x: &Option<Box<T>>) -> Option<&T> {
x.as_ref().map(|b: &Box<T>| Deref::deref(b))
x.as_ref().map(Deref::deref)
}
#[derive(Default, Debug)]