git.delta.rocks / jrsonnet / refs/commits / 4f4be44d138e

difftreelog

style fix clippy warnings

Yaroslav Bolyukin2022-04-20parent: #ed4ee4d.patch.diff
in: master

5 files changed

modifiedcrates/jrsonnet-evaluator/src/function.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/function.rs
+++ b/crates/jrsonnet-evaluator/src/function.rs
@@ -15,12 +15,12 @@
 #[derive(Clone, Copy)]
 pub struct CallLocation<'l>(pub Option<&'l ExprLocation>);
 impl<'l> CallLocation<'l> {
-	pub fn new(loc: &'l ExprLocation) -> Self {
+	pub const fn new(loc: &'l ExprLocation) -> Self {
 		Self(Some(loc))
 	}
 }
 impl CallLocation<'static> {
-	pub fn native() -> Self {
+	pub const fn native() -> Self {
 		Self(None)
 	}
 }
modifiedcrates/jrsonnet-evaluator/src/integrations/serde.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/integrations/serde.rs
+++ b/crates/jrsonnet-evaluator/src/integrations/serde.rs
@@ -20,7 +20,7 @@
 			Val::Arr(a) => {
 				let mut out = Vec::with_capacity(a.len());
 				for item in a.iter() {
-					out.push((&item?).try_into()?);
+					out.push(item?.try_into()?);
 				}
 				Self::Array(out)
 			}
@@ -29,8 +29,8 @@
 				for key in o.fields() {
 					out.insert(
 						(&key as &str).into(),
-						(&o.get(key)?
-							.expect("key is present in fields, so value should exist"))
+						o.get(key)?
+							.expect("key is present in fields, so value should exist")
 							.try_into()?,
 					);
 				}
@@ -40,6 +40,13 @@
 		})
 	}
 }
+impl TryFrom<Val> for Value {
+	type Error = LocError;
+
+	fn try_from(value: Val) -> Result<Self, Self::Error> {
+		<Self as TryFrom<&Val>>::try_from(&value)
+	}
+}
 
 impl TryFrom<&Value> for Val {
 	type Error = LocError;
@@ -68,3 +75,10 @@
 		})
 	}
 }
+impl TryFrom<Value> for Val {
+	type Error = LocError;
+
+	fn try_from(value: Value) -> Result<Self, Self::Error> {
+		<Self as TryFrom<&Value>>::try_from(&value)
+	}
+}
modifiedcrates/jrsonnet-evaluator/src/typed/conversions.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/typed/conversions.rs
+++ b/crates/jrsonnet-evaluator/src/typed/conversions.rs
@@ -442,7 +442,7 @@
 	fn try_from(value: Val) -> Result<Self, Self::Error> {
 		<Self as Typed>::TYPE.check(&value)?;
 		match value {
-			Val::Func(FuncVal::Normal(desc)) => Ok(desc.clone()),
+			Val::Func(FuncVal::Normal(desc)) => Ok(desc),
 			Val::Func(_) => throw!(RuntimeError("expected normal function, not builtin".into())),
 			_ => unreachable!(),
 		}
modifiedcrates/jrsonnet-evaluator/src/val.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/val.rs
+++ b/crates/jrsonnet-evaluator/src/val.rs
@@ -126,15 +126,6 @@
 	}
 }
 
