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
20 Val::Arr(a) => {20 Val::Arr(a) => {
21 let mut out = Vec::with_capacity(a.len());21 let mut out = Vec::with_capacity(a.len());
22 for item in a.iter() {22 for item in a.iter() {
23 out.push((&item?).try_into()?);23 out.push(item?.try_into()?);
24 }24 }
25 Self::Array(out)25 Self::Array(out)
26 }26 }
29 for key in o.fields() {29 for key in o.fields() {
30 out.insert(30 out.insert(
31 (&key as &str).into(),31 (&key as &str).into(),
32 (&o.get(key)?32 o.get(key)?
33 .expect("key is present in fields, so value should exist"))33 .expect("key is present in fields, so value should exist")
34 .try_into()?,34 .try_into()?,
35 );35 );
36 }36 }
40 })40 })
41 }41 }
42}42}
43impl TryFrom<Val> for Value {
44 type Error = LocError;
45
46 fn try_from(value: Val) -> Result<Self, Self::Error> {
47 <Self as TryFrom<&Val>>::try_from(&value)
48 }
49}
4350
44impl TryFrom<&Value> for Val {51impl TryFrom<&Value> for Val {
45 type Error = LocError;52 type Error = LocError;
68 })75 })
69 }76 }
70}77}
78impl TryFrom<Value> for Val {
79 type Error = LocError;
80
81 fn try_from(value: Value) -> Result<Self, Self::Error> {
82 <Self as TryFrom<&Value>>::try_from(&value)
83 }
84}
7185
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
--- a/crates/jrsonnet-macros/src/lib.rs
+++ b/crates/jrsonnet-macros/src/lib.rs
@@ -35,7 +35,7 @@
 
 fn path_is(path: &Path, needed: &str) -> bool {
 	path.leading_colon.is_none()
-		&& path.segments.len() >= 1
+		&& !path.segments.is_empty()
 		&& path.segments.iter().last().unwrap().ident == needed
 }
 
@@ -119,7 +119,7 @@
 
 enum ArgInfo {
 	Normal {
-		ty: Type,
+		ty: Box<Type>,
 		is_option: bool,
 		name: String,
 		// ident: Ident,
@@ -147,27 +147,27 @@
 				))
 			}
 		};
-		let ty = &typed.ty as &Type;
-		if type_is_path(&ty, "CallLocation").is_some() {
+		let ty = &typed.ty;
+		if type_is_path(ty, "CallLocation").is_some() {
 			return Ok(Self::Location);
-		} else if type_is_path(&ty, "Self").is_some() {
+		} else if type_is_path(ty, "Self").is_some() {
 			return Ok(Self::This);
-		} else if type_is_path(&ty, "LazyVal").is_some() {
+		} else if type_is_path(ty, "LazyVal").is_some() {
 			return Ok(Self::Lazy {
 				is_option: false,
 				name: ident.to_string(),
 			});
 		}
 
-		let (is_option, ty) = if let Some(ty) = extract_type_from_option(&ty)? {
-			if type_is_path(&ty, "LazyVal").is_some() {
+		let (is_option, ty) = if let Some(ty) = extract_type_from_option(ty)? {
+			if type_is_path(ty, "LazyVal").is_some() {
 				return Ok(Self::Lazy {
 					is_option: true,
 					name: ident.to_string(),
 				});
 			}
 
-			(true, ty.clone())
+			(true, Box::new(ty.clone()))
 		} else {
 			(false, ty.clone())
 		};
@@ -210,7 +210,7 @@
 		.sig
 		.inputs
 		.iter()
-		.map(|a| ArgInfo::parse(a))
+		.map(ArgInfo::parse)
 		.collect::<Result<Vec<_>>>()?;
 
 	let params_desc = args.iter().flat_map(|a| match a {
@@ -380,8 +380,7 @@
 struct TypedField<'f>(&'f syn::Field, TypedAttr);
 impl<'f> TypedField<'f> {
 	fn try_new(field: &'f syn::Field) -> Result<Self> {
-		let attr =
-			parse_attr::<TypedAttr, _>(&field.attrs, "typed")?.unwrap_or_else(Default::default);
+		let attr = parse_attr::<TypedAttr, _>(&field.attrs, "typed")?.unwrap_or_default();
 		if field.ident.is_none() {
 			return Err(Error::new(
 				field.span(),
@@ -468,17 +467,15 @@
 					out.member(#name.into()).value(self.#ident.try_into()?);
 				}
 			}
+		} else if self.is_option() {
+			quote! {
+				if let Some(value) = self.#ident {
+					value.serialize(out)?;
+				}
+			}
 		} else {
-			if self.is_option() {
-				quote! {
-					if let Some(value) = self.#ident {
-						value.serialize(out)?;
-					}
-				}
-			} else {
-				quote! {
-					self.#ident.serialize(out)?;
-				}
+			quote! {
+				self.#ident.serialize(out)?;
 			}
 		}
 	}