fix/allow clippy errors

This commit is contained in:
Schrottkatze 2023-11-20 10:27:47 +01:00
parent 55acd88f0a
commit 8c52d3668e
9 changed files with 51 additions and 30 deletions

View file

@ -28,7 +28,8 @@ let_underscore_must_use = "warn"
manual_clamp = "warn" manual_clamp = "warn"
pedantic = "warn" pedantic = "warn"
str_to_string = "warn" str_to_string = "warn"
unneeded_field_patter = "warn" unneeded_field_pattern = "warn"
unnested_or_patterns = "warn"
allow_attributes_without_reason = "deny" allow_attributes_without_reason = "deny"
cast_lossles = "deny" cast_lossles = "deny"

View file

@ -8,6 +8,10 @@ pub const TRAIT_NUMERIC: &str = "Num";
pub const CMD_ADD: &str = "add"; 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 { pub fn initialise_globals() -> GlobalNamespace {
let ns = GlobalNamespace::init(); let ns = GlobalNamespace::init();

View file

@ -12,10 +12,7 @@ use codespan_reporting::{
use crate::{ use crate::{
builtins::initialise_globals, builtins::initialise_globals,
error::{ErrorKind, Errors}, error::{ErrorKind, Errors},
syntax::{ syntax::{check::check, parse_syntax, PipelineElement},
check::{self, check},
parse_syntax, PipelineElement,
},
typed::into_typed_repr, typed::into_typed_repr,
}; };
@ -70,7 +67,7 @@ impl<'a> Evaluator<'a> {
locs: errs, 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.errors.insert(file_id, errs);
self.curr_phase = EvalPhase::Failed; self.curr_phase = EvalPhase::Failed;
} else { } else {
self.curr_phase = EvalPhase::BareTyped(file_id, syntax.clone()) self.curr_phase = EvalPhase::BareTyped(file_id, syntax.clone());
} }
} }
EvalPhase::BareTyped(file_id, syntax) => { EvalPhase::BareTyped(file_id, syntax) => {
let ns = initialise_globals(); let ns = initialise_globals();
let r = into_typed_repr(&ns, syntax); let r = into_typed_repr(&ns, syntax);
if let Err(errs) = r { match r {
self.errors.insert(file_id, vec![errs]); Ok(typed) => {
self.curr_phase = EvalPhase::Failed; if self.cfg.debug_print_typed_repr {
} else { println!("Typed repr: {typed:#?}");
if self.cfg.debug_print_typed_repr { }
let typed = r.unwrap();
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<!, codespan_reporting::files::Error> { pub fn error_out(self) -> Result<!, codespan_reporting::files::Error> {
let Evaluator { let Evaluator { files, errors, .. } = self;
curr_phase,
files,
errors,
cfg,
} = self;
let writer = StandardStream::stderr(ColorChoice::Always); let writer = StandardStream::stderr(ColorChoice::Always);
let config = term::Config::default(); let config = term::Config::default();
for (file_id, errors) in errors.iter() { for (file_id, errors) in &errors {
let writer = &mut writer.lock(); let writer = &mut writer.lock();
for error in errors { for error in errors {
term::emit(writer, &config, &files, &error.into_diag(*file_id, &files))?; term::emit(writer, &config, &files, &error.into_diag(*file_id, &files))?;

View file

@ -5,9 +5,9 @@ use logos::Logos;
pub enum Token<'a> { pub enum Token<'a> {
#[regex("[\\w]+", |lex| lex.slice())] #[regex("[\\w]+", |lex| lex.slice())]
Word(&'a str), Word(&'a str),
#[regex("[\\d]+", priority = 2, callback = |lex| lex.slice().parse::<i64>().unwrap())] #[regex("[\\d]+", priority = 2, callback = |lex| lex.slice().parse::<i64>().expect("regex should only match valid integers. This is a bug."))]
IntLiteral(i64), IntLiteral(i64),
#[regex("[\\d]+\\.[\\d]+", |lex| lex.slice().parse::<f64>().unwrap())] #[regex("[\\d]+\\.[\\d]+", |lex| lex.slice().parse::<f64>().expect("regex should only match valid floats. This is a bug."))]
FloatLiteral(f64), FloatLiteral(f64),
#[regex(r#""([^"\\]|\\["\\bnfrt]|u[a-fA-F0-9]{4})*""#, |lex| lex.slice().to_owned())] #[regex(r#""([^"\\]|\\["\\bnfrt]|u[a-fA-F0-9]{4})*""#, |lex| lex.slice().to_owned())]
StringLiteral(String), StringLiteral(String),

View file

@ -1,4 +1,4 @@
#![feature(never_type)] #![feature(never_type, lint_reasons)]
use std::ops::Range; use std::ops::Range;
@ -10,7 +10,10 @@ mod args;
mod builtins; mod builtins;
mod error; mod error;
mod evaluator; mod evaluator;
#[allow(clippy::indexing_slicing, reason = "in logos, outside our control")]
mod lexer; mod lexer;
mod namespace; mod namespace;
mod syntax; mod syntax;
mod typed; mod typed;

View file

@ -20,8 +20,14 @@ impl<'a> TypeDef<'a> {
match def { match def {
InternalTypeDef::Single(id) => match id { InternalTypeDef::Single(id) => match id {
// safe to unwrap because this is only used with internal representations // safe to unwrap because this is only used with internal representations
TypeNamespaceId::Types(id) => TypeDef::Type(ns.get_type(*id).unwrap()), TypeNamespaceId::Types(id) => TypeDef::Type(
TypeNamespaceId::Traits(id) => TypeDef::Trait(ns.get_trait(*id).unwrap()), 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( InternalTypeDef::List(list) => TypeDef::List(
list.into_iter() list.into_iter()

View file

@ -1,4 +1,5 @@
#[cfg(test)] #[cfg(test)]
#[allow(clippy::unwrap_used, reason = "these are tests. they may unwrap.")]
mod test; mod test;
use crate::{ use crate::{

View file

@ -45,6 +45,10 @@ pub fn parse_syntax(input: &str) -> Result<Vec<PipelineElement>, Vec<logos::Span
match tok { match tok {
Token::Pipe => { Token::Pipe => {
if !partial_command.is_empty() { 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 let span = partial_command.first().unwrap().span.start
..partial_command.last().unwrap().span.end; ..partial_command.last().unwrap().span.end;
r.push(PipelineElement { r.push(PipelineElement {
@ -84,6 +88,10 @@ pub fn parse_syntax(input: &str) -> Result<Vec<PipelineElement>, Vec<logos::Span
} }
if !partial_command.is_empty() { if !partial_command.is_empty() {
#[allow(
clippy::unwrap_used,
reason = "this branch can only run if partial_command isn't empty"
)]
let span = let span =
partial_command.first().unwrap().span.start..partial_command.last().unwrap().span.end; partial_command.first().unwrap().span.start..partial_command.last().unwrap().span.end;
r.push(PipelineElement { r.push(PipelineElement {

View file

@ -31,6 +31,10 @@ pub enum LiteralKind {
} }
impl LiteralKind { impl LiteralKind {
#[allow(
clippy::unwrap_used,
reason = "these are fetched by type name constants used for keeping names consistent in codebase, which cannot be None"
)]
pub fn get_type<'a>(&self, ns: &'a GlobalNamespace) -> Type<'a> { pub fn get_type<'a>(&self, ns: &'a GlobalNamespace) -> Type<'a> {
match self { match self {
LiteralKind::Int(_) => ns.get_type_by_name(TYPE_INTEGER).unwrap(), LiteralKind::Int(_) => ns.get_type_by_name(TYPE_INTEGER).unwrap(),