git.delta.rocks / jrsonnet / refs/commits / 3fc6c25f159a

difftreelog

style fix clippy warnings

Yaroslav Bolyukin2021-01-24parent: #2634495.patch.diff
in: master

9 files changed

modifiedcrates/jrsonnet-evaluator/src/builtin/manifest.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/builtin/manifest.rs
+++ b/crates/jrsonnet-evaluator/src/builtin/manifest.rs
@@ -42,7 +42,7 @@
 			}
 		}
 		Val::Null => buf.push_str("null"),
-		Val::Str(s) => buf.push_str(&escape_string_json(&s)),
+		Val::Str(s) => buf.push_str(&escape_string_json(s)),
 		Val::Num(n) => write!(buf, "{}", n).unwrap(),
 		Val::Arr(items) => {
 			buf.push('[');
modifiedcrates/jrsonnet-evaluator/src/builtin/mod.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/builtin/mod.rs
+++ b/crates/jrsonnet-evaluator/src/builtin/mod.rs
@@ -445,7 +445,7 @@
 			},
 			Val::Arr(a) => {
 				base64::encode(a.iter().map(|v| {
-					Ok(v?.clone().unwrap_num()? as u8)
+					Ok(v?.unwrap_num()? as u8)
 				}).collect::<Result<Vec<_>>>()?).into()
 			},
 			_ => unreachable!()
@@ -589,7 +589,7 @@
 	name: &str,
 	args: &ArgsDesc,
 ) -> Result<Val> {
-	if let Some(f) = BUILTINS.with(|builtins| builtins.get(name).map(|f| *f)) {
+	if let Some(f) = BUILTINS.with(|builtins| builtins.get(name).copied()) {
 		return Ok(f(context, loc, args)?);
 	}
 	throw!(IntrinsicNotFound(name.into()))
modifiedcrates/jrsonnet-evaluator/src/evaluate.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/evaluate.rs
+++ b/crates/jrsonnet-evaluator/src/evaluate.rs
@@ -473,7 +473,6 @@
 					}
 					v.get(n as usize)?
 						.ok_or_else(|| ArrayBoundsError(n as usize, v.len()))?
-						.clone()
 				}
 				(Val::Arr(_), Val::Str(n)) => throw!(AttemptedIndexAnArrayWithString(n)),
 				(Val::Arr(_), n) => throw!(ValueIndexMustBeTypeGot(
modifiedcrates/jrsonnet-evaluator/src/native.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/native.rs
+++ b/crates/jrsonnet-evaluator/src/native.rs
@@ -1,3 +1,5 @@
+#![allow(clippy::type_complexity)]
+
 use crate::{error::Result, Val};
 use jrsonnet_parser::ParamsDesc;
 use std::fmt::Debug;
modifiedcrates/jrsonnet-evaluator/src/obj.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/obj.rs
+++ b/crates/jrsonnet-evaluator/src/obj.rs
@@ -34,7 +34,7 @@
 		}
 		let mut debug = f.debug_struct("ObjValue");
 		for (name, member) in self.0.this_entries.iter() {
-			debug.field(&name, member);
+			debug.field(name, member);
 		}
 		#[cfg(feature = "unstable")]
 		{
@@ -140,7 +140,7 @@
 			.evaluate()?)
 	}
 
-	pub fn ptr_eq(a: &ObjValue, b: &ObjValue) -> bool {
+	pub fn ptr_eq(a: &Self, b: &Self) -> bool {
 		Rc::ptr_eq(&a.0, &b.0)
 	}
 }
