Fix clippy lints (#2119)

This commit is contained in:
James Lindsay
2024-11-29 22:58:49 +00:00
committed by GitHub
parent 00629571f2
commit e3bb11ec1b
32 changed files with 694 additions and 456 deletions

View File

@@ -191,7 +191,7 @@ impl SymmetricalBasis {
}
// https://gitlab.com/inkscape/lib2geom/-/blob/master/src/2geom/sbasis.cpp#L228
impl<'a> std::ops::Mul for &'a SymmetricalBasis {
impl std::ops::Mul for &SymmetricalBasis {
type Output = SymmetricalBasis;
fn mul(self, b: Self) -> Self::Output {
let a = self;

View File

@@ -34,7 +34,6 @@ use syn::{parse_macro_input, DeriveInput, GenericParam, Lifetime, LifetimeParam,
/// // }
///
/// ```
#[proc_macro_derive(DynAny, attributes(dyn_any_derive))]
pub fn system_desc_derive(input: TokenStream) -> TokenStream {
let ast = parse_macro_input!(input as DeriveInput);

View File

@@ -145,7 +145,7 @@ macro_rules! impl_type {
}
#[cfg(feature = "alloc")]
unsafe impl<'a, T: StaticTypeClone + Clone> StaticType for Cow<'a, T> {
unsafe impl<T: StaticTypeClone + Clone> StaticType for Cow<'_, T> {
type Static = Cow<'static, <T as StaticTypeClone>::Static>;
}
unsafe impl<T: StaticTypeSized> StaticType for *const [T] {
@@ -173,11 +173,11 @@ mod slice {
}
#[cfg(feature = "alloc")]
unsafe impl<'a, T: StaticTypeSized> StaticType for Box<dyn Iterator<Item = T> + 'a + Send + Sync> {
unsafe impl<T: StaticTypeSized> StaticType for Box<dyn Iterator<Item = T> + '_ + Send + Sync> {
type Static = Box<dyn Iterator<Item = <T as StaticTypeSized>::Static> + Send + Sync>;
}
unsafe impl<'a> StaticType for &'a str {
unsafe impl StaticType for &str {
type Static = &'static str;
}
unsafe impl StaticType for () {

View File

@@ -9,7 +9,7 @@ macro_rules! generate_benchmarks {
$(
c.bench_function(concat!("parse ", $input), |b| {
b.iter(|| {
let _ = black_box(ast::Node::from_str($input)).unwrap();
let _ = black_box(ast::Node::try_parse_from_str($input)).unwrap();
});
});
)*
@@ -17,7 +17,7 @@ macro_rules! generate_benchmarks {
fn evaluation_bench(c: &mut Criterion) {
$(
let expr = ast::Node::from_str($input).unwrap().0;
let expr = ast::Node::try_parse_from_str($input).unwrap().0;
let context = EvalContext::default();
c.bench_function(concat!("eval ", $input), |b| {

View File

@@ -4,9 +4,10 @@ use lazy_static::lazy_static;
use num_complex::{Complex, ComplexFloat};
use crate::value::{Number, Value};
type FunctionImplementation = Box<dyn Fn(&[Value]) -> Option<Value> + Send + Sync>;
lazy_static! {
pub static ref DEFAULT_FUNCTIONS: HashMap<&'static str, Box<dyn Fn(&[Value]) -> Option<Value> + Send + Sync>> = {
let mut map: HashMap<&'static str, Box<dyn Fn(&[Value]) -> Option<Value> + Send + Sync>> = HashMap::new();
pub static ref DEFAULT_FUNCTIONS: HashMap<&'static str, FunctionImplementation> = {
let mut map: HashMap<&'static str, FunctionImplementation> = HashMap::new();
map.insert(
"sin",

View File

@@ -14,7 +14,7 @@ use parser::ParseError;
use value::Value;
pub fn evaluate(expression: &str) -> Result<(Result<Value, EvalError>, Unit), ParseError> {
let expr = ast::Node::from_str(expression);
let expr = ast::Node::try_parse_from_str(expression);
let context = EvalContext::default();
expr.map(|(node, unit)| (node.eval(&context), unit))
}
@@ -37,7 +37,7 @@ mod tests {
let expected_value = $expected_value;
let expected_unit = $expected_unit;
let expr = ast::Node::from_str($input);
let expr = ast::Node::try_parse_from_str($input);
let context = EvalContext::default();
let (actual_value, actual_unit) = expr.map(|(node, unit)| (node.eval(&context), unit)).unwrap();

View File

@@ -56,7 +56,7 @@ pub enum ParseError {
}
impl Node {
pub fn from_str(s: &str) -> Result<(Node, Unit), ParseError> {
pub fn try_parse_from_str(s: &str) -> Result<(Node, Unit), ParseError> {
let pairs = ExprParser::parse(Rule::program, s).map_err(Box::new)?;
let (node, metadata) = parse_expr(pairs)?;
Ok((node, metadata.unit))
@@ -325,7 +325,7 @@ mod tests {
$(
#[test]
fn $name() {
let result = Node::from_str($input).unwrap();
let result = Node::try_parse_from_str($input).unwrap();
assert_eq!(result.0, $expected);
}
)*
@@ -334,7 +334,7 @@ mod tests {
test_parser! {
test_parse_int_literal: "42" => Node::Lit(Literal::Float(42.0)),
test_parse_float_literal: "3.14" => Node::Lit(Literal::Float(3.14)),
test_parse_float_literal: "3.14" => Node::Lit(Literal::Float(#[allow(clippy::approx_constant)] 3.14)),
test_parse_ident: "x" => Node::Var("x".to_string()),
test_parse_unary_neg: "-42" => Node::UnaryOp {
expr: Box::new(Node::Lit(Literal::Float(42.0))),