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"
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"

View file

@ -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();

View file

@ -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 {
match r {
Ok(typed) => {
if self.cfg.debug_print_typed_repr {
let typed = r.unwrap();
println!("Typed repr: {typed:#?}");
}
todo!()
}
Err(errs) => {
self.errors.insert(file_id, vec![errs]);
self.curr_phase = EvalPhase::Failed;
}
EvalPhase::Failed => self.error_out().unwrap(),
}
self.next()
}
EvalPhase::Failed => self.error_out().expect("unable to print errors"),
}
self.next();
}
pub fn error_out(self) -> Result<!, codespan_reporting::files::Error> {
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))?;

View file

@ -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::<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),
#[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),
#[regex(r#""([^"\\]|\\["\\bnfrt]|u[a-fA-F0-9]{4})*""#, |lex| lex.slice().to_owned())]
StringLiteral(String),

View file

@ -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;

View file

@ -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()

View file

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

View file

@ -45,6 +45,10 @@ pub fn parse_syntax(input: &str) -> Result<Vec<PipelineElement>, Vec<logos::Span
match tok {
Token::Pipe => {
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<PipelineElement>, Vec<logos::Span
}
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 {

View file

@ -31,6 +31,10 @@ pub enum 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> {
match self {
LiteralKind::Int(_) => ns.get_type_by_name(TYPE_INTEGER).unwrap(),