From 5f4546d6adf008775659ff2ceea9cdbdde1f3826 Mon Sep 17 00:00:00 2001 From: Pineapple Date: Mon, 18 Mar 2024 00:02:27 -0700 Subject: [PATCH] Fix clippy lints --- numbat-cli/src/completer.rs | 5 +---- numbat-cli/src/main.rs | 3 +-- numbat-wasm/src/jquery_terminal_formatter.rs | 18 +++++++++--------- numbat-wasm/src/lib.rs | 4 ++-- numbat/src/lib.rs | 2 +- numbat/src/resolver.rs | 7 ++----- numbat/src/tokenizer.rs | 1 + numbat/src/typechecker.rs | 1 + 8 files changed, 18 insertions(+), 23 deletions(-) diff --git a/numbat-cli/src/completer.rs b/numbat-cli/src/completer.rs index e3b77330..3e85e43c 100644 --- a/numbat-cli/src/completer.rs +++ b/numbat-cli/src/completer.rs @@ -1,10 +1,7 @@ use std::sync::{Arc, Mutex}; use numbat::{unicode_input::UNICODE_INPUT, Context}; -use rustyline::{ - self, - completion::{extract_word, Completer, Pair}, -}; +use rustyline::completion::{extract_word, Completer, Pair}; pub struct NumbatCompleter { pub context: Arc>, diff --git a/numbat-cli/src/main.rs b/numbat-cli/src/main.rs index 4bb15c51..9bbb7f71 100644 --- a/numbat-cli/src/main.rs +++ b/numbat-cli/src/main.rs @@ -22,8 +22,7 @@ use anyhow::{bail, Context as AnyhowContext, Result}; use clap::Parser; use rustyline::config::Configurer; use rustyline::{ - self, error::ReadlineError, history::DefaultHistory, Completer, Editor, Helper, Hinter, - Validator, + error::ReadlineError, history::DefaultHistory, Completer, Editor, Helper, Hinter, Validator, }; use rustyline::{EventHandler, Highlighter, KeyCode, KeyEvent, Modifiers}; diff --git a/numbat-wasm/src/jquery_terminal_formatter.rs b/numbat-wasm/src/jquery_terminal_formatter.rs index 2b60aae4..cc30fba0 100644 --- a/numbat-wasm/src/jquery_terminal_formatter.rs +++ b/numbat-wasm/src/jquery_terminal_formatter.rs @@ -11,13 +11,13 @@ pub fn jt_format(class: Option<&str>, content: &str) -> String { } let content = html_escape::encode_text(content) - .replace("[", "[") - .replace("]", "]"); + .replace('[', "[") + .replace(']', "]"); if let Some(class) = class { format!("[[;;;hl-{class}]{content}]") } else { - content.into() + content } } @@ -68,19 +68,19 @@ impl std::io::Write for JqueryTerminalWriter { fn write(&mut self, buf: &[u8]) -> std::io::Result { if let Some(color) = &self.color { if color.fg() == Some(&Color::Red) { - self.buffer.write("[[;;;hl-diagnostic-red]".as_bytes())?; + self.buffer.write_all("[[;;;hl-diagnostic-red]".as_bytes())?; let size = self.buffer.write(buf)?; - self.buffer.write("]".as_bytes())?; + self.buffer.write_all("]".as_bytes())?; Ok(size) } else if color.fg() == Some(&Color::Blue) { - self.buffer.write("[[;;;hl-diagnostic-blue]".as_bytes())?; + self.buffer.write_all("[[;;;hl-diagnostic-blue]".as_bytes())?; let size = self.buffer.write(buf)?; - self.buffer.write("]".as_bytes())?; + self.buffer.write_all("]".as_bytes())?; Ok(size) } else if color.bold() { - self.buffer.write("[[;;;hl-diagnostic-bold]".as_bytes())?; + self.buffer.write_all("[[;;;hl-diagnostic-bold]".as_bytes())?; let size = self.buffer.write(buf)?; - self.buffer.write("]".as_bytes())?; + self.buffer.write_all("]".as_bytes())?; Ok(size) } else { self.buffer.write(buf) diff --git a/numbat-wasm/src/lib.rs b/numbat-wasm/src/lib.rs index fd69af64..7b614ddc 100644 --- a/numbat-wasm/src/lib.rs +++ b/numbat-wasm/src/lib.rs @@ -79,7 +79,7 @@ impl Numbat { FormatType::JqueryTerminal => Box::new(JqueryTerminalFormatter {}), FormatType::Html => Box::new(HtmlFormatter {}), }; - fmt.format(&markup, indent).into() + fmt.format(markup, indent) } pub fn interpret(&mut self, code: &str) -> InterpreterOutput { @@ -102,7 +102,7 @@ impl Numbat { match self .ctx - .interpret_with_settings(&mut settings, &code, CodeSource::Text) + .interpret_with_settings(&mut settings, code, CodeSource::Text) { Ok((statements, result)) => { // Pretty print diff --git a/numbat/src/lib.rs b/numbat/src/lib.rs index e478a636..ebf4b19f 100644 --- a/numbat/src/lib.rs +++ b/numbat/src/lib.rs @@ -101,7 +101,7 @@ pub struct Context { } impl Context { - pub fn new(module_importer: impl ModuleImporter + Send + Sync + 'static) -> Self { + pub fn new(module_importer: impl ModuleImporter + 'static) -> Self { Context { prefix_transformer: Transformer::new(), typechecker: TypeChecker::default(), diff --git a/numbat/src/resolver.rs b/numbat/src/resolver.rs index 28073aa9..1da275df 100644 --- a/numbat/src/resolver.rs +++ b/numbat/src/resolver.rs @@ -53,7 +53,7 @@ pub struct Resolver { } impl Resolver { - pub(crate) fn new(importer: impl ModuleImporter + Send + 'static) -> Self { + pub(crate) fn new(importer: impl ModuleImporter + 'static) -> Self { Self { importer: Arc::new(importer), files: SimpleFiles::new(), @@ -136,10 +136,7 @@ impl Resolver { #[cfg(test)] mod tests { - use crate::{ - ast::{Expression, Statement}, - number::Number, - }; + use crate::{ast::Expression, number::Number}; use super::*; diff --git a/numbat/src/tokenizer.rs b/numbat/src/tokenizer.rs index be5f3d9b..c6eb986b 100644 --- a/numbat/src/tokenizer.rs +++ b/numbat/src/tokenizer.rs @@ -664,6 +664,7 @@ pub fn tokenize(input: &str, code_source_id: usize) -> Result> { } #[cfg(test)] +#[allow(clippy::type_complexity)] fn tokenize_reduced(input: &str) -> Result, String> { Ok(tokenize(input, 0) .map_err(|e| { diff --git a/numbat/src/typechecker.rs b/numbat/src/typechecker.rs index f1a48583..48bb34cb 100644 --- a/numbat/src/typechecker.rs +++ b/numbat/src/typechecker.rs @@ -1,3 +1,4 @@ +#![allow(clippy::result_large_err)] use std::{ collections::{HashMap, HashSet}, error::Error,