git.delta.rocks / jrsonnet / refs/commits / 8766467a8ebe

difftreelog

style fix clippy warnings

Yaroslav Bolyukin2021-06-12parent: #e71a0d8.patch.diff
in: master

5 files changed

modifiedcrates/jrsonnet-evaluator/src/builtin/mod.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/builtin/mod.rs
+++ b/crates/jrsonnet-evaluator/src/builtin/mod.rs
@@ -466,8 +466,7 @@
 		0, name: ty!(string) => Val::Str;
 		1, rest: ty!(any);
 	], {
-
-		Ok(DebugGcTraceValue::new(name, rest))
+		Ok(DebugGcTraceValue::create(name, rest))
 	})
 }
 
modifiedcrates/jrsonnet-evaluator/src/evaluate.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/evaluate.rs
+++ b/crates/jrsonnet-evaluator/src/evaluate.rs
@@ -127,8 +127,8 @@
 		impl Bindable for BindableMethod {
 			fn bind(&self, this: Option<ObjValue>, super_obj: Option<ObjValue>) -> Result<LazyVal> {
 				Ok(LazyVal::new(Box::new(BindableMethodLazyVal {
-					this: this.clone(),
-					super_obj: super_obj.clone(),
+					this,
+					super_obj,
 
 					context_creator: self.context_creator.clone(),
 					name: self.name.clone(),
@@ -586,7 +586,7 @@
 								add: false,
 								visibility: Visibility::Normal,
 								invoke: LazyBinding::Bindable(Gc::new(Box::new(ObjCompBinding {
-									context: ctx.clone(),
+									context: ctx,
 									value: obj.value.clone(),
 								}))),
 								location: obj.value.1.clone(),
modifiedcrates/jrsonnet-evaluator/src/integrations/serde.rsdiffbeforeafterboth
before · crates/jrsonnet-evaluator/src/integrations/serde.rs
1use crate::{2	error::{Error::*, LocError, Result},3	throw, Context, LazyBinding, LazyVal, ObjMember, ObjValue, Val,4};5use gc::Gc;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};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			Val::DebugGcTraceValue(v) => Value::try_from(&*v.value as &Val)?,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(None, Gc::new(entries), Gc::new(Vec::new())))81			}82		}83	}84}
after · crates/jrsonnet-evaluator/src/integrations/serde.rs
1use crate::{2	error::{Error::*, LocError, Result},3	throw, LazyBinding, LazyVal, ObjMember, ObjValue, Val,4};5use gc::Gc;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};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			Val::DebugGcTraceValue(v) => Self::try_from(&*v.value as &Val)?,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(None, Gc::new(entries), Gc::new(Vec::new())))81			}82		}83	}84}
modifiedcrates/jrsonnet-evaluator/src/obj.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/obj.rs
+++ b/crates/jrsonnet-evaluator/src/obj.rs
@@ -1,7 +1,7 @@
-use crate::{evaluate_add_op, evaluate_assert, Context, LazyBinding, Result, Val};
+use crate::{evaluate_add_op, LazyBinding, Result, Val};
 use gc::{Finalize, Gc, GcCell, Trace};
 use jrsonnet_interner::IStr;
-use jrsonnet_parser::{AssertStmt, ExprLocation, Visibility};
+use jrsonnet_parser::{ExprLocation, Visibility};
 use rustc_hash::{FxHashMap, FxHashSet};
 use std::hash::{Hash, Hasher};
 use std::{fmt::Debug, hash::BuildHasherDefault};
modifiedcrates/jrsonnet-evaluator/src/val.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/val.rs
+++ b/crates/jrsonnet-evaluator/src/val.rs
@@ -49,7 +49,7 @@
 	pub fn evaluate(&self) -> Result<Val> {
 		match &*self.0.borrow() {
 			LazyValInternals::Computed(v) => return Ok(v.clone()),
-			LazyValInternals::Errored(e) => return Err(e.clone().into()),
+			LazyValInternals::Errored(e) => return Err(e.clone()),
 			LazyValInternals::Pending => return Err(RecursiveLazyValueEvaluation.into()),
 			_ => (),
 		};
@@ -400,7 +400,7 @@
 impl Clone for DebugGcTraceValue {
 	fn clone(&self) -> Self {
 		self.print("Cloned");
-		let value = DebugGcTraceValue {
+		let value = Self {
 			name: self.name.clone(),
 			value: self.value.clone(),
 		};
@@ -409,7 +409,7 @@
 	}
 }
 impl DebugGcTraceValue {
-	pub fn new(name: IStr, value: Val) -> Val {
+	pub fn create(name: IStr, value: Val) -> Val {
 		let value = Self {
 			name,
 			value: Box::new(value),