Run clippy

This commit is contained in:
Greg Shuflin 2021-11-14 03:27:30 -08:00
parent 94ee3e1897
commit da4990107c
6 changed files with 19 additions and 33 deletions

View File

@ -39,12 +39,10 @@ pub fn walk_block<V: ASTVisitor>(v: &mut V, block: &Block) {
Import(ref import_spec) => { Import(ref import_spec) => {
v.import(import_spec); v.import(import_spec);
} }
Flow(ref flow_control) => match flow_control { Flow(ref flow_control) =>
FlowControl::Return(Some(ref retval)) => { if let FlowControl::Return(Some(ref retval)) = flow_control {
walk_expression(v, retval); walk_expression(v, retval);
} },
_ => (),
},
} }
} }
} }

View File

@ -6,9 +6,9 @@
//! It defines the `Schala` type, which contains the state for a Schala REPL, and implements //! It defines the `Schala` type, which contains the state for a Schala REPL, and implements
//! `ProgrammingLanguageInterface` and the chain of compiler passes for it. //! `ProgrammingLanguageInterface` and the chain of compiler passes for it.
extern crate schala_repl;
extern crate schala_lang_codegen;
extern crate derivative; extern crate derivative;
extern crate schala_lang_codegen;
extern crate schala_repl;
#[macro_use] #[macro_use]
mod util; mod util;

View File

@ -26,10 +26,7 @@ impl Parser {
schala_parser::program(input, self).map_err(|err: peg::error::ParseError<LineCol>| { schala_parser::program(input, self).map_err(|err: peg::error::ParseError<LineCol>| {
let msg = err.to_string(); let msg = err.to_string();
ParseError { ParseError { msg, location: err.location.offset.into() }
msg,
location: err.location.offset.into(),
}
}) })
} }
@ -91,14 +88,14 @@ peg::parser! {
ImportSpecifier { ImportSpecifier {
id: parser.fresh(), id: parser.fresh(),
path_components, path_components,
imported_names: suffix.unwrap_or_else(|| ImportedNames::LastOfPath) imported_names: suffix.unwrap_or(ImportedNames::LastOfPath)
} }
} }
rule path_components() -> Vec<Rc<String>> = rule path_components() -> Vec<Rc<String>> =
"::"? name:identifier() rest:path_component()* { "::"? name:identifier() rest:path_component()* {
let mut items = vec![rc_string(name)]; 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 items
} }
@ -217,7 +214,7 @@ peg::parser! {
__ kind:expression_kind(true, parser) _ type_anno:type_anno()? { Expression { id: parser.fresh(), type_anno, kind } } __ kind:expression_kind(true, parser) _ type_anno:type_anno()? { Expression { id: parser.fresh(), type_anno, kind } }
rule expression_no_struct(parser: &mut Parser) -> Expression = 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 = rule expression_kind(struct_ok: bool, parser: &mut Parser) -> ExpressionKind =
precedence_expr(struct_ok, parser) precedence_expr(struct_ok, parser)
@ -568,11 +565,7 @@ impl BinopSequence {
parser: &mut Parser, parser: &mut Parser,
) -> Expression { ) -> Expression {
let mut lhs = Expression::new(parser.fresh(), lhs); let mut lhs = Expression::new(parser.fresh(), lhs);
loop { while let Some((next_op, next_rhs)) = rest.pop() {
let (next_op, next_rhs) = match rest.pop() {
Some((a, b)) => (a, b),
None => break,
};
let new_precedence = next_op.get_precedence(); let new_precedence = next_op.get_precedence();
if precedence >= new_precedence { if precedence >= new_precedence {
rest.push((next_op, next_rhs)); rest.push((next_op, next_rhs));

View File

@ -4,9 +4,7 @@ use schala_repl::{
}; };
use stopwatch::Stopwatch; use stopwatch::Stopwatch;
use crate::{ use crate::{error::SchalaError, parsing, reduced_ir, symbol_table, tree_walk_eval, type_inference};
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. /// All the state necessary to parse and execute a Schala program are stored in this struct.
pub struct Schala<'a> { pub struct Schala<'a> {
@ -127,7 +125,7 @@ impl SourceReference {
pub(crate) fn load_new_source(&mut self, source: &str) { pub(crate) fn load_new_source(&mut self, source: &str) {
self.newline_offsets = vec![]; self.newline_offsets = vec![];
for (offset, ch) in source.as_bytes().iter().enumerate() { for (offset, ch) in source.as_bytes().iter().enumerate() {
if *ch == ('\n' as u8) { if *ch == b'\n' {
self.newline_offsets.push(offset); 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()); self.run_pipeline(source, request.config).map_err(|schala_err| schala_err.display());
let total_duration = sw.elapsed(); 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() .into_iter()
.map(|(label, duration)| (label.to_string(), duration)) .map(|(label, duration)| (label.to_string(), duration))
.collect(); .collect();

View File

@ -55,7 +55,7 @@ impl<'a> ScopeResolver<'a> {
if components.len() == 1 { if components.len() == 1 {
match name_type { match name_type {
Some(NameType::Import(fqsn)) => { 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 { if let Some(def_id) = def_id {
self.symbol_table.id_to_def.insert(*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)) => { Some(NameType::LocalFunction(item_id)) => {
let def_id = self.symbol_table.id_to_def.get(item_id); let def_id = self.symbol_table.id_to_def.get(item_id);
if let Some(def_id) = def_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); self.symbol_table.id_to_def.insert(*id, def_id);
} }
} }
Some(NameType::LocalVariable(item_id)) => { Some(NameType::LocalVariable(item_id)) => {
let def_id = self.symbol_table.id_to_def.get(item_id); let def_id = self.symbol_table.id_to_def.get(item_id);
if let Some(def_id) = def_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); 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); self.symbol_table.id_to_def.insert(*id, def_id);
}, },
} }
} else { } else if let Some(def_id) = def_id {
if let Some(def_id) = def_id { self.symbol_table.id_to_def.insert(*id, def_id);
self.symbol_table.id_to_def.insert(*id, def_id);
}
} }
} }
} }

View File

@ -67,8 +67,7 @@ impl<'a, 'b> Evaluator<'a, 'b> {
if self.early_returning { if self.early_returning {
break; break;
} }
if let Some(_) = self.loop_control { if self.loop_control.is_some() {
println!("We here?");
break; break;
} }
} }