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
--- a/crates/jrsonnet-evaluator/src/typed.rs
+++ b/crates/jrsonnet-evaluator/src/typed.rs
@@ -29,7 +29,7 @@
 pub struct TypeLocError(Box<TypeError>, ValuePathStack);
 impl From<TypeError> for TypeLocError {
 	fn from(e: TypeError) -> Self {
-		TypeLocError(Box::new(e), ValuePathStack(Vec::new()))
+		Self(Box::new(e), ValuePathStack(Vec::new()))
 	}
 }
 impl From<TypeLocError> for LocError {
@@ -61,7 +61,7 @@
 			write!(out, "{}", err)?;
 
 			for (i, line) in out.lines().enumerate() {
-				if line.trim().len() == 0 {
+				if line.trim().is_empty() {
 					continue;
 				}
 				if i != 0 {
@@ -118,8 +118,8 @@
 impl Display for ValuePathItem {
 	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
 		match self {
-			ValuePathItem::Field(name) => write!(f, ".{}", name)?,
-			ValuePathItem::Index(idx) => write!(f, "[{}]", idx)?,
+			Self::Field(name) => write!(f, ".{}", name)?,
+			Self::Index(idx) => write!(f, "[{}]", idx)?,
 		}
 		Ok(())
 	}
@@ -140,25 +140,25 @@
 impl CheckType for ComplexValType {
 	fn check(&self, value: &Val) -> Result<()> {
 		match self {
-			ComplexValType::Any => Ok(()),
-			ComplexValType::Simple(s) => s.check(value),
-			ComplexValType::Char => match value {
+			Self::Any => Ok(()),
+			Self::Simple(s) => s.check(value),
+			Self::Char => match value {
 				Val::Str(s) if s.len() == 1 || s.chars().count() == 1 => Ok(()),
 				v => Err(TypeError::ExpectedGot(self.clone(), v.value_type()).into()),
 			},
-			ComplexValType::BoundedNumber(from, to) => {
+			Self::BoundedNumber(from, to) => {
 				if let Val::Num(n) = value {
 					if from.map(|from| from > *n).unwrap_or(false)
 						|| to.map(|to| to <= *n).unwrap_or(false)
 					{
-						return Err(TypeError::BoundsFailed(*n, from.clone(), to.clone()).into());
+						return Err(TypeError::BoundsFailed(*n, *from, *to).into());
 					}
 					Ok(())
 				} else {
 					Err(TypeError::ExpectedGot(self.clone(), value.value_type()).into())
 				}
 			}
-			ComplexValType::Array(elem_type) => match value {
+			Self::Array(elem_type) => match value {
 				Val::Arr(a) => {
 					for (i, item) in a.iter().enumerate() {
 						push_type(
@@ -170,9 +170,9 @@
 					}
 					Ok(())
 				}
-				v => return Err(TypeError::ExpectedGot(self.clone(), v.value_type()).into()),
+				v => Err(TypeError::ExpectedGot(self.clone(), v.value_type()).into()),
 			},
-			ComplexValType::ArrayRef(elem_type) => match value {
+			Self::ArrayRef(elem_type) => match value {
 				Val::Arr(a) => {
 					for (i, item) in a.iter().enumerate() {
 						push_type(
@@ -184,9 +184,9 @@
 					}
 					Ok(())
 				}
-				v => return Err(TypeError::ExpectedGot(self.clone(), v.value_type()).into()),
+				v => Err(TypeError::ExpectedGot(self.clone(), v.value_type()).into()),
 			},
-			ComplexValType::ObjectRef(elems) => match value {
+			Self::ObjectRef(elems) => match value {
 				Val::Obj(obj) => {
 					for (k, v) in elems.iter() {
 						if let Some(got_v) = obj.get((*k).into())? {
@@ -202,11 +202,11 @@
 							);
 						}
 					}
-					return Ok(());
+					Ok(())
 				}
-				v => return Err(TypeError::ExpectedGot(self.clone(), v.value_type()).into()),
+				v => Err(TypeError::ExpectedGot(self.clone(), v.value_type()).into()),
 			},
-			ComplexValType::Union(types) => {
+			Self::Union(types) => {
 				let mut errors = Vec::new();
 				for ty in types.iter() {
 					match ty.check(value) {
@@ -219,9 +219,9 @@
 						},
 					}
 				}
-				return Err(TypeError::UnionFailed(self.clone(), TypeLocErrorList(errors)).into());
+				Err(TypeError::UnionFailed(self.clone(), TypeLocErrorList(errors)).into())
 			}
-			ComplexValType::UnionRef(types) => {
+			Self::UnionRef(types) => {
 				let mut errors = Vec::new();
 				for ty in types.iter() {
 					match ty.check(value) {
@@ -234,15 +234,15 @@
 						},
 					}
 				}
-				return Err(TypeError::UnionFailed(self.clone(), TypeLocErrorList(errors)).into());
+				Err(TypeError::UnionFailed(self.clone(), TypeLocErrorList(errors)).into())
 			}
-			ComplexValType::Sum(types) => {
+			Self::Sum(types) => {
 				for ty in types.iter() {
 					ty.check(value)?
 				}
 				Ok(())
 			}
-			ComplexValType::SumRef(types) => {
+			Self::SumRef(types) => {
 				for ty in types.iter() {
 					ty.check(value)?
 				}
modifiedcrates/jrsonnet-evaluator/src/val.rsdiffbeforeafterboth
176pub enum ArrValue {176pub enum ArrValue {
177 Lazy(Rc<Vec<LazyVal>>),177 Lazy(Rc<Vec<LazyVal>>),
178 Eager(Rc<Vec<Val>>),178 Eager(Rc<Vec<Val>>),
179 Extended(Box<(ArrValue, ArrValue)>),179 Extended(Box<(Self, Self)>),
180}180}
181impl ArrValue {181impl ArrValue {
182 pub fn len(&self) -> usize {182 pub fn len(&self) -> usize {
183 match self {183 match self {
184 ArrValue::Lazy(l) => l.len(),184 Self::Lazy(l) => l.len(),
185 ArrValue::Eager(e) => e.len(),185 Self::Eager(e) => e.len(),
186 ArrValue::Extended(v) => v.0.len() + v.1.len(),186 Self::Extended(v) => v.0.len() + v.1.len(),
187 }187 }
188 }188 }
189189
193193
194 pub fn get(&self, index: usize) -> Result<Option<Val>> {194 pub fn get(&self, index: usize) -> Result<Option<Val>> {
195 match self {195 match self {
196 ArrValue::Lazy(vec) => {196 Self::Lazy(vec) => {
197 if let Some(v) = vec.get(index) {197 if let Some(v) = vec.get(index) {
198 Ok(Some(v.evaluate()?))198 Ok(Some(v.evaluate()?))
199 } else {199 } else {
200 Ok(None)200 Ok(None)
201 }201 }
202 }202 }
203 ArrValue::Eager(vec) => Ok(vec.get(index).cloned()),203 Self::Eager(vec) => Ok(vec.get(index).cloned()),
204 ArrValue::Extended(v) => {204 Self::Extended(v) => {
205 let a_len = v.0.len();205 let a_len = v.0.len();
206 if a_len > index {206 if a_len > index {
207 v.0.get(index)207 v.0.get(index)
214214
215 pub fn get_lazy(&self, index: usize) -> Option<LazyVal> {215 pub fn get_lazy(&self, index: usize) -> Option<LazyVal> {
216 match self {216 match self {
217 ArrValue::Lazy(vec) => vec.get(index).cloned(),217 Self::Lazy(vec) => vec.get(index).cloned(),
218 ArrValue::Eager(vec) => vec218 Self::Eager(vec) => vec.get(index).cloned().map(LazyVal::new_resolved),
219 .get(index)
220 .cloned()
221 .map(|val| LazyVal::new_resolved(val)),
222 ArrValue::Extended(v) => {219 Self::Extended(v) => {
223 let a_len = v.0.len();220 let a_len = v.0.len();
224 if a_len > index {221 if a_len > index {
225 v.0.get_lazy(index)222 v.0.get_lazy(index)
232229
233 pub fn evaluated(&self) -> Result<Rc<Vec<Val>>> {230 pub fn evaluated(&self) -> Result<Rc<Vec<Val>>> {
234 Ok(match self {231 Ok(match self {
235 ArrValue::Lazy(vec) => {232 Self::Lazy(vec) => {
236 let mut out = Vec::with_capacity(vec.len());233 let mut out = Vec::with_capacity(vec.len());
237 for item in vec.iter() {234 for item in vec.iter() {
238 out.push(item.evaluate()?);235 out.push(item.evaluate()?);
239 }236 }
240 Rc::new(out)237 Rc::new(out)
241 }238 }
242 ArrValue::Eager(vec) => vec.clone(),239 Self::Eager(vec) => vec.clone(),
243 ArrValue::Extended(v) => {240 Self::Extended(_v) => {
244 let mut out = Vec::with_capacity(self.len());241 let mut out = Vec::with_capacity(self.len());
245 for item in self.iter() {242 for item in self.iter() {
246 out.push(item?);243 out.push(item?);
252249
253 pub fn iter(&self) -> impl DoubleEndedIterator<Item = Result<Val>> + '_ {250 pub fn iter(&self) -> impl DoubleEndedIterator<Item = Result<Val>> + '_ {
254 (0..self.len()).map(move |idx| match self {251 (0..self.len()).map(move |idx| match self {
255 ArrValue::Lazy(l) => l[idx].evaluate(),252 Self::Lazy(l) => l[idx].evaluate(),
256 ArrValue::Eager(e) => Ok(e[idx].clone()),253 Self::Eager(e) => Ok(e[idx].clone()),
257 ArrValue::Extended(_) => self.get(idx).map(|e| e.unwrap()),254 Self::Extended(_) => self.get(idx).map(|e| e.unwrap()),
258 })255 })
259 }256 }
260257
261 pub fn iter_lazy(&self) -> impl DoubleEndedIterator<Item = LazyVal> + '_ {258 pub fn iter_lazy(&self) -> impl DoubleEndedIterator<Item = LazyVal> + '_ {
262 (0..self.len()).map(move |idx| match self {259 (0..self.len()).map(move |idx| match self {
263 ArrValue::Lazy(l) => l[idx].clone(),260 Self::Lazy(l) => l[idx].clone(),
264 ArrValue::Eager(e) => LazyVal::new_resolved(e[idx].clone()),261 Self::Eager(e) => LazyVal::new_resolved(e[idx].clone()),
265 ArrValue::Extended(_) => self.get_lazy(idx).unwrap(),262 Self::Extended(_) => self.get_lazy(idx).unwrap(),
266 })263 })
267 }264 }
268265
269 pub fn reversed(self) -> Self {266 pub fn reversed(self) -> Self {
270 match self {267 match self {
271 ArrValue::Lazy(vec) => {268 Self::Lazy(vec) => {
272 let mut out = (&vec as &Vec<_>).clone();269 let mut out = (&vec as &Vec<_>).clone();
273 out.reverse();270 out.reverse();
274 Self::Lazy(Rc::new(out))271 Self::Lazy(Rc::new(out))
275 }272 }
276 ArrValue::Eager(vec) => {273 Self::Eager(vec) => {
277 let mut out = (&vec as &Vec<_>).clone();274 let mut out = (&vec as &Vec<_>).clone();
278 out.reverse();275 out.reverse();
279 Self::Eager(Rc::new(out))276 Self::Eager(Rc::new(out))
280 }277 }
281 ArrValue::Extended(b) => ArrValue::Extended(Box::new((b.1.reversed(), b.0.reversed()))),278 Self::Extended(b) => Self::Extended(Box::new((b.1.reversed(), b.0.reversed()))),
282 }279 }
283 }280 }
284281
285 pub fn ptr_eq(a: &ArrValue, b: &ArrValue) -> bool {282 pub fn ptr_eq(a: &Self, b: &Self) -> bool {
286 match (a, b) {283 match (a, b) {
287 (ArrValue::Lazy(a), ArrValue::Lazy(b)) => Rc::ptr_eq(a, b),284 (Self::Lazy(a), Self::Lazy(b)) => Rc::ptr_eq(a, b),
288 (ArrValue::Eager(a), ArrValue::Eager(b)) => Rc::ptr_eq(a, b),285 (Self::Eager(a), Self::Eager(b)) => Rc::ptr_eq(a, b),
289 _ => false,286 _ => false,
290 }287 }
291 }288 }
359 self.assert_type(context, ValType::Num)?;356 self.assert_type(context, ValType::Num)?;
360 self.unwrap_num()357 self.unwrap_num()
361 }358 }
362 pub fn value_type(&self) -> ValType {359 pub const fn value_type(&self) -> ValType {
363 match self {360 match self {
364 Self::Str(..) => ValType::Str,361 Self::Str(..) => ValType::Str,
365 Self::Num(..) => ValType::Num,362 Self::Num(..) => ValType::Num,
378 Self::Null => "null".into(),375 Self::Null => "null".into(),
379 Self::Str(s) => s.clone(),376 Self::Str(s) => s.clone(),
380 v => manifest_json_ex(377 v => manifest_json_ex(
381 &v,378 v,
382 &ManifestJsonOptions {379 &ManifestJsonOptions {
383 padding: "",380 padding: "",
384 mtype: ManifestType::ToString,381 mtype: ManifestType::ToString,
556 (Val::Obj(_), Val::Obj(_)) => throw!(RuntimeError(553 (Val::Obj(_), Val::Obj(_)) => throw!(RuntimeError(
557 "primitiveEquals operates on primitive types, got object".into(),554 "primitiveEquals operates on primitive types, got object".into(),
558 )),555 )),
559 (a, b) if is_function_like(&a) && is_function_like(&b) => {556 (a, b) if is_function_like(a) && is_function_like(b) => {
560 throw!(RuntimeError("cannot test equality of functions".into()))557 throw!(RuntimeError("cannot test equality of functions".into()))
561 }558 }
562 (_, _) => false,559 (_, _) => false,
598 }595 }
599 Ok(true)596 Ok(true)
600 }597 }
601 (a, b) => Ok(primitive_equals(&a, &b)?),598 (a, b) => Ok(primitive_equals(a, b)?),
602 }599 }
603}600}
604601
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 { '&' })?;
 		}