-impl PartialEq for FuncVal {
-	fn eq(&self, other: &Self) -> bool {
-		match (self, other) {
-			(Self::Normal(a), Self::Normal(b)) => a == b,
-			(Self::StaticBuiltin(an), Self::StaticBuiltin(bn)) => std::ptr::eq(*an, *bn),
-			(..) => false,
-		}
-	}
-}
 impl FuncVal {
 	pub fn args_len(&self) -> usize {
 		match self {
@@ -353,13 +344,13 @@
 }
 
 impl Val {
-	pub fn as_bool(&self) -> Option<bool> {
+	pub const fn as_bool(&self) -> Option<bool> {
 		match self {
 			Val::Bool(v) => Some(*v),
 			_ => None,
 		}
 	}
-	pub fn as_null(&self) -> Option<()> {
+	pub const fn as_null(&self) -> Option<()> {
 		match self {
 			Val::Null => Some(()),
 			_ => None,
@@ -371,7 +362,7 @@
 			_ => None,
 		}
 	}
-	pub fn as_num(&self) -> Option<f64> {
+	pub const fn as_num(&self) -> Option<f64> {
 		match self {
 			Val::Num(n) => Some(*n),
 			_ => None,
modifiedcrates/jrsonnet-macros/src/lib.rsdiffbeforeafterboth
3535
36fn path_is(path: &Path, needed: &str) -> bool {36fn path_is(path: &Path, needed: &str) -> bool {
37 path.leading_colon.is_none()37 path.leading_colon.is_none()
38 && path.segments.len() >= 138 && !path.segments.is_empty()
39 && path.segments.iter().last().unwrap().ident == needed39 && path.segments.iter().last().unwrap().ident == needed
40}40}
4141
119119
120enum ArgInfo {120enum ArgInfo {
121 Normal {121 Normal {
122 ty: Type,122 ty: Box<Type>,
123 is_option: bool,123 is_option: bool,
124 name: String,124 name: String,
125 // ident: Ident,125 // ident: Ident,
147 ))147 ))
148 }148 }
149 };149 };
150 let ty = &typed.ty as &Type;150 let ty = &typed.ty;
151 if type_is_path(&ty, "CallLocation").is_some() {151 if type_is_path(ty, "CallLocation").is_some() {
152 return Ok(Self::Location);152 return Ok(Self::Location);
153 } else if type_is_path(&ty, "Self").is_some() {153 } else if type_is_path(ty, "Self").is_some() {
154 return Ok(Self::This);154 return Ok(Self::This);
155 } else if type_is_path(&ty, "LazyVal").is_some() {155 } else if type_is_path(ty, "LazyVal").is_some() {
156 return Ok(Self::Lazy {156 return Ok(Self::Lazy {
157 is_option: false,157 is_option: false,
158 name: ident.to_string(),158 name: ident.to_string(),
159 });159 });
160 }160 }
161161
162 let (is_option, ty) = if let Some(ty) = extract_type_from_option(&ty)? {162 let (is_option, ty) = if let Some(ty) = extract_type_from_option(ty)? {
163 if type_is_path(&ty, "LazyVal").is_some() {163 if type_is_path(ty, "LazyVal").is_some() {
164 return Ok(Self::Lazy {164 return Ok(Self::Lazy {
165 is_option: true,165 is_option: true,
166 name: ident.to_string(),166 name: ident.to_string(),
167 });167 });
168 }168 }
169169
170 (true, ty.clone())170 (true, Box::new(ty.clone()))
171 } else {171 } else {
172 (false, ty.clone())172 (false, ty.clone())
173 };173 };
210 .sig210 .sig
211 .inputs211 .inputs
212 .iter()212 .iter()
213 .map(|a| ArgInfo::parse(a))213 .map(ArgInfo::parse)
214 .collect::<Result<Vec<_>>>()?;214 .collect::<Result<Vec<_>>>()?;
215215
216 let params_desc = args.iter().flat_map(|a| match a {216 let params_desc = args.iter().flat_map(|a| match a {
380struct TypedField<'f>(&'f syn::Field, TypedAttr);380struct TypedField<'f>(&'f syn::Field, TypedAttr);
381impl<'f> TypedField<'f> {381impl<'f> TypedField<'f> {
382 fn try_new(field: &'f syn::Field) -> Result<Self> {382 fn try_new(field: &'f syn::Field) -> Result<Self> {
383 let attr =383 let attr = parse_attr::<TypedAttr, _>(&field.attrs, "typed")?.unwrap_or_default();
384 parse_attr::<TypedAttr, _>(&field.attrs, "typed")?.unwrap_or_else(Default::default);
385 if field.ident.is_none() {384 if field.ident.is_none() {
386 return Err(Error::new(385 return Err(Error::new(
387 field.span(),386 field.span(),
468 out.member(#name.into()).value(self.#ident.try_into()?);467 out.member(#name.into()).value(self.#ident.try_into()?);
469 }468 }
470 }469 }
471 } else {470 } else if self.is_option() {
472 if self.is_option() {
473 quote! {471 quote! {
474 if let Some(value) = self.#ident {472 if let Some(value) = self.#ident {
480 self.#ident.serialize(out)?;478 self.#ident.serialize(out)?;
481 }479 }
482 }480 }
483 }
484 }481 }
485482
486 fn as_option(&self) -> Option<&Type> {483 fn as_option(&self) -> Option<&Type> {