git.delta.rocks / jrsonnet / refs/commits / ee371c2d9f29

difftreelog

fix clippy warnings

Yaroslav Bolyukin2021-05-23parent: #51b072d.patch.diff
in: master

5 files changed

modifiedcrates/jrsonnet-evaluator/src/evaluate.rsdiffbeforeafterboth
--- 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(
modifiedcrates/jrsonnet-evaluator/src/integrations/serde.rsdiffbeforeafterboth
before · crates/jrsonnet-evaluator/src/integrations/serde.rs
1use crate::{2	Context,3	error::{Error::*, LocError, Result},4	throw, LazyBinding, LazyVal, ObjMember, ObjValue, Val,5};6use jrsonnet_parser::Visibility;7use rustc_hash::FxHasher;8use serde_json::{Map, Number, Value};9use std::{10	collections::HashMap,11	convert::{TryFrom, TryInto},12	hash::BuildHasherDefault,13	rc::Rc,14};1516impl TryFrom<&Val> for Value {17	type Error = LocError;18	fn try_from(v: &Val) -> Result<Self> {19		Ok(match v {20			Val::Bool(b) => Self::Bool(*b),21			Val::Null => Self::Null,22			Val::Str(s) => Self::String((s as &str).into()),23			Val::Num(n) => Self::Number(if n.fract() <= f64::EPSILON {24				(*n as i64).into()25			} else {26				Number::from_f64(*n).expect("to json number")27			}),28			Val::Arr(a) => {29				let mut out = Vec::with_capacity(a.len());30				for item in a.iter() {31					out.push((&item?).try_into()?);32				}33				Self::Array(out)34			}35			Val::Obj(o) => {36				let mut out = Map::new();37				for key in o.fields() {38					out.insert(39						(&key as &str).into(),40						(&o.get(key)?.expect("field exists")).try_into()?,41					);42				}43				Self::Object(out)44			}45			Val::Func(_) => throw!(RuntimeError("tried to manifest function".into())),46		})47	}48}4950impl From<&Value> for Val {51	fn from(v: &Value) -> Self {52		match v {53			Value::Null => Self::Null,54			Value::Bool(v) => Self::Bool(*v),55			Value::Number(n) => Self::Num(n.as_f64().expect("as f64")),56			Value::String(s) => Self::Str((s as &str).into()),57			Value::Array(a) => {58				let mut out = Vec::with_capacity(a.len());59				for v in a {60					out.push(LazyVal::new_resolved(v.into()));61				}62				Self::Arr(out.into())63			}64			Value::Object(o) => {65				let mut entries = HashMap::with_capacity_and_hasher(66					o.len(),67					BuildHasherDefault::<FxHasher>::default(),68				);69				for (k, v) in o {70					entries.insert(71						(k as &str).into(),72						ObjMember {73							add: false,74							visibility: Visibility::Normal,75							invoke: LazyBinding::Bound(LazyVal::new_resolved(v.into())),76							location: None,77						},78					);79				}80				Self::Obj(ObjValue::new(Context::new(), None, Rc::new(entries), Rc::new(Vec::new())))81			}82		}83	}84}
after · crates/jrsonnet-evaluator/src/integrations/serde.rs
1use crate::{2	error::{Error::*, LocError, Result},3	throw, Context, LazyBinding, LazyVal, ObjMember, ObjValue, Val,4};5use jrsonnet_parser::Visibility;6use rustc_hash::FxHasher;7use serde_json::{Map, Number, Value};8use std::{9	collections::HashMap,10	convert::{TryFrom, TryInto},11	hash::BuildHasherDefault,12	rc::Rc,13};1415impl TryFrom<&Val> for Value {16	type Error = LocError;17	fn try_from(v: &Val) -> Result<Self> {18		Ok(match v {19			Val::Bool(b) => Self::Bool(*b),20			Val::Null => Self::Null,21			Val::Str(s) => Self::String((s as &str).into()),22			Val::Num(n) => Self::Number(if n.fract() <= f64::EPSILON {23				(*n as i64).into()24			} else {25				Number::from_f64(*n).expect("to json number")26			}),27			Val::Arr(a) => {28				let mut out = Vec::with_capacity(a.len());29				for item in a.iter() {30					out.push((&item?).try_into()?);31				}32				Self::Array(out)33			}34			Val::Obj(o) => {35				let mut out = Map::new();36				for key in o.fields() {37					out.insert(38						(&key as &str).into(),39						(&o.get(key)?.expect("field exists")).try_into()?,40					);41				}42				Self::Object(out)43			}44			Val::Func(_) => throw!(RuntimeError("tried to manifest function".into())),45		})46	}47}4849impl From<&Value> for Val {50	fn from(v: &Value) -> Self {51		match v {52			Value::Null => Self::Null,53			Value::Bool(v) => Self::Bool(*v),54			Value::Number(n) => Self::Num(n.as_f64().expect("as f64")),55			Value::String(s) => Self::Str((s as &str).into()),56			Value::Array(a) => {57				let mut out = Vec::with_capacity(a.len());58				for v in a {59					out.push(LazyVal::new_resolved(v.into()));60				}61				Self::Arr(out.into())62			}63			Value::Object(o) => {64				let mut entries = HashMap::with_capacity_and_hasher(65					o.len(),66					BuildHasherDefault::<FxHasher>::default(),67				);68				for (k, v) in o {69					entries.insert(70						(k as &str).into(),71						ObjMember {72							add: false,73							visibility: Visibility::Normal,74							invoke: LazyBinding::Bound(LazyVal::new_resolved(v.into())),75							location: None,76						},77					);78				}79				Self::Obj(ObjValue::new(80					Context::new(),81					None,82					Rc::new(entries),83					Rc::new(Vec::new()),84				))85			}86		}87	}88}
modifiedcrates/jrsonnet-evaluator/src/lib.rsdiffbeforeafterboth
--- 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");
 	}
 }
modifiedcrates/jrsonnet-evaluator/src/obj.rsdiffbeforeafterboth
--- 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<Self>, this_entries: Rc<FxHashMap<IStr, ObjMember>>, assertions: Rc<Vec<AssertStmt>>) -> Self {
+	pub fn new(
+		context: Context,
+		super_obj: Option<Self>,
+		this_entries: Rc<FxHashMap<IStr, ObjMember>>,
+		assertions: Rc<Vec<AssertStmt>>,
+	) -> 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<Option<Val>> {
-		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<Option<Val>> {
+	fn get_raw(&self, key: IStr, real_this: Option<&Self>) -> Result<Option<Val>> {
 		let real_this = real_this.unwrap_or(self);
 		let cache_key = (key.clone(), real_this.clone());
 
modifiedcrates/jrsonnet-evaluator/src/val.rsdiffbeforeafterboth
--- 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)?)
 			}
 		}
 	}