git.delta.rocks / jrsonnet / refs/commits / 2d0d919b58c4

difftreelog

style fix warnings with nightly clippy

Yaroslav Bolyukin2022-05-26parent: #e1e1d4b.patch.diff
in: master

9 files changed

modifiedcrates/jrsonnet-cli/src/trace.rsdiffbeforeafterboth
--- a/crates/jrsonnet-cli/src/trace.rs
+++ b/crates/jrsonnet-cli/src/trace.rs
@@ -9,7 +9,7 @@
 
 use crate::ConfigureState;
 
-#[derive(PartialEq)]
+#[derive(PartialEq, Eq)]
 pub enum TraceFormatName {
 	Compact,
 	Explaining,
modifiedcrates/jrsonnet-evaluator/src/integrations/serde.rsdiffbeforeafterboth
before · crates/jrsonnet-evaluator/src/integrations/serde.rs
1use jrsonnet_types::ComplexValType;2use serde_json::{Map, Number, Value};34use crate::{5	error::{Error::*, Result},6	throw,7	typed::Typed,8	ObjValueBuilder, State, Val,9};1011impl Typed for Value {12	const TYPE: &'static ComplexValType = &ComplexValType::Any;1314	fn into_untyped(value: Self, s: State) -> Result<Val> {15		Ok(match value {16			Value::Null => Val::Null,17			Value::Bool(v) => Val::Bool(v),18			Value::Number(n) => Val::Num(n.as_f64().ok_or_else(|| {19				RuntimeError(format!("json number can't be represented as jsonnet: {}", n).into())20			})?),21			Value::String(s) => Val::Str((&s as &str).into()),22			Value::Array(a) => {23				let mut out: Vec<Val> = Vec::with_capacity(a.len());24				for v in a {25					out.push(Self::into_untyped(v, s.clone())?);26				}27				Val::Arr(out.into())28			}29			Value::Object(o) => {30				let mut builder = ObjValueBuilder::with_capacity(o.len());31				for (k, v) in o {32					builder33						.member((&k as &str).into())34						.value(s.clone(), Self::into_untyped(v, s.clone())?)?;35				}36				Val::Obj(builder.build())37			}38		})39	}4041	fn from_untyped(value: Val, s: State) -> Result<Self> {42		Ok(match value {43			Val::Bool(b) => Self::Bool(b),44			Val::Null => Self::Null,45			Val::Str(s) => Self::String((&s as &str).into()),46			Val::Num(n) => Self::Number(if n.fract() <= f64::EPSILON {47				(n as i64).into()48			} else {49				Number::from_f64(n).expect("jsonnet numbers can't be infinite or NaN")50			}),51			Val::Arr(a) => {52				let mut out = Vec::with_capacity(a.len());53				for item in a.iter(s.clone()) {54					out.push(Self::from_untyped(item?, s.clone())?);55				}56				Self::Array(out)57			}58			Val::Obj(o) => {59				let mut out = Map::new();60				for key in o.fields(61					#[cfg(feature = "exp-preserve-order")]62					cfg!(feature = "exp-serde-preserve-order"),63				) {64					out.insert(65						(&key as &str).into(),66						Self::from_untyped(67							o.get(s.clone(), key)?68								.expect("key is present in fields, so value should exist"),69							s.clone(),70						)?,71					);72				}73				Self::Object(out)74			}75			Val::Func(_) => throw!(RuntimeError("tried to manifest function".into())),76		})77	}78}
after · crates/jrsonnet-evaluator/src/integrations/serde.rs
1use jrsonnet_types::ComplexValType;2use serde_json::{Map, Number, Value};34use crate::{5	error::{Error::*, Result},6	throw,7	typed::Typed,8	ObjValueBuilder, State, Val,9};1011impl Typed for Value {12	const TYPE: &'static ComplexValType = &ComplexValType::Any;1314	fn into_untyped(value: Self, s: State) -> Result<Val> {15		Ok(match value {16			Self::Null => Val::Null,17			Self::Bool(v) => Val::Bool(v),18			Self::Number(n) => Val::Num(n.as_f64().ok_or_else(|| {19				RuntimeError(format!("json number can't be represented as jsonnet: {}", n).into())20			})?),21			Self::String(s) => Val::Str((&s as &str).into()),22			Self::Array(a) => {23				let mut out: Vec<Val> = Vec::with_capacity(a.len());24				for v in a {25					out.push(Self::into_untyped(v, s.clone())?);26				}27				Val::Arr(out.into())28			}29			Self::Object(o) => {30				let mut builder = ObjValueBuilder::with_capacity(o.len());31				for (k, v) in o {32					builder33						.member((&k as &str).into())34						.value(s.clone(), Self::into_untyped(v, s.clone())?)?;35				}36				Val::Obj(builder.build())37			}38		})39	}4041	fn from_untyped(value: Val, s: State) -> Result<Self> {42		Ok(match value {43			Val::Bool(b) => Self::Bool(b),44			Val::Null => Self::Null,45			Val::Str(s) => Self::String((&s as &str).into()),46			Val::Num(n) => Self::Number(if n.fract() <= f64::EPSILON {47				(n as i64).into()48			} else {49				Number::from_f64(n).expect("jsonnet numbers can't be infinite or NaN")50			}),51			Val::Arr(a) => {52				let mut out = Vec::with_capacity(a.len());53				for item in a.iter(s.clone()) {54					out.push(Self::from_untyped(item?, s.clone())?);55				}56				Self::Array(out)57			}58			Val::Obj(o) => {59				let mut out = Map::new();60				for key in o.fields(61					#[cfg(feature = "exp-preserve-order")]62					cfg!(feature = "exp-serde-preserve-order"),63				) {64					out.insert(65						(&key as &str).into(),66						Self::from_untyped(67							o.get(s.clone(), key)?68								.expect("key is present in fields, so value should exist"),69							s.clone(),70						)?,71					);72				}73				Self::Object(out)74			}75			Val::Func(_) => throw!(RuntimeError("tried to manifest function".into())),76		})77	}78}
modifiedcrates/jrsonnet-evaluator/src/lib.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/lib.rs
+++ b/crates/jrsonnet-evaluator/src/lib.rs
@@ -17,6 +17,11 @@
 	clippy::cast_possible_wrap,
 	clippy::cast_possible_truncation,
 	clippy::cast_sign_loss,
+	// False positives
+	// https://github.com/rust-lang/rust-clippy/issues/6902
+	clippy::use_self,
+	// https://github.com/rust-lang/rust-clippy/issues/8539
+	clippy::iter_with_drain,
 )]
 
 // For jrsonnet-macros
modifiedcrates/jrsonnet-evaluator/src/stdlib/format.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/stdlib/format.rs
+++ b/crates/jrsonnet-evaluator/src/stdlib/format.rs
@@ -120,7 +120,7 @@
 	Ok((out, &str[i..]))
 }
 
