From 59f8127eaa0cc19514df0dc6c15508a912d7901a Mon Sep 17 00:00:00 2001 From: Aleksey Yakovlev Date: Wed, 26 Jun 2024 15:24:25 +0700 Subject: [PATCH] clippy run --- src/cli/error.rs | 4 ---- src/cli/mod.rs | 11 +---------- src/compiler/ast/node.rs | 9 ++++----- src/compiler/cst/parser.rs | 8 +++++--- src/compiler/rst/compilation_context.rs | 7 ------- 5 files changed, 10 insertions(+), 29 deletions(-) diff --git a/src/cli/error.rs b/src/cli/error.rs index 4fe68d8..6954ffe 100644 --- a/src/cli/error.rs +++ b/src/cli/error.rs @@ -5,8 +5,6 @@ pub(crate) enum Error { UnknownCommand, FileWatcher(notify::Error), CantCrateOutputFile(std::io::Error), - CantReadInputFile(std::io::Error), - AstParsingFailed(crate::compiler::ast::Error), Compilation(crate::compiler::Error), } @@ -16,8 +14,6 @@ impl Display for Error { Error::UnknownCommand => write!(f, "Unknown command"), Error::FileWatcher(e) => write!(f, "File watching error: {}", e), Error::CantCrateOutputFile(e) => write!(f, "Can't create output file: {}", e), - Error::CantReadInputFile(e) => write!(f, "Can't read input file: {}", e), - Error::AstParsingFailed(e) => write!(f, "Ast parsing error: {}", e), Error::Compilation(e) => write!(f, "Compilation error: {}", e), } } diff --git a/src/cli/mod.rs b/src/cli/mod.rs index 87a3097..60c5904 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -59,16 +59,7 @@ pub(crate) fn run_cli() { fn handle_cli_error(cli_result: Result<(), Error>) { if cli_result.is_err() { - match cli_result.unwrap_err() { - Error::UnknownCommand => eprintln!("unknown command"), - Error::FileWatcher(_) => eprintln!("can't create watcher"), - Error::CantCrateOutputFile(_) => eprintln!("can't create output file"), - Error::CantReadInputFile(_) => eprintln!("can't read input file"), - Error::AstParsingFailed(_) => eprintln!("ast parsing error"), - Error::Compilation(compilation_error) => { - handle_compilation_error(compilation_error) - } - } + eprintln!("{}", cli_result.unwrap_err()); } } diff --git a/src/compiler/ast/node.rs b/src/compiler/ast/node.rs index 7d60ee5..b54b95e 100644 --- a/src/compiler/ast/node.rs +++ b/src/compiler/ast/node.rs @@ -28,8 +28,8 @@ pub(crate) enum AstNodeType { impl AstNodeType { pub(crate) fn must_capture_value(&self) -> bool { - match self { - AstNodeType::AtomUtf8 + matches!(self, + AstNodeType::AtomUtf8 | AstNodeType::AtomHex | AstNodeType::AtomFnName | AstNodeType::StatementConstName @@ -37,9 +37,8 @@ impl AstNodeType { | AstNodeType::AtomBaseNumberValue | AstNodeType::StatementFnName | AstNodeType::AtomFnParamIdentifier - | AstNodeType::AtomConst => true, - _ => false, - } + | AstNodeType::AtomConst + ) } } diff --git a/src/compiler/cst/parser.rs b/src/compiler/cst/parser.rs index 0451c78..a6ffdc5 100644 --- a/src/compiler/cst/parser.rs +++ b/src/compiler/cst/parser.rs @@ -255,9 +255,11 @@ fn parse_atom_hex_into(node: &AstNode, buf: &mut Vec) -> Result<(), Err node_type: AstNodeType::AtomHex, })?; - let bytes = - decode_bytes_from_string(content.as_str()).map_err(|x| Error::MalformedNodeValue { - message: format!("can't parse bytes {}", content), + let bytes = decode_bytes_from_string(content.as_str()) + .map_err(|_| { + Error::MalformedNodeValue { + message: format!("can't parse bytes {}", content), + } })?; for byte in bytes { diff --git a/src/compiler/rst/compilation_context.rs b/src/compiler/rst/compilation_context.rs index 3439ce7..802754c 100644 --- a/src/compiler/rst/compilation_context.rs +++ b/src/compiler/rst/compilation_context.rs @@ -116,13 +116,6 @@ impl CompilationContext { return self.native_function_index.find(name); } - pub(crate) fn get_parents(&self, context_id: u64) -> Option> { - return self - .local_contexts - .get(&context_id) - .map(|it| it.parents.clone()); - } - pub(crate) fn bind_parents(&mut self, context_id: u64, parents: Vec) { self.local_contexts.entry(context_id).or_insert_with(LocalCompilationContext::new);