git.delta.rocks / jrsonnet / refs/commits / cb765629121c

difftreelog

style fix clippy warnings

Yaroslav Bolyukin2023-07-27parent: #5dc3b98.patch.diff
in: master

11 files changed

modifiedcrates/jrsonnet-evaluator/src/dynamic.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/dynamic.rs
+++ b/crates/jrsonnet-evaluator/src/dynamic.rs
@@ -22,7 +22,7 @@
 		self.0
 			.set(value)
 			.map_err(|_| ())
-			.expect("wrapper is filled already")
+			.expect("wrapper is filled already");
 	}
 }
 impl<T: Clone + Trace + 'static> Pending<T> {
@@ -53,8 +53,8 @@
 	}
 }
 
-impl<T: Trace + Clone> Into<Thunk<T>> for Pending<T> {
-	fn into(self) -> Thunk<T> {
-		Thunk::new(self)
+impl<T: Trace + Clone> From<Pending<T>> for Thunk<T> {
+	fn from(value: Pending<T>) -> Self {
+		Self::new(value)
 	}
 }
modifiedcrates/jrsonnet-evaluator/src/evaluate/mod.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/evaluate/mod.rs
+++ b/crates/jrsonnet-evaluator/src/evaluate/mod.rs
@@ -294,7 +294,7 @@
 	// We have single context for all fields, so we can cache binds
 	let uctx = CachedUnbound::new(evaluate_object_locals(fctx.clone(), locals));
 
-	for member in members.iter() {
+	for member in members {
 		match member {
 			Member::Field(field) => {
 				evaluate_field_member(&mut builder, ctx.clone(), uctx.clone(), field)?;
modifiedcrates/jrsonnet-evaluator/src/function/arglike.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/function/arglike.rs
+++ b/crates/jrsonnet-evaluator/src/function/arglike.rs
@@ -210,14 +210,14 @@
 		tailstrict: bool,
 		handler: &mut dyn FnMut(&IStr, Thunk<Val>) -> Result<()>,
 	) -> Result<()> {
-		for (name, value) in self.iter() {
+		for (name, value) in self {
 			handler(name, value.evaluate_arg(ctx.clone(), tailstrict)?)?;
 		}
 		Ok(())
 	}
 
 	fn named_names(&self, handler: &mut dyn FnMut(&IStr)) {
-		for (name, _) in self.iter() {
+		for (name, _) in self {
 			handler(name);
 		}
 	}
modifiedcrates/jrsonnet-evaluator/src/lib.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/lib.rs
+++ b/crates/jrsonnet-evaluator/src/lib.rs
@@ -39,6 +39,8 @@
 	clippy::type_repetition_in_bounds,
 	// ci is being run with nightly, but library should work on stable
 	clippy::missing_const_for_fn,
+	// too many false-positives with .expect() calls
+	clippy::missing_panics_doc,
 )]
 
 // For jrsonnet-macros
modifiedcrates/jrsonnet-evaluator/src/map.rsdiffbeforeafterboth
before · crates/jrsonnet-evaluator/src/map.rs
1use jrsonnet_gcmodule::{Cc, Trace};2use jrsonnet_interner::IStr;34use crate::{GcHashMap, Thunk, Val};56#[derive(Trace)]7#[trace(tracking(force))]8pub struct LayeredHashMapInternals {9	parent: Option<LayeredHashMap>,10	current: GcHashMap<IStr, Thunk<Val>>,11}1213#[derive(Trace)]14pub struct LayeredHashMap(Cc<LayeredHashMapInternals>);1516impl LayeredHashMap {17	pub fn iter_keys(self, mut handler: impl FnMut(IStr)) {18		for (k, _) in self.0.current.iter() {19			handler(k.clone());20		}21		if let Some(parent) = self.0.parent.clone() {22			parent.iter_keys(handler);23		}24	}2526	pub(crate) fn new(layer: GcHashMap<IStr, Thunk<Val>>) -> Self {27		Self(Cc::new(LayeredHashMapInternals {28			parent: None,29			current: layer,30		}))31	}3233	pub fn extend(self, new_layer: GcHashMap<IStr, Thunk<Val>>) -> Self {34		Self(Cc::new(LayeredHashMapInternals {35			parent: Some(self),36			current: new_layer,37		}))38	}3940	pub fn get(&self, key: &IStr) -> Option<&Thunk<Val>> {41		(self.0)42			.current43			.get(key)44			.or_else(|| self.0.parent.as_ref().and_then(|p| p.get(key)))45	}4647	pub fn contains_key(&self, key: &IStr) -> bool {48		(self.0).current.contains_key(key)49			|| self50				.051				.parent52				.as_ref()53				.map_or(false, |p| p.contains_key(key))54	}55}5657impl Clone for LayeredHashMap {58	fn clone(&self) -> Self {59		Self(self.0.clone())60	}61}6263impl Default for LayeredHashMap {64	fn default() -> Self {65		Self(Cc::new(LayeredHashMapInternals {66			parent: None,67			current: GcHashMap::new(),68		}))69	}70}
after · crates/jrsonnet-evaluator/src/map.rs
1use jrsonnet_gcmodule::{Cc, Trace};2use jrsonnet_interner::IStr;34use crate::{GcHashMap, Thunk, Val};56#[derive(Trace)]7#[trace(tracking(force))]8pub struct LayeredHashMapInternals {9	parent: Option<LayeredHashMap>,10	current: GcHashMap<IStr, Thunk<Val>>,11}1213#[derive(Trace)]14pub struct LayeredHashMap(Cc<LayeredHashMapInternals>);1516impl LayeredHashMap {17	pub fn iter_keys(self, mut handler: impl FnMut(IStr)) {18		for (k, _) in &*self.0.current {19			handler(k.clone());20		}21		if let Some(parent) = self.0.parent.clone() {22			parent.iter_keys(handler);23		}24	}2526	pub(crate) fn new(layer: GcHashMap<IStr, Thunk<Val>>) -> Self {27		Self(Cc::new(LayeredHashMapInternals {28			parent: None,29			current: layer,30		}))31	}3233	pub fn extend(self, new_layer: GcHashMap<IStr, Thunk<Val>>) -> Self {34		Self(Cc::new(LayeredHashMapInternals {35			parent: Some(self),36			current: new_layer,37		}))38	}3940	pub fn get(&self, key: &IStr) -> Option<&Thunk<Val>> {41		(self.0)42			.current43			.get(key)44			.or_else(|| self.0.parent.as_ref().and_then(|p| p.get(key)))45	}4647	pub fn contains_key(&self, key: &IStr) -> bool {48		(self.0).current.contains_key(key)49			|| self50				.051				.parent52				.as_ref()53				.map_or(false, |p| p.contains_key(key))54	}55}5657impl Clone for LayeredHashMap {58	fn clone(&self) -> Self {59		Self(self.0.clone())60	}61}6263impl Default for LayeredHashMap {64	fn default() -> Self {65		Self(Cc::new(LayeredHashMapInternals {66			parent: None,67			current: GcHashMap::new(),68		}))69	}70}
modifiedcrates/jrsonnet-evaluator/src/typed/mod.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/typed/mod.rs
+++ b/crates/jrsonnet-evaluator/src/typed/mod.rs
@@ -206,7 +206,7 @@
 			},
 			Self::ObjectRef(elems) => match value {
 				Val::Obj(obj) => {
-					for (k, v) in elems.iter() {
+					for (k, v) in *elems {
 						if let Some(got_v) = obj.get((*k).into())? {
 							push_type_description(
 								|| format!("property {k}"),
@@ -225,7 +225,7 @@
 			},
 			Self::Union(types) => {
 				let mut errors = Vec::new();
-				for ty in types.iter() {
+				for ty in types {
 					match ty.check(value) {
 						Ok(()) => {
 							return Ok(());
@@ -240,7 +240,7 @@
 			}
 			Self::UnionRef(types) => {
 				let mut errors = Vec::new();
-				for ty in types.iter() {
+				for ty in *types {
 					match ty.check(value) {
 						Ok(()) => {
 							return Ok(());
@@ -254,13 +254,13 @@
 				Err(TypeError::UnionFailed(self.clone(), TypeLocErrorList(errors)).into())
 			}
 			Self::Sum(types) => {
-				for ty in types.iter() {
+				for ty in types {
 					ty.check(value)?;
 				}
 				Ok(())
 			}
 			Self::SumRef(types) => {
-				for ty in types.iter() {
+				for ty in *types {
 					ty.check(value)?;
 				}
 				Ok(())
modifiedcrates/jrsonnet-evaluator/src/val.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/val.rs
+++ b/crates/jrsonnet-evaluator/src/val.rs
@@ -346,15 +346,14 @@
 impl Eq for StrValue {}
 impl PartialOrd for StrValue {
 	fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
-		let a = self.clone().into_flat();
-		let b = other.clone().into_flat();
-		Some(a.cmp(&b))
+		Some(self.cmp(other))
 	}
 }
 impl Ord for StrValue {
 	fn cmp(&self, other: &Self) -> std::cmp::Ordering {
-		self.partial_cmp(other)
-			.expect("partial_cmp always returns Some")
+		let a = self.clone().into_flat();
+		let b = other.clone().into_flat();
+		a.cmp(&b)
 	}
 }
 
modifiedcrates/jrsonnet-interner/src/inner.rsdiffbeforeafterboth
--- a/crates/jrsonnet-interner/src/inner.rs
+++ b/crates/jrsonnet-interner/src/inner.rs
@@ -217,7 +217,7 @@
 impl Eq for Inner {}
 impl PartialOrd for Inner {
 	fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> {
-		self.as_slice().partial_cmp(other.as_slice())
+		Some(self.cmp(other))
 	}
 }
 impl Ord for Inner {
modifiedcrates/jrsonnet-macros/src/lib.rsdiffbeforeafterboth
--- a/crates/jrsonnet-macros/src/lib.rs
+++ b/crates/jrsonnet-macros/src/lib.rs
@@ -591,7 +591,7 @@
 		.map(TypedField::parse)
 		.collect::<Result<Vec<_>>>()?;
 
-	let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl( );
+	let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl();
 
 	let typed = {
 		let fields = fields
modifiedcrates/jrsonnet-stdlib/src/sort.rsdiffbeforeafterboth
--- a/crates/jrsonnet-stdlib/src/sort.rs
+++ b/crates/jrsonnet-stdlib/src/sort.rs
@@ -26,13 +26,13 @@
 struct NonNaNf64(f64);
 impl PartialOrd for NonNaNf64 {
 	fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
-		self.0.partial_cmp(&other.0)
+		Some(self.cmp(other))
 	}
 }
 impl Eq for NonNaNf64 {}
 impl Ord for NonNaNf64 {
 	fn cmp(&self, other: &Self) -> std::cmp::Ordering {
-		self.partial_cmp(other).expect("non nan")
+		self.0.partial_cmp(&other.0).expect("non nan")
 	}
 }
 
modifiedflake.nixdiffbeforeafterboth
--- a/flake.nix
+++ b/flake.nix
@@ -17,7 +17,7 @@
           overlays = [ rust-overlay.overlays.default ];
         };
         rust = ((pkgs.rustChannelOf { date = "2023-07-23"; channel = "nightly"; }).default.override {
-          extensions = [ "rust-src" "miri" "rust-analyzer" ];
+          extensions = [ "rust-src" "miri" "rust-analyzer" "clippy" ];
         });
       in
       rec {