-#[derive(Debug, PartialEq)]
+#[derive(Debug, PartialEq, Eq)]
 pub enum Width {
 	Star,
 	Fixed(usize),
@@ -174,7 +174,7 @@
 	Ok(((), &str[idx..]))
 }
 
-#[derive(Debug, PartialEq)]
+#[derive(Debug, PartialEq, Eq)]
 pub enum ConvTypeV {
 	Decimal,
 	Octal,
modifiedcrates/jrsonnet-evaluator/src/stdlib/manifest.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/stdlib/manifest.rs
+++ b/crates/jrsonnet-evaluator/src/stdlib/manifest.rs
@@ -3,7 +3,7 @@
 	throw, State, Val,
 };
 
-#[derive(PartialEq, Clone, Copy)]
+#[derive(PartialEq, Eq, Clone, Copy)]
 pub enum ManifestType {
 	// Applied in manifestification
 	Manifest,
modifiedcrates/jrsonnet-evaluator/src/trace/location.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/trace/location.rs
+++ b/crates/jrsonnet-evaluator/src/trace/location.rs
@@ -1,5 +1,5 @@
 #[allow(clippy::module_name_repetitions)]
-#[derive(Clone, PartialEq, Debug)]
+#[derive(Clone, PartialEq, Eq, Debug)]
 pub struct CodeLocation {
 	pub offset: usize,
 
modifiedcrates/jrsonnet-evaluator/src/val.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/val.rs
+++ b/crates/jrsonnet-evaluator/src/val.rs
@@ -476,43 +476,43 @@
 impl Val {
 	pub const fn as_bool(&self) -> Option<bool> {
 		match self {
-			Val::Bool(v) => Some(*v),
+			Self::Bool(v) => Some(*v),
 			_ => None,
 		}
 	}
 	pub const fn as_null(&self) -> Option<()> {
 		match self {
-			Val::Null => Some(()),
+			Self::Null => Some(()),
 			_ => None,
 		}
 	}
 	pub fn as_str(&self) -> Option<IStr> {
 		match self {
-			Val::Str(s) => Some(s.clone()),
+			Self::Str(s) => Some(s.clone()),
 			_ => None,
 		}
 	}
 	pub const fn as_num(&self) -> Option<f64> {
 		match self {
-			Val::Num(n) => Some(*n),
+			Self::Num(n) => Some(*n),
 			_ => None,
 		}
 	}
 	pub fn as_arr(&self) -> Option<ArrValue> {
 		match self {
-			Val::Arr(a) => Some(a.clone()),
+			Self::Arr(a) => Some(a.clone()),
 			_ => None,
 		}
 	}
 	pub fn as_obj(&self) -> Option<ObjValue> {
 		match self {
-			Val::Obj(o) => Some(o.clone()),
+			Self::Obj(o) => Some(o.clone()),
 			_ => None,
 		}
 	}
 	pub fn as_func(&self) -> Option<FuncVal> {
 		match self {
-			Val::Func(f) => Some(f.clone()),
+			Self::Func(f) => Some(f.clone()),
 			_ => None,
 		}
 	}
modifiedcrates/jrsonnet-interner/src/inner.rsdiffbeforeafterboth
--- a/crates/jrsonnet-interner/src/inner.rs
+++ b/crates/jrsonnet-interner/src/inner.rs
@@ -157,7 +157,7 @@
 	pub fn ptr_eq(a: &Self, b: &Self) -> bool {
 		a.0 == b.0
 	}
-	pub fn as_ptr(this: &Self) -> *const u8 {
+	pub const fn as_ptr(this: &Self) -> *const u8 {
 		// SAFETY: data is initialized
 		unsafe { this.0.as_ptr().add(mem::size_of::<InnerHeader>()) }
 	}
modifiedcrates/jrsonnet-parser/src/expr.rsdiffbeforeafterboth
--- a/crates/jrsonnet-parser/src/expr.rs
+++ b/crates/jrsonnet-parser/src/expr.rs
@@ -21,7 +21,7 @@
 }
 
 #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
-#[derive(Debug, Clone, Copy, PartialEq, Trace)]
+#[derive(Debug, Clone, Copy, PartialEq, Eq, Trace)]
 pub enum Visibility {
 	/// :
 	Normal,
@@ -60,7 +60,7 @@
 }
 
 #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
-#[derive(Debug, Clone, Copy, PartialEq, Trace)]
+#[derive(Debug, Clone, Copy, PartialEq, Eq, Trace)]
 pub enum UnaryOpType {
 	Plus,
 	Minus,
@@ -85,7 +85,7 @@
 }
 
 #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
-#[derive(Debug, Clone, Copy, PartialEq, Trace)]
+#[derive(Debug, Clone, Copy, PartialEq, Eq, Trace)]
 pub enum BinaryOpType {
 	Mul,
 	Div,
@@ -179,7 +179,7 @@
 }
 
 #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
-#[derive(Debug, Clone, PartialEq, Trace)]
+#[derive(Debug, Clone, PartialEq, Eq, Trace)]
 pub enum DestructRest {
 	/// ...rest
 	Keep(IStr),
@@ -188,7 +188,7 @@
 }
 
 #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
-#[derive(Debug, Clone, PartialEq, Trace)]
+#[derive(Debug, Clone, PartialEq, Eq, Trace)]
 pub enum Destruct {
 	Full(IStr),
 	#[cfg(feature = "exp-destruct")]
@@ -263,7 +263,7 @@
 }
 
 #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
-#[derive(Debug, PartialEq, Clone, Copy, Trace)]
+#[derive(Debug, PartialEq, Eq, Clone, Copy, Trace)]
 pub enum LiteralType {
 	This,
 	Super,
@@ -357,7 +357,7 @@
 
 /// file, begin offset, end offset
 #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
-#[derive(Clone, PartialEq, Trace)]
+#[derive(Clone, PartialEq, Eq, Trace)]
 #[skip_trace]
 #[repr(C)]
 pub struct ExprLocation(pub Source, pub u32, pub u32);