Skip to content

Commit a6fe813

Browse files
committed
fix clippy lints
1 parent 3a79d86 commit a6fe813

File tree

8 files changed

+27
-103
lines changed

8 files changed

+27
-103
lines changed

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ regex = "1"
1313
itertools = "0.10"
1414
thiserror = "1.0"
1515
maplit = "1.0"
16-
codespan-reporting = "0.11"
1716
logos = "0.12"
1817

1918
serde = {version = "1.0", features = ["derive"]}

examples/errors.rs

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/ast.rs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,6 @@ use serde::{Deserialize, Serialize};
55
#[derive(Eq, PartialEq, Clone, Copy, Serialize, Deserialize)]
66
pub struct Span(pub usize, pub usize);
77

8-
pub trait MaybeSpanned {
9-
fn try_span(&self) -> Option<Span>;
10-
}
11-
12-
impl MaybeSpanned for Span {
13-
fn try_span(&self) -> Option<Span> {
14-
Some(*self)
15-
}
16-
}
17-
18-
pub fn span_between(a: impl MaybeSpanned, b: impl MaybeSpanned) -> Option<Span> {
19-
Some(Span(a.try_span()?.0, b.try_span()?.1))
20-
}
21-
228
impl std::fmt::Display for Span {
239
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
2410
write!(f, "{}..{}", self.0, self.1)
@@ -65,11 +51,6 @@ pub enum SimplExpr {
6551
JsonAccess(Span, Box<SimplExpr>, Box<SimplExpr>),
6652
FunctionCall(Span, String, Vec<SimplExpr>),
6753
}
68-
impl MaybeSpanned for SimplExpr {
69-
fn try_span(&self) -> Option<Span> {
70-
Some(self.span())
71-
}
72-
}
7354

7455
impl std::fmt::Display for SimplExpr {
7556
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {

src/dynval.rs

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::ast::{MaybeSpanned, Span};
1+
use crate::ast::Span;
22
use itertools::Itertools;
33
use serde::{Deserialize, Serialize};
44
use std::{convert::TryFrom, fmt, iter::FromIterator};
@@ -26,12 +26,6 @@ impl ConversionError {
2626
#[derive(Clone, Deserialize, Serialize, Default, Eq)]
2727
pub struct DynVal(pub String, pub Option<Span>);
2828

29-
impl MaybeSpanned for DynVal {
30-
fn try_span(&self) -> Option<Span> {
31-
self.1
32-
}
33-
}
34-
3529
impl From<String> for DynVal {
3630
fn from(s: String) -> Self {
3731
DynVal(s, None)
@@ -98,7 +92,7 @@ impl_try_from!(impl From<DynVal> {
9892
for f64 => |x| x.as_f64();
9993
for i32 => |x| x.as_i32();
10094
for bool => |x| x.as_bool();
101-
for Vec<String> => |x| x.as_vec();
95+
//for Vec<String> => |x| x.as_vec();
10296
});
10397

10498
impl_primval_from!(bool, i32, u32, f32, u8, f64, &str);
@@ -145,26 +139,24 @@ impl DynVal {
145139
self.0.parse().map_err(|e| ConversionError::new(self.clone(), "bool", Box::new(e)))
146140
}
147141

148-
pub fn as_vec(&self) -> Result<Vec<String>> {
149-
match self.0.strip_prefix('[').and_then(|x| x.strip_suffix(']')) {
150-
Some(content) => {
151-
let mut items: Vec<String> = content.split(',').map(|x: &str| x.to_string()).collect();
152-
let mut removed = 0;
153-
for times_ran in 0..items.len() {
154-
// escapes `,` if there's a `\` before em
155-
if items[times_ran - removed].ends_with('\\') {
156-
items[times_ran - removed].pop();
157-
let it = items.remove((times_ran + 1) - removed);
158-
items[times_ran - removed] += ",";
159-
items[times_ran - removed] += &it;
160-
removed += 1;
161-
}
162-
}
163-
Ok(items)
164-
}
165-
None => Err(ConversionError { value: self.clone(), target_type: "vec", source: None }),
166-
}
167-
}
142+
// pub fn as_vec(&self) -> Result<Vec<String>> {
143+
// match self.0.strip_prefix('[').and_then(|x| x.strip_suffix(']')) {
144+
// Some(content) => {
145+
// let mut items: Vec<String> = content.split(',').map(|x: &str| x.to_string()).collect();
146+
// let mut removed = 0;
147+
// for times_ran in 0..items.len() {
148+
//// escapes `,` if there's a `\` before em
149+
// if items[times_ran - removed].ends_with('\\') {
150+
// items[times_ran - removed].pop();
151+
// let it = items.remove((times_ran + 1) - removed);
152+
// items[times_ran - removed] += ",";
153+
// items[times_ran - removed] += &it;
154+
// removed += 1;
155+
//}
156+
// Ok(items)
157+
//}
158+
// None => Err(ConversionError { value: self.clone(), target_type: "vec", source: None }),
159+
//}
168160

169161
pub fn as_json_value(&self) -> Result<serde_json::Value> {
170162
serde_json::from_str::<serde_json::Value>(&self.0)

src/error.rs

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use crate::{
33
dynval,
44
parser::lexer::{self, LexicalError},
55
};
6-
use codespan_reporting::diagnostic;
76

87
pub type Result<T> = std::result::Result<T, Error>;
98
#[derive(thiserror::Error, Debug)]
@@ -42,32 +41,6 @@ impl Error {
4241
_ => None,
4342
}
4443
}
45-
46-
pub fn pretty_diagnostic(&self) -> diagnostic::Diagnostic<usize> {
47-
let diag = diagnostic::Diagnostic::error().with_message(format!("{}", self));
48-
if let Some(span) = self.get_span() {
49-
diag.with_labels(vec![diagnostic::Label::primary(0, span.0..span.1)])
50-
} else {
51-
diag
52-
}
53-
}
54-
}
55-
56-
pub trait ErrorExt {
57-
fn at(self, span: Span) -> Error;
58-
}
59-
impl ErrorExt for Box<dyn std::error::Error> {
60-
fn at(self, span: Span) -> Error {
61-
Error::Spanned(span, self)
62-
}
63-
}
64-
pub trait ResultExt<T> {
65-
fn at(self, span: Span) -> std::result::Result<T, Error>;
66-
}
67-
impl<T, E: std::error::Error + 'static> ResultExt<T> for std::result::Result<T, E> {
68-
fn at(self, span: Span) -> std::result::Result<T, Error> {
69-
self.map_err(|x| Error::Spanned(span, Box::new(x)))
70-
}
7144
}
7245

7346
fn get_parse_error_span(err: &lalrpop_util::ParseError<usize, lexer::Token, lexer::LexicalError>) -> Option<Span> {

src/eval.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ type VarName = String;
5151

5252
pub trait FunctionSource {
5353
type Err;
54-
fn run_fn(&self, name: &str, args: &Vec<DynVal>) -> Result<DynVal, Self::Err>;
54+
fn run_fn(&self, name: &str, args: &[DynVal]) -> Result<DynVal, Self::Err>;
5555
}
5656

5757
impl SimplExpr {
@@ -139,6 +139,7 @@ impl SimplExpr {
139139
BinOp::Mod => DynVal::from(a.as_f64()? % b.as_f64()?),
140140
BinOp::GT => DynVal::from(a.as_f64()? > b.as_f64()?),
141141
BinOp::LT => DynVal::from(a.as_f64()? < b.as_f64()?),
142+
#[allow(clippy::useless_conversion)]
142143
BinOp::Elvis => DynVal::from(if a.0.is_empty() { b } else { a }),
143144
BinOp::RegexMatch => {
144145
let regex = regex::Regex::new(&b.as_string()?)?;

src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ pub mod parser;
99
use ast::SimplExpr;
1010
use lalrpop_util::lalrpop_mod;
1111

12-
lalrpop_mod!(pub simplexpr_parser);
12+
lalrpop_mod!(
13+
#[allow(clippy::all)]
14+
pub simplexpr_parser
15+
);
1316

1417
pub fn parse_string(s: &str) -> Result<SimplExpr, error::Error> {
1518
parser::parse_string(s)

src/parser/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::{
99
pub fn parse_string(s: &str) -> Result<SimplExpr> {
1010
let lexer = lexer::Lexer::new(s);
1111
let parser = crate::simplexpr_parser::ExprParser::new();
12-
Ok(parser.parse(lexer).map_err(|e| Error::from_parse_error(e))?)
12+
parser.parse(lexer).map_err(Error::from_parse_error)
1313
}
1414

1515
#[cfg(test)]

0 commit comments

Comments
 (0)