From da4990107cf7a8e648788e03f36c70efeafda62d Mon Sep 17 00:00:00 2001 From: Greg Shuflin Date: Sun, 14 Nov 2021 03:27:30 -0800 Subject: [PATCH] Run clippy --- schala-lang/language/src/ast/visitor.rs | 8 +++----- schala-lang/language/src/lib.rs | 4 ++-- schala-lang/language/src/parsing/new.rs | 17 +++++------------ schala-lang/language/src/schala.rs | 8 +++----- .../language/src/symbol_table/resolver.rs | 12 +++++------- .../language/src/tree_walk_eval/evaluator.rs | 3 +-- 6 files changed, 19 insertions(+), 33 deletions(-) diff --git a/schala-lang/language/src/ast/visitor.rs b/schala-lang/language/src/ast/visitor.rs index 11baf9c..3ca88c9 100644 --- a/schala-lang/language/src/ast/visitor.rs +++ b/schala-lang/language/src/ast/visitor.rs @@ -39,12 +39,10 @@ pub fn walk_block(v: &mut V, block: &Block) { Import(ref import_spec) => { v.import(import_spec); } - Flow(ref flow_control) => match flow_control { - FlowControl::Return(Some(ref retval)) => { + Flow(ref flow_control) => + if let FlowControl::Return(Some(ref retval)) = flow_control { walk_expression(v, retval); - } - _ => (), - }, + }, } } } diff --git a/schala-lang/language/src/lib.rs b/schala-lang/language/src/lib.rs index 3ac261d..966facf 100644 --- a/schala-lang/language/src/lib.rs +++ b/schala-lang/language/src/lib.rs @@ -6,9 +6,9 @@ //! It defines the `Schala` type, which contains the state for a Schala REPL, and implements //! `ProgrammingLanguageInterface` and the chain of compiler passes for it. -extern crate schala_repl; -extern crate schala_lang_codegen; extern crate derivative; +extern crate schala_lang_codegen; +extern crate schala_repl; #[macro_use] mod util; diff --git a/schala-lang/language/src/parsing/new.rs b/schala-lang/language/src/parsing/new.rs index 1735cfd..428e4b4 100644 --- a/schala-lang/language/src/parsing/new.rs +++ b/schala-lang/language/src/parsing/new.rs @@ -26,10 +26,7 @@ impl Parser { schala_parser::program(input, self).map_err(|err: peg::error::ParseError| { let msg = err.to_string(); - ParseError { - msg, - location: err.location.offset.into(), - } + ParseError { msg, location: err.location.offset.into() } }) } @@ -91,14 +88,14 @@ peg::parser! { ImportSpecifier { id: parser.fresh(), path_components, - imported_names: suffix.unwrap_or_else(|| ImportedNames::LastOfPath) + imported_names: suffix.unwrap_or(ImportedNames::LastOfPath) } } rule path_components() -> Vec> = "::"? name:identifier() rest:path_component()* { let mut items = vec![rc_string(name)]; - items.extend(rest.into_iter().map(|n| rc_string(n))); + items.extend(rest.into_iter().map(rc_string)); items } @@ -217,7 +214,7 @@ peg::parser! { __ kind:expression_kind(true, parser) _ type_anno:type_anno()? { Expression { id: parser.fresh(), type_anno, kind } } rule expression_no_struct(parser: &mut Parser) -> Expression = - __ kind:expression_kind(false, parser) { Expression { id: parser.fresh(), type_anno: None, kind: kind } } + __ kind:expression_kind(false, parser) { Expression { id: parser.fresh(), type_anno: None, kind } } rule expression_kind(struct_ok: bool, parser: &mut Parser) -> ExpressionKind = precedence_expr(struct_ok, parser) @@ -568,11 +565,7 @@ impl BinopSequence { parser: &mut Parser, ) -> Expression { let mut lhs = Expression::new(parser.fresh(), lhs); - loop { - let (next_op, next_rhs) = match rest.pop() { - Some((a, b)) => (a, b), - None => break, - }; + while let Some((next_op, next_rhs)) = rest.pop() { let new_precedence = next_op.get_precedence(); if precedence >= new_precedence { rest.push((next_op, next_rhs)); diff --git a/schala-lang/language/src/schala.rs b/schala-lang/language/src/schala.rs index 6d55148..03cb9fb 100644 --- a/schala-lang/language/src/schala.rs +++ b/schala-lang/language/src/schala.rs @@ -4,9 +4,7 @@ use schala_repl::{ }; use stopwatch::Stopwatch; -use crate::{ - error::SchalaError, parsing, reduced_ir, symbol_table, tree_walk_eval, type_inference, -}; +use crate::{error::SchalaError, parsing, reduced_ir, symbol_table, tree_walk_eval, type_inference}; /// All the state necessary to parse and execute a Schala program are stored in this struct. pub struct Schala<'a> { @@ -127,7 +125,7 @@ impl SourceReference { pub(crate) fn load_new_source(&mut self, source: &str) { self.newline_offsets = vec![]; for (offset, ch) in source.as_bytes().iter().enumerate() { - if *ch == ('\n' as u8) { + if *ch == b'\n' { self.newline_offsets.push(offset); } } @@ -194,7 +192,7 @@ impl<'a> ProgrammingLanguageInterface for Schala<'a> { self.run_pipeline(source, request.config).map_err(|schala_err| schala_err.display()); let total_duration = sw.elapsed(); - let stage_durations: Vec<_> = std::mem::replace(&mut self.timings, vec![]) + let stage_durations: Vec<_> = std::mem::take(&mut self.timings) .into_iter() .map(|(label, duration)| (label.to_string(), duration)) .collect(); diff --git a/schala-lang/language/src/symbol_table/resolver.rs b/schala-lang/language/src/symbol_table/resolver.rs index 32f7ca1..0811fdd 100644 --- a/schala-lang/language/src/symbol_table/resolver.rs +++ b/schala-lang/language/src/symbol_table/resolver.rs @@ -55,7 +55,7 @@ impl<'a> ScopeResolver<'a> { if components.len() == 1 { match name_type { Some(NameType::Import(fqsn)) => { - let def_id = self.symbol_table.symbol_trie.lookup(&fqsn); + let def_id = self.symbol_table.symbol_trie.lookup(fqsn); if let Some(def_id) = def_id { self.symbol_table.id_to_def.insert(*id, def_id); @@ -71,14 +71,14 @@ impl<'a> ScopeResolver<'a> { Some(NameType::LocalFunction(item_id)) => { let def_id = self.symbol_table.id_to_def.get(item_id); if let Some(def_id) = def_id { - let def_id = def_id.clone(); + let def_id = *def_id; self.symbol_table.id_to_def.insert(*id, def_id); } } Some(NameType::LocalVariable(item_id)) => { let def_id = self.symbol_table.id_to_def.get(item_id); if let Some(def_id) = def_id { - let def_id = def_id.clone(); + let def_id = *def_id; self.symbol_table.id_to_def.insert(*id, def_id); } } @@ -87,10 +87,8 @@ impl<'a> ScopeResolver<'a> { self.symbol_table.id_to_def.insert(*id, def_id); }, } - } else { - if let Some(def_id) = def_id { - self.symbol_table.id_to_def.insert(*id, def_id); - } + } else if let Some(def_id) = def_id { + self.symbol_table.id_to_def.insert(*id, def_id); } } } diff --git a/schala-lang/language/src/tree_walk_eval/evaluator.rs b/schala-lang/language/src/tree_walk_eval/evaluator.rs index 279eb16..843b5a7 100644 --- a/schala-lang/language/src/tree_walk_eval/evaluator.rs +++ b/schala-lang/language/src/tree_walk_eval/evaluator.rs @@ -67,8 +67,7 @@ impl<'a, 'b> Evaluator<'a, 'b> { if self.early_returning { break; } - if let Some(_) = self.loop_control { - println!("We here?"); + if self.loop_control.is_some() { break; } }