From ae6a79077f4487ac92e159e4fa7ad9bc3e115f72 Mon Sep 17 00:00:00 2001 From: Greg Shuflin Date: Tue, 19 Oct 2021 22:24:27 -0700 Subject: [PATCH] more clippy lints --- schala-lang/language/src/ast/mod.rs | 4 ++- schala-lang/language/src/ast/visitor.rs | 18 +++++++------ schala-lang/language/src/ast/walker.rs | 26 ++++++++++--------- schala-lang/language/src/parsing/mod.rs | 25 +++++++----------- schala-lang/language/src/parsing/test.rs | 2 ++ .../language/src/symbol_table/resolver.rs | 2 +- schala-lang/language/src/tokenizing.rs | 3 ++- 7 files changed, 42 insertions(+), 38 deletions(-) diff --git a/schala-lang/language/src/ast/mod.rs b/schala-lang/language/src/ast/mod.rs index 0c4a5cd..674d664 100644 --- a/schala-lang/language/src/ast/mod.rs +++ b/schala-lang/language/src/ast/mod.rs @@ -1,5 +1,7 @@ -use std::rc::Rc; +#![allow(clippy::upper_case_acronyms)] +#![allow(clippy::enum_variant_names)] +use std::rc::Rc; use crate::derivative::Derivative; mod walker; diff --git a/schala-lang/language/src/ast/visitor.rs b/schala-lang/language/src/ast/visitor.rs index 05fc157..3514e98 100644 --- a/schala-lang/language/src/ast/visitor.rs +++ b/schala-lang/language/src/ast/visitor.rs @@ -6,26 +6,28 @@ use crate::ast::*; pub trait ASTVisitor: Sized { fn ast(&mut self, _ast: &AST) {} - fn block(&mut self, _statements: &Vec) {} + fn block(&mut self, _statements: &[ Statement ]) {} fn statement(&mut self, _statement: &Statement) {} fn declaration(&mut self, _declaration: &Declaration) {} fn signature(&mut self, _signature: &Signature) {} fn type_declaration(&mut self, _name: &TypeSingletonName, _body: &TypeBody, _mutable: bool) {} fn type_alias(&mut self, _alias: &Rc, _original: &Rc) {} fn binding(&mut self, _name: &Rc, _constant: bool, _type_anno: Option<&TypeIdentifier>, _expr: &Expression) {} - fn implemention(&mut self, _type_name: &TypeIdentifier, _interface_name: Option<&TypeSingletonName>, _block: &Vec) {} - fn interface(&mut self, _name: &Rc, _signatures: &Vec) {} + fn implemention(&mut self, _type_name: &TypeIdentifier, _interface_name: Option<&TypeSingletonName>, _block: &[ Declaration ]) {} + fn interface(&mut self, _name: &Rc, _signatures: &[ Signature ]) {} fn expression(&mut self, _expression: &Expression) {} fn expression_kind(&mut self, _kind: &ExpressionKind) {} fn type_annotation(&mut self, _type_anno: Option<&TypeIdentifier>) {} - fn named_struct(&mut self, _name: &QualifiedName, _fields: &Vec<(Rc, Expression)>) {} - fn call(&mut self, _f: &Expression, _arguments: &Vec) {} - fn index(&mut self, _indexee: &Expression, _indexers: &Vec) {} + fn named_struct(&mut self, _name: &QualifiedName, _fields: &[ (Rc, Expression) ]) {} + fn call(&mut self, _f: &Expression, _arguments: &[ InvocationArgument ]) {} + fn index(&mut self, _indexee: &Expression, _indexers: &[ Expression ]) {} fn if_expression(&mut self, _discrim: Option<&Expression>, _body: &IfExpressionBody) {} fn condition_arm(&mut self, _arm: &ConditionArm) {} + #[allow(clippy::ptr_arg)] fn while_expression(&mut self, _condition: Option<&Expression>, _body: &Block) {} - fn for_expression(&mut self, _enumerators: &Vec, _body: &ForBody) {} - fn lambda(&mut self, _params: &Vec, _type_anno: Option<&TypeIdentifier>, _body: &Block) {} + fn for_expression(&mut self, _enumerators: &[ Enumerator ], _body: &ForBody) {} + #[allow(clippy::ptr_arg)] + fn lambda(&mut self, _params: &[ FormalParam ], _type_anno: Option<&TypeIdentifier>, _body: &Block) {} fn invocation_argument(&mut self, _arg: &InvocationArgument) {} fn formal_param(&mut self, _param: &FormalParam) {} fn import(&mut self, _import: &ImportSpecifier) {} diff --git a/schala-lang/language/src/ast/walker.rs b/schala-lang/language/src/ast/walker.rs index e818565..2776500 100644 --- a/schala-lang/language/src/ast/walker.rs +++ b/schala-lang/language/src/ast/walker.rs @@ -9,6 +9,7 @@ pub fn walk_ast(v: &mut V, ast: &AST) { walk_block(v, &ast.statements); } +#[allow(clippy::ptr_arg)] fn walk_block(v: &mut V, block: &Vec) { for s in block { v.statement(s); @@ -79,7 +80,7 @@ fn expression(v: &mut V, expression: &Expression) { } -fn call(v: &mut V, f: &Expression, args: &Vec) { +fn call(v: &mut V, f: &Expression, args: &[ InvocationArgument ]) { v.expression(f); expression(v, f); for arg in args.iter() { @@ -103,20 +104,21 @@ fn invocation_argument(v: &mut V, arg: &InvocationArgument) { } } -fn index(v: &mut V, indexee: &Expression, indexers: &Vec) { +fn index(v: &mut V, indexee: &Expression, indexers: &[ Expression ]) { v.expression(indexee); for i in indexers.iter() { v.expression(i); } } -fn named_struct(v: &mut V, n: &QualifiedName, fields: &Vec<(Rc, Expression)>) { +fn named_struct(v: &mut V, n: &QualifiedName, fields: &[ (Rc, Expression) ]) { v.qualified_name(n); for (_, expr) in fields.iter() { v.expression(expr); } } +#[allow(clippy::ptr_arg)] fn lambda(v: &mut V, params: &Vec, type_anno: Option<&TypeIdentifier>, body: &Block) { for param in params { v.formal_param(param); @@ -128,11 +130,11 @@ fn lambda(v: &mut V, params: &Vec, type_anno: Option } fn formal_param(v: &mut V, param: &FormalParam) { - param.default.as_ref().map(|p| { - v.expression(p); - expression(v, p); - }); - v.type_annotation(param.anno.as_ref()); + if let Some(p) = param.default.as_ref() { + v.expression(p); + expression(v, p); + }; + v.type_annotation(param.anno.as_ref()); } fn expression_kind(v: &mut V, expression_kind: &ExpressionKind) { @@ -230,10 +232,10 @@ fn condition_arm(v: &mut V, arm: &ConditionArm) { }, _ => () } - arm.guard.as_ref().map(|guard| { - v.expression(guard); - expression(v, guard); - }); + if let Some(guard) = arm.guard.as_ref() { + v.expression(guard); + expression(v, guard); + }; v.block(&arm.body); walk_block(v, &arm.body); } diff --git a/schala-lang/language/src/parsing/mod.rs b/schala-lang/language/src/parsing/mod.rs index ec6d5b4..abfc267 100644 --- a/schala-lang/language/src/parsing/mod.rs +++ b/schala-lang/language/src/parsing/mod.rs @@ -1,3 +1,5 @@ +#![allow(clippy::upper_case_acronyms)] + //! # Parsing //! This module is where the recursive-descent parsing methods live. //! @@ -417,15 +419,10 @@ impl Parser { #[recursive_descent_method] fn type_body(&mut self) -> ParseResult { - let mut variants = Vec::new(); - variants.push(self.variant_specifier()?); - loop { - if let Pipe = self.token_handler.peek_kind() { + let mut variants = vec![self.variant_specifier()?]; + while let Pipe = self.token_handler.peek_kind() { self.token_handler.next(); variants.push(self.variant_specifier()?); - } else { - break; - } } Ok(TypeBody(variants)) } @@ -616,6 +613,7 @@ impl Parser { } // this implements Pratt parsing, see http://journal.stuffwithstuff.com/2011/03/19/pratt-parsers-expression-parsing-made-easy/ + #[allow(clippy::while_let_loop)] fn precedence_expr(&mut self, precedence: i32) -> ParseResult { let record = ParseRecord { production_name: "precedence_expr".to_string(), @@ -799,14 +797,11 @@ impl Parser { #[recursive_descent_method] fn qualified_identifier(&mut self) -> ParseResult>> { let mut components = vec![self.identifier()?]; - loop { - match (self.token_handler.peek_kind(), self.token_handler.peek_kind_n(1)) { - (Colon, Colon) => { - self.token_handler.next(); self.token_handler.next(); - components.push(self.identifier()?); - }, - _ => break, - } + + while let (Colon, Colon) = (self.token_handler.peek_kind(), self.token_handler.peek_kind_n(1)) { + self.token_handler.next(); + self.token_handler.next(); + components.push(self.identifier()?); } Ok(components) } diff --git a/schala-lang/language/src/parsing/test.rs b/schala-lang/language/src/parsing/test.rs index 1066a00..9e9a40e 100644 --- a/schala-lang/language/src/parsing/test.rs +++ b/schala-lang/language/src/parsing/test.rs @@ -1,4 +1,6 @@ #![cfg(test)] +#![allow(clippy::upper_case_acronyms)] + use std::rc::Rc; use crate::tokenizing::Location; diff --git a/schala-lang/language/src/symbol_table/resolver.rs b/schala-lang/language/src/symbol_table/resolver.rs index 14965e3..9727685 100644 --- a/schala-lang/language/src/symbol_table/resolver.rs +++ b/schala-lang/language/src/symbol_table/resolver.rs @@ -92,7 +92,7 @@ impl<'a> ASTVisitor for Resolver<'a> { self.symbol_table.id_to_fqsn.insert(qualified_name.id.clone(), fqsn); } - fn named_struct(&mut self, qualified_name: &QualifiedName, _fields: &Vec<(Rc, Expression)>) { + fn named_struct(&mut self, qualified_name: &QualifiedName, _fields: &[ (Rc, Expression) ]) { let fqsn = self.lookup_name_in_scope(qualified_name); self.symbol_table.id_to_fqsn.insert(qualified_name.id.clone(), fqsn); } diff --git a/schala-lang/language/src/tokenizing.rs b/schala-lang/language/src/tokenizing.rs index 2aff7e5..3568e4f 100644 --- a/schala-lang/language/src/tokenizing.rs +++ b/schala-lang/language/src/tokenizing.rs @@ -1,8 +1,9 @@ +#![allow(clippy::upper_case_acronyms)] + use itertools::Itertools; use std::{iter::{Iterator, Peekable}, convert::TryFrom, rc::Rc, fmt}; use std::convert::TryInto; - /// A location in a particular source file. Note that the /// sizes of the internal unsigned integer types limit /// the size of a source file to 2^32 lines of