From 8c52d3668ec1239855eec8fbb33b5a8e7b5ad159 Mon Sep 17 00:00:00 2001 From: Schrottkatze Date: Mon, 20 Nov 2023 10:27:47 +0100 Subject: [PATCH] fix/allow clippy errors --- Cargo.toml | 3 ++- src/builtins/mod.rs | 4 ++++ src/evaluator.rs | 42 +++++++++++++++++----------------------- src/lexer.rs | 4 ++-- src/main.rs | 5 ++++- src/namespace/typedef.rs | 10 ++++++++-- src/syntax/check.rs | 1 + src/syntax/mod.rs | 8 ++++++++ src/typed.rs | 4 ++++ 9 files changed, 51 insertions(+), 30 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f35a466..1d32042 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,7 +28,8 @@ let_underscore_must_use = "warn" manual_clamp = "warn" pedantic = "warn" str_to_string = "warn" -unneeded_field_patter = "warn" +unneeded_field_pattern = "warn" +unnested_or_patterns = "warn" allow_attributes_without_reason = "deny" cast_lossles = "deny" diff --git a/src/builtins/mod.rs b/src/builtins/mod.rs index 375905d..45c211b 100644 --- a/src/builtins/mod.rs +++ b/src/builtins/mod.rs @@ -8,6 +8,10 @@ pub const TRAIT_NUMERIC: &str = "Num"; pub const CMD_ADD: &str = "add"; +#[allow( + clippy::unwrap_used, + reason = "Errs can only be returned in case of duplicate names in the same namespace, which will not happen here" +)] pub fn initialise_globals() -> GlobalNamespace { let ns = GlobalNamespace::init(); diff --git a/src/evaluator.rs b/src/evaluator.rs index f1f6832..0cad793 100644 --- a/src/evaluator.rs +++ b/src/evaluator.rs @@ -12,10 +12,7 @@ use codespan_reporting::{ use crate::{ builtins::initialise_globals, error::{ErrorKind, Errors}, - syntax::{ - check::{self, check}, - parse_syntax, PipelineElement, - }, + syntax::{check::check, parse_syntax, PipelineElement}, typed::into_typed_repr, }; @@ -70,7 +67,7 @@ impl<'a> Evaluator<'a> { locs: errs, }], ); - self.curr_phase = EvalPhase::Failed + self.curr_phase = EvalPhase::Failed; } }; } @@ -87,42 +84,39 @@ impl<'a> Evaluator<'a> { self.errors.insert(file_id, errs); self.curr_phase = EvalPhase::Failed; } else { - self.curr_phase = EvalPhase::BareTyped(file_id, syntax.clone()) + self.curr_phase = EvalPhase::BareTyped(file_id, syntax.clone()); } } EvalPhase::BareTyped(file_id, syntax) => { let ns = initialise_globals(); let r = into_typed_repr(&ns, syntax); - if let Err(errs) = r { - self.errors.insert(file_id, vec![errs]); - self.curr_phase = EvalPhase::Failed; - } else { - if self.cfg.debug_print_typed_repr { - let typed = r.unwrap(); - println!("Typed repr: {typed:#?}"); - } + match r { + Ok(typed) => { + if self.cfg.debug_print_typed_repr { + println!("Typed repr: {typed:#?}"); + } - todo!() + todo!() + } + Err(errs) => { + self.errors.insert(file_id, vec![errs]); + self.curr_phase = EvalPhase::Failed; + } } } - EvalPhase::Failed => self.error_out().unwrap(), + EvalPhase::Failed => self.error_out().expect("unable to print errors"), } - self.next() + self.next(); } pub fn error_out(self) -> Result { - let Evaluator { - curr_phase, - files, - errors, - cfg, - } = self; + let Evaluator { files, errors, .. } = self; let writer = StandardStream::stderr(ColorChoice::Always); let config = term::Config::default(); - for (file_id, errors) in errors.iter() { + for (file_id, errors) in &errors { let writer = &mut writer.lock(); for error in errors { term::emit(writer, &config, &files, &error.into_diag(*file_id, &files))?; diff --git a/src/lexer.rs b/src/lexer.rs index a8b9a31..917a4e9 100644 --- a/src/lexer.rs +++ b/src/lexer.rs @@ -5,9 +5,9 @@ use logos::Logos; pub enum Token<'a> { #[regex("[\\w]+", |lex| lex.slice())] Word(&'a str), - #[regex("[\\d]+", priority = 2, callback = |lex| lex.slice().parse::().unwrap())] + #[regex("[\\d]+", priority = 2, callback = |lex| lex.slice().parse::().expect("regex should only match valid integers. This is a bug."))] IntLiteral(i64), - #[regex("[\\d]+\\.[\\d]+", |lex| lex.slice().parse::().unwrap())] + #[regex("[\\d]+\\.[\\d]+", |lex| lex.slice().parse::().expect("regex should only match valid floats. This is a bug."))] FloatLiteral(f64), #[regex(r#""([^"\\]|\\["\\bnfrt]|u[a-fA-F0-9]{4})*""#, |lex| lex.slice().to_owned())] StringLiteral(String), diff --git a/src/main.rs b/src/main.rs index fe63cf2..c289f37 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,4 @@ -#![feature(never_type)] +#![feature(never_type, lint_reasons)] use std::ops::Range; @@ -10,7 +10,10 @@ mod args; mod builtins; mod error; mod evaluator; + +#[allow(clippy::indexing_slicing, reason = "in logos, outside our control")] mod lexer; + mod namespace; mod syntax; mod typed; diff --git a/src/namespace/typedef.rs b/src/namespace/typedef.rs index 6c468d7..279a8be 100644 --- a/src/namespace/typedef.rs +++ b/src/namespace/typedef.rs @@ -20,8 +20,14 @@ impl<'a> TypeDef<'a> { match def { InternalTypeDef::Single(id) => match id { // safe to unwrap because this is only used with internal representations - TypeNamespaceId::Types(id) => TypeDef::Type(ns.get_type(*id).unwrap()), - TypeNamespaceId::Traits(id) => TypeDef::Trait(ns.get_trait(*id).unwrap()), + TypeNamespaceId::Types(id) => TypeDef::Type( + ns.get_type(*id) + .expect("Incorrect internal type id. This is a bug."), + ), + TypeNamespaceId::Traits(id) => TypeDef::Trait( + ns.get_trait(*id) + .expect("Incorrect internal trait id. This is a bug."), + ), }, InternalTypeDef::List(list) => TypeDef::List( list.into_iter() diff --git a/src/syntax/check.rs b/src/syntax/check.rs index 7f68c7d..5b30ccf 100644 --- a/src/syntax/check.rs +++ b/src/syntax/check.rs @@ -1,4 +1,5 @@ #[cfg(test)] +#[allow(clippy::unwrap_used, reason = "these are tests. they may unwrap.")] mod test; use crate::{ diff --git a/src/syntax/mod.rs b/src/syntax/mod.rs index a43aaac..34787c4 100644 --- a/src/syntax/mod.rs +++ b/src/syntax/mod.rs @@ -45,6 +45,10 @@ pub fn parse_syntax(input: &str) -> Result, Vec { if !partial_command.is_empty() { + #[allow( + clippy::unwrap_used, + reason = "this branch can only run if partial_command isn't empty" + )] let span = partial_command.first().unwrap().span.start ..partial_command.last().unwrap().span.end; r.push(PipelineElement { @@ -84,6 +88,10 @@ pub fn parse_syntax(input: &str) -> Result, Vec(&self, ns: &'a GlobalNamespace) -> Type<'a> { match self { LiteralKind::Int(_) => ns.get_type_by_name(TYPE_INTEGER).unwrap(),