modifiedcrates/jrsonnet-evaluator/src/typed.rsdiffbeforeafterboth
29pub struct TypeLocError(Box<TypeError>, ValuePathStack);29pub struct TypeLocError(Box<TypeError>, ValuePathStack);
30impl From<TypeError> for TypeLocError {30impl From<TypeError> for TypeLocError {
31 fn from(e: TypeError) -> Self {31 fn from(e: TypeError) -> Self {
32 TypeLocError(Box::new(e), ValuePathStack(Vec::new()))32 Self(Box::new(e), ValuePathStack(Vec::new()))
33 }33 }
34}34}
35impl From<TypeLocError> for LocError {35impl From<TypeLocError> for LocError {
61 write!(out, "{}", err)?;61 write!(out, "{}", err)?;
6262
63 for (i, line) in out.lines().enumerate() {63 for (i, line) in out.lines().enumerate() {
64 if line.trim().len() == 0 {64 if line.trim().is_empty() {
65 continue;65 continue;
66 }66 }
67 if i != 0 {67 if i != 0 {
118impl Display for ValuePathItem {118impl Display for ValuePathItem {
119 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {119 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
120 match self {120 match self {
121 ValuePathItem::Field(name) => write!(f, ".{}", name)?,121 Self::Field(name) => write!(f, ".{}", name)?,
122 ValuePathItem::Index(idx) => write!(f, "[{}]", idx)?,122 Self::Index(idx) => write!(f, "[{}]", idx)?,
123 }123 }
124 Ok(())124 Ok(())
125 }125 }
140impl CheckType for ComplexValType {140impl CheckType for ComplexValType {
141 fn check(&self, value: &Val) -> Result<()> {141 fn check(&self, value: &Val) -> Result<()> {
142 match self {142 match self {
143 ComplexValType::Any => Ok(()),143 Self::Any => Ok(()),
144 ComplexValType::Simple(s) => s.check(value),144 Self::Simple(s) => s.check(value),
145 ComplexValType::Char => match value {145 Self::Char => match value {
146 Val::Str(s) if s.len() == 1 || s.chars().count() == 1 => Ok(()),146 Val::Str(s) if s.len() == 1 || s.chars().count() == 1 => Ok(()),
147 v => Err(TypeError::ExpectedGot(self.clone(), v.value_type()).into()),147 v => Err(TypeError::ExpectedGot(self.clone(), v.value_type()).into()),
148 },148 },
149 ComplexValType::BoundedNumber(from, to) => {149 Self::BoundedNumber(from, to) => {
150 if let Val::Num(n) = value {150 if let Val::Num(n) = value {
151 if from.map(|from| from > *n).unwrap_or(false)151 if from.map(|from| from > *n).unwrap_or(false)
152 || to.map(|to| to <= *n).unwrap_or(false)152 || to.map(|to| to <= *n).unwrap_or(false)
153 {153 {
154 return Err(TypeError::BoundsFailed(*n, from.clone(), to.clone()).into());154 return Err(TypeError::BoundsFailed(*n, *from, *to).into());
155 }155 }
156 Ok(())156 Ok(())
157 } else {157 } else {
158 Err(TypeError::ExpectedGot(self.clone(), value.value_type()).into())158 Err(TypeError::ExpectedGot(self.clone(), value.value_type()).into())
159 }159 }
160 }160 }
161 ComplexValType::Array(elem_type) => match value {161 Self::Array(elem_type) => match value {
162 Val::Arr(a) => {162 Val::Arr(a) => {
163 for (i, item) in a.iter().enumerate() {163 for (i, item) in a.iter().enumerate() {
164 push_type(164 push_type(
170 }170 }
171 Ok(())171 Ok(())
172 }172 }
173 v => return Err(TypeError::ExpectedGot(self.clone(), v.value_type()).into()),173 v => Err(TypeError::ExpectedGot(self.clone(), v.value_type()).into()),
174 },174 },
175 ComplexValType::ArrayRef(elem_type) => match value {175 Self::ArrayRef(elem_type) => match value {
176 Val::Arr(a) => {176 Val::Arr(a) => {
177 for (i, item) in a.iter().enumerate() {177 for (i, item) in a.iter().enumerate() {
178 push_type(178 push_type(
184 }184 }
185 Ok(())185 Ok(())
186 }186 }
187 v => return Err(TypeError::ExpectedGot(self.clone(), v.value_type()).into()),187 v => Err(TypeError::ExpectedGot(self.clone(), v.value_type()).into()),
188 },188 },
189 ComplexValType::ObjectRef(elems) => match value {189 Self::ObjectRef(elems) => match value {
190 Val::Obj(obj) => {190 Val::Obj(obj) => {
191 for (k, v) in elems.iter() {191 for (k, v) in elems.iter() {
192 if let Some(got_v) = obj.get((*k).into())? {192 if let Some(got_v) = obj.get((*k).into())? {
202 );202 );
203 }203 }
204 }204 }
205 return Ok(());205 Ok(())
206 }206 }
207 v => return Err(TypeError::ExpectedGot(self.clone(), v.value_type()).into()),207 v => Err(TypeError::ExpectedGot(self.clone(), v.value_type()).into()),
208 },208 },
209 ComplexValType::Union(types) => {209 Self::Union(types) => {
210 let mut errors = Vec::new();210 let mut errors = Vec::new();
211 for ty in types.iter() {211 for ty in types.iter() {
212 match ty.check(value) {212 match ty.check(value) {
219 },219 },
220 }220 }
221 }221 }
222 return Err(TypeError::UnionFailed(self.clone(), TypeLocErrorList(errors)).into());222 Err(TypeError::UnionFailed(self.clone(), TypeLocErrorList(errors)).into())
223 }223 }
224 ComplexValType::UnionRef(types) => {224 Self::UnionRef(types) => {
225 let mut errors = Vec::new();225 let mut errors = Vec::new();
226 for ty in types.iter() {226 for ty in types.iter() {
227 match ty.check(value) {227 match ty.check(value) {
234 },234 },
235 }235 }
236 }236 }
237 return Err(TypeError::UnionFailed(self.clone(), TypeLocErrorList(errors)).into());237 Err(TypeError::UnionFailed(self.clone(), TypeLocErrorList(errors)).into())
238 }238 }
239 ComplexValType::Sum(types) => {239 Self::Sum(types) => {
240 for ty in types.iter() {240 for ty in types.iter() {
241 ty.check(value)?241 ty.check(value)?
242 }242 }
243 Ok(())243 Ok(())
244 }244 }
245 ComplexValType::SumRef(types) => {245 Self::SumRef(types) => {
246 for ty in types.iter() {246 for ty in types.iter() {
247 ty.check(value)?247 ty.check(value)?
248 }248 }
modifiedcrates/jrsonnet-evaluator/src/val.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/val.rs
+++ b/crates/jrsonnet-evaluator/src/val.rs
@@ -176,14 +176,14 @@
 pub enum ArrValue {
 	Lazy(Rc<Vec<LazyVal>>),
 	Eager(Rc<Vec<Val>>),
-	Extended(Box<(ArrValue, ArrValue)>),
+	Extended(Box<(Self, Self)>),
 }
 impl ArrValue {
 	pub fn len(&self) -> usize {
 		match self {
-			ArrValue::Lazy(l) => l.len(),
-			ArrValue::Eager(e) => e.len(),
-			ArrValue::Extended(v) => v.0.len() + v.1.len(),
+			Self::Lazy(l) => l.len(),
+			Self::Eager(e) => e.len(),
+			Self::Extended(v) => v.0.len() + v.1.len(),
 		}
 	}
 
@@ -193,15 +193,15 @@
 
 	pub fn get(&self, index: usize) -> Result<Option<Val>> {
 		match self {
-			ArrValue::Lazy(vec) => {
+			Self::Lazy(vec) => {
 				if let Some(v) = vec.get(index) {
 					Ok(Some(v.evaluate()?))
 				} else {
 					Ok(None)
 				}
 			}
-			ArrValue::Eager(vec) => Ok(vec.get(index).cloned()),
-			ArrValue::Extended(v) => {
+			Self::Eager(vec) => Ok(vec.get(index).cloned()),
+			Self::Extended(v) => {
 				let a_len = v.0.len();
 				if a_len > index {
 					v.0.get(index)
@@ -214,12 +214,9 @@
 
 	pub fn get_lazy(&self, index: usize) -> Option<LazyVal> {
 		match self {
-			ArrValue::Lazy(vec) => vec.get(index).cloned(),
-			ArrValue::Eager(vec) => vec
-				.get(index)
-				.cloned()
-				.map(|val| LazyVal::new_resolved(val)),
-			ArrValue::Extended(v) => {
+			Self::Lazy(vec) => vec.get(index).cloned(),
+			Self::Eager(vec) => vec.get(index).cloned().map(LazyVal::new_resolved),
+			Self::Extended(v) => {
 				let a_len = v.0.len();
 				if a_len > index {
 					v.0.get_lazy(index)
@@ -232,15 +229,15 @@
 
 	pub fn evaluated(&self) -> Result<Rc<Vec<Val>>> {
 		Ok(match self {
-			ArrValue::Lazy(vec) => {
+			Self::Lazy(vec) => {
 				let mut out = Vec::with_capacity(vec.len());
 				for item in vec.iter() {
 					out.push(item.evaluate()?);
 				}
 				Rc::new(out)
 			}
-			ArrValue::Eager(vec) => vec.clone(),
-			ArrValue::Extended(v) => {
+			Self::Eager(vec) => vec.clone(),
+			Self::Extended(_v) => {
 				let mut out = Vec::with_capacity(self.len());
 				for item in self.iter() {
 					out.push(item?);
@@ -252,40 +249,40 @@
 
 	pub fn iter(&self) -> impl DoubleEndedIterator<Item = Result<Val>> + '_ {
 		(0..self.len()).map(move |idx| match self {
-			ArrValue::Lazy(l) => l[idx].evaluate(),
-			ArrValue::Eager(e) => Ok(e[idx].clone()),
-			ArrValue::Extended(_) => self.get(idx).map(|e| e.unwrap()),
+			Self::Lazy(l) => l[idx].evaluate(),
+			Self::Eager(e) => Ok(e[idx].clone()),
+			Self::Extended(_) => self.get(idx).map(|e| e.unwrap()),
 		})
 	}
 
 	pub fn iter_lazy(&self) -> impl DoubleEndedIterator<Item = LazyVal> + '_ {
 		(0..self.len()).map(move |idx| match self {
-			ArrValue::Lazy(l) => l[idx].clone(),
-			ArrValue::Eager(e) => LazyVal::new_resolved(e[idx].clone()),
-			ArrValue::Extended(_) => self.get_lazy(idx).unwrap(),
+			Self::Lazy(l) => l[idx].clone(),
+			Self::Eager(e) => LazyVal::new_resolved(e[idx].clone()),
+			Self::Extended(_) => self.get_lazy(idx).unwrap(),
 		})
 	}
 
 	pub fn reversed(self) -> Self {
 		match self {
-			ArrValue::Lazy(vec) => {
+			Self::Lazy(vec) => {
 				let mut out = (&vec as &Vec<_>).clone();
 				out.reverse();
 				Self::Lazy(Rc::new(out))
 			}
-			ArrValue::Eager(vec) => {
+			Self::Eager(vec) => {
 				let mut out = (&vec as &Vec<_>).clone();
 				out.reverse();
 				Self::Eager(Rc::new(out))
 			}
-			ArrValue::Extended(b) => ArrValue::Extended(Box::new((b.1.reversed(), b.0.reversed()))),
+			Self::Extended(b) => Self::Extended(Box::new((b.1.reversed(), b.0.reversed()))),
 		}
 	}
 
-	pub fn ptr_eq(a: &ArrValue, b: &ArrValue) -> bool {
+	pub fn ptr_eq(a: &Self, b: &Self) -> bool {
 		match (a, b) {
-			(ArrValue::Lazy(a), ArrValue::Lazy(b)) => Rc::ptr_eq(a, b),
-			(ArrValue::Eager(a), ArrValue::Eager(b)) => Rc::ptr_eq(a, b),
+			(Self::Lazy(a), Self::Lazy(b)) => Rc::ptr_eq(a, b),
+			(Self::Eager(a), Self::Eager(b)) => Rc::ptr_eq(a, b),
 			_ => false,
 		}
 	}
@@ -359,7 +356,7 @@
 		self.assert_type(context, ValType::Num)?;
 		self.unwrap_num()
 	}
-	pub fn value_type(&self) -> ValType {
+	pub const fn value_type(&self) -> ValType {
 		match self {
 			Self::Str(..) => ValType::Str,
 			Self::Num(..) => ValType::Num,
@@ -378,7 +375,7 @@
 			Self::Null => "null".into(),
 			Self::Str(s) => s.clone(),
 			v => manifest_json_ex(
-				&v,
+				v,
 				&ManifestJsonOptions {
 					padding: "",
 					mtype: ManifestType::ToString,
@@ -556,7 +553,7 @@
 		(Val::Obj(_), Val::Obj(_)) => throw!(RuntimeError(
 			"primitiveEquals operates on primitive types, got object".into(),
 		)),
-		(a, b) if is_function_like(&a) && is_function_like(&b) => {
+		(a, b) if is_function_like(a) && is_function_like(b) => {
 			throw!(RuntimeError("cannot test equality of functions".into()))
 		}
 		(_, _) => false,
@@ -598,6 +595,6 @@
 			}
 			Ok(true)
 		}
-		(a, b) => Ok(primitive_equals(&a, &b)?),
+		(a, b) => Ok(primitive_equals(a, b)?),
 	}
 }
modifiedcrates/jrsonnet-interner/src/lib.rsdiffbeforeafterboth
--- a/crates/jrsonnet-interner/src/lib.rs
+++ b/crates/jrsonnet-interner/src/lib.rs
@@ -68,7 +68,7 @@
 		IStr(STR_POOL.with(|pool| {
 			let mut pool = pool.borrow_mut();
 			if let Some((k, _)) = pool.get_key_value(str) {
-				return k.clone();
+				k.clone()
 			} else {
 				let rc: Rc<str> = str.into();
 				pool.insert(rc.clone(), ());
modifiedcrates/jrsonnet-types/src/lib.rsdiffbeforeafterboth
--- a/crates/jrsonnet-types/src/lib.rs
+++ b/crates/jrsonnet-types/src/lib.rs
@@ -133,10 +133,8 @@
 	union: &[ComplexValType],
 ) -> std::fmt::Result {
 	for (i, v) in union.iter().enumerate() {
-		let should_add_braces = match v {
-			ComplexValType::UnionRef(_) | ComplexValType::Union(_) if !is_union => true,
-			_ => false,
-		};
+		let should_add_braces =
+			matches!(v, ComplexValType::UnionRef(_) | ComplexValType::Union(_) if !is_union);
 		if i != 0 {
 			write!(f, " {} ", if is_union { '|' } else { '&' })?;
 		}