From ee371c2d9f294bb5853b47a9d31bfb34bb5afac3 Mon Sep 17 00:00:00 2001 From: Yaroslav Bolyukin Date: Sun, 23 May 2021 15:46:56 +0000 Subject: [PATCH] fix: clippy warnings --- --- a/crates/jrsonnet-evaluator/src/evaluate.rs +++ b/crates/jrsonnet-evaluator/src/evaluate.rs @@ -147,8 +147,8 @@ Ok(match (a, op, b) { (a, BinaryOpType::Add, b) => evaluate_add_op(a, b)?, - (a, BinaryOpType::Eq, b) => Val::Bool(equals(&a, &b)?), - (a, BinaryOpType::Neq, b) => Val::Bool(!equals(&a, &b)?), + (a, BinaryOpType::Eq, b) => Val::Bool(equals(a, b)?), + (a, BinaryOpType::Neq, b) => Val::Bool(!equals(a, b)?), (Val::Str(v1), BinaryOpType::Mul, Val::Num(v2)) => Val::Str(v1.repeat(*v2 as usize).into()), @@ -578,7 +578,7 @@ } Intrinsic(name) => Val::Func(Rc::new(FuncVal::Intrinsic(name.clone()))), AssertExpr(assert, returned) => { - evaluate_assert(context.clone(), &assert)?; + evaluate_assert(context.clone(), assert)?; evaluate(context, returned)? } ErrorStmt(e) => push( --- a/crates/jrsonnet-evaluator/src/integrations/serde.rs +++ b/crates/jrsonnet-evaluator/src/integrations/serde.rs @@ -1,7 +1,6 @@ use crate::{ - Context, error::{Error::*, LocError, Result}, - throw, LazyBinding, LazyVal, ObjMember, ObjValue, Val, + throw, Context, LazyBinding, LazyVal, ObjMember, ObjValue, Val, }; use jrsonnet_parser::Visibility; use rustc_hash::FxHasher; @@ -77,7 +76,12 @@ }, ); } - Self::Obj(ObjValue::new(Context::new(), None, Rc::new(entries), Rc::new(Vec::new()))) + Self::Obj(ObjValue::new( + Context::new(), + None, + Rc::new(entries), + Rc::new(Vec::new()), + )) } } } --- a/crates/jrsonnet-evaluator/src/lib.rs +++ b/crates/jrsonnet-evaluator/src/lib.rs @@ -1,6 +1,9 @@ #![cfg_attr(feature = "unstable", feature(stmt_expr_attributes))] #![warn(clippy::all, clippy::nursery)] -#![allow(macro_expanded_macro_exports_accessed_by_absolute_paths, clippy::ptr_arg)] +#![allow( + macro_expanded_macro_exports_accessed_by_absolute_paths, + clippy::ptr_arg +)] mod builtin; mod ctx; @@ -390,7 +393,7 @@ loc_data: true, }, ) - .map_err(|e| ImportSyntaxError { + .map_err(|e| ImportSyntaxError { path: source.clone(), source_code: code.clone(), error: Box::new(e), @@ -998,9 +1001,10 @@ let state = EvaluationState::default(); state.with_stdlib(); - let error = state.evaluate_snippet_raw( - Rc::new(PathBuf::from("issue40.jsonnet")), - r#" + let error = state + .evaluate_snippet_raw( + Rc::new(PathBuf::from("issue40.jsonnet")), + r#" local conf = { n: "" }; @@ -1010,8 +1014,10 @@ }; std.manifestJsonEx(result, "") - "#.into(), - ).unwrap_err(); + "# + .into(), + ) + .unwrap_err(); assert_eq!(error.error().to_string(), "assert failed: is number"); } } --- a/crates/jrsonnet-evaluator/src/obj.rs +++ b/crates/jrsonnet-evaluator/src/obj.rs @@ -1,6 +1,6 @@ -use crate::{Context, evaluate_add_op, evaluate_assert, LazyBinding, Result, Val}; +use crate::{evaluate_add_op, evaluate_assert, Context, LazyBinding, Result, Val}; use jrsonnet_interner::IStr; -use jrsonnet_parser::{ExprLocation, LocExpr, Visibility, AssertStmt}; +use jrsonnet_parser::{AssertStmt, ExprLocation, Visibility}; use rustc_hash::{FxHashMap, FxHashSet}; use std::hash::{Hash, Hasher}; use std::{cell::RefCell, fmt::Debug, hash::BuildHasherDefault, rc::Rc}; @@ -54,7 +54,12 @@ } impl ObjValue { - pub fn new(context: Context, super_obj: Option, this_entries: Rc>, assertions: Rc>) -> Self { + pub fn new( + context: Context, + super_obj: Option, + this_entries: Rc>, + assertions: Rc>, + ) -> Self { Self(Rc::new(ObjValueInternals { context, super_obj, @@ -66,12 +71,27 @@ })) } pub fn new_empty() -> Self { - Self::new(Context::new(), None, Rc::new(FxHashMap::default()), Rc::new(Vec::new())) + Self::new( + Context::new(), + None, + Rc::new(FxHashMap::default()), + Rc::new(Vec::new()), + ) } pub fn extend_from(&self, super_obj: Self) -> Self { match &self.0.super_obj { - None => Self::new(self.0.context.clone(), Some(super_obj), self.0.this_entries.clone(), self.0.assertions.clone()), - Some(v) => Self::new(self.0.context.clone(), Some(v.extend_from(super_obj)), self.0.this_entries.clone(), self.0.assertions.clone()), + None => Self::new( + self.0.context.clone(), + Some(super_obj), + self.0.this_entries.clone(), + self.0.assertions.clone(), + ), + Some(v) => Self::new( + self.0.context.clone(), + Some(v.extend_from(super_obj)), + self.0.this_entries.clone(), + self.0.assertions.clone(), + ), } } pub fn with_this(&self, this_obj: Self) -> Self { @@ -176,17 +196,22 @@ } pub fn get(&self, key: IStr) -> Result> { - self.run_assertions(self.0.this_obj.as_ref().unwrap_or(self))?; + self.run_assertions()?; self.get_raw(key, self.0.this_obj.as_ref()) } pub fn extend_with_field(self, key: IStr, value: ObjMember) -> Self { let mut new = FxHashMap::with_capacity_and_hasher(1, BuildHasherDefault::default()); new.insert(key, value); - Self::new(Context::new(), Some(self), Rc::new(new), Rc::new(Vec::new())) + Self::new( + Context::new(), + Some(self), + Rc::new(new), + Rc::new(Vec::new()), + ) } - pub fn get_raw(&self, key: IStr, real_this: Option<&Self>) -> Result> { + fn get_raw(&self, key: IStr, real_this: Option<&Self>) -> Result> { let real_this = real_this.unwrap_or(self); let cache_key = (key.clone(), real_this.clone()); --- a/crates/jrsonnet-evaluator/src/val.rs +++ b/crates/jrsonnet-evaluator/src/val.rs @@ -124,7 +124,7 @@ for p in handler.params.0.iter() { out_args.push(args.binding(p.0.clone())?.evaluate()?); } - Ok(handler.call(loc.clone().map(|l| l.0.clone()), &out_args)?) + Ok(handler.call(loc.map(|l| l.0.clone()), &out_args)?) } } } -- gitstuff