git.delta.rocks / jrsonnet / refs/commits / 70f37833046b

difftreelog

style fix clippy warnings

Yaroslav Bolyukin2022-10-11parent: #afca252.patch.diff
in: master

20 files changed

modifiedbindings/jsonnet/src/lib.rsdiffbeforeafterboth
--- a/bindings/jsonnet/src/lib.rs
+++ b/bindings/jsonnet/src/lib.rs
@@ -70,6 +70,7 @@
 
 /// Creates a new Jsonnet virtual machine.
 #[no_mangle]
+#[allow(clippy::box_default)]
 pub extern "C" fn jsonnet_make() -> *mut State {
 	let state = State::default();
 	state.settings_mut().import_resolver = Box::new(FileImportResolver::default());
modifiedcrates/jrsonnet-cli/src/stdlib.rsdiffbeforeafterboth
--- a/crates/jrsonnet-cli/src/stdlib.rs
+++ b/crates/jrsonnet-cli/src/stdlib.rs
@@ -44,7 +44,7 @@
 		if out.len() != 2 {
 			return Err("bad ext-file syntax".to_owned());
 		}
-		let file = read_to_string(&out[1]);
+		let file = read_to_string(out[1]);
 		match file {
 			Ok(content) => Ok(Self {
 				name: out[0].into(),
modifiedcrates/jrsonnet-evaluator/src/error.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/error.rs
+++ b/crates/jrsonnet-evaluator/src/error.rs
@@ -100,7 +100,7 @@
 	#[error("duplicate local var: {0}")]
 	DuplicateLocalVar(IStr),
 
-	#[error("type mismatch: expected {}, got {2} {0}", .1.iter().map(|e| format!("{}", e)).collect::<Vec<_>>().join(", "))]
+	#[error("type mismatch: expected {}, got {2} {0}", .1.iter().map(|e| format!("{e}")).collect::<Vec<_>>().join(", "))]
 	TypeMismatch(&'static str, Vec<ValType>, ValType),
 	#[error("no such field: {}{}", format_empty_str(.0), format_found(.1, "field"))]
 	NoSuchField(IStr, Vec<IStr>),
@@ -113,7 +113,7 @@
 	BindingParameterASecondTime(IStr),
 	#[error("too many args, function has {0}{}", format_signature(.1))]
 	TooManyArgsFunctionHas(usize, FunctionSignature),
-	#[error("function argument is not passed: {}{}", .0.as_ref().map(|n| n.as_str()).unwrap_or("<unnamed>"), format_signature(.1))]
+	#[error("function argument is not passed: {}{}", .0.as_ref().map_or("<unnamed>", IStr::as_str), format_signature(.1))]
 	FunctionParameterNotBoundInCall(Option<IStr>, FunctionSignature),
 
 	#[error("external variable is not defined: {0}")]
@@ -249,7 +249,7 @@
 	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
 		writeln!(f, "{}", self.0 .0)?;
 		for el in &self.0 .1 .0 {
-			writeln!(f, "\t{:?}", el)?;
+			writeln!(f, "\t{el:?}")?;
 		}
 		Ok(())
 	}
modifiedcrates/jrsonnet-evaluator/src/evaluate/mod.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/evaluate/mod.rs
+++ b/crates/jrsonnet-evaluator/src/evaluate/mod.rs
@@ -436,7 +436,7 @@
 		UnaryOp(o, v) => evaluate_unary_op(*o, &evaluate(s, ctx, v)?)?,
 		Var(name) => s.push(
 			CallLocation::new(loc),
-			|| format!("variable <{}> access", name),
+			|| format!("variable <{name}> access"),
 			|| ctx.binding(name.clone())?.evaluate(s.clone()),
 		)?,
 		Index(value, index) => {
@@ -446,7 +446,7 @@
 			) {
 				(Val::Obj(v), Val::Str(key)) => s.push(
 					CallLocation::new(loc),
-					|| format!("field <{}> access", key),
+					|| format!("field <{key}> access"),
 					|| match v.get(s.clone(), key.clone()) {
 						Ok(Some(v)) => Ok(v),
 						#[cfg(not(feature = "friendly-errors"))]
@@ -611,7 +611,7 @@
 				if let Some(value) = expr {
 					Ok(Some(s.push(
 						loc,
-						|| format!("slice {}", desc),
+						|| format!("slice {desc}"),
 						|| T::from_untyped(evaluate(s.clone(), ctx.clone(), value)?, s.clone()),
 					)?))
 				} else {
modifiedcrates/jrsonnet-evaluator/src/evaluate/operator.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/evaluate/operator.rs
+++ b/crates/jrsonnet-evaluator/src/evaluate/operator.rs
@@ -30,8 +30,8 @@
 		(Str(a), Num(b)) => Str(format!("{a}{b}").into()),
 
 		(Str(a), o) | (o, Str(a)) if a.is_empty() => Val::Str(o.clone().to_string(s)?),
-		(Str(a), o) => Str(format!("{}{}", a, o.clone().to_string(s)?).into()),
-		(o, Str(a)) => Str(format!("{}{}", o.clone().to_string(s)?, a).into()),
+		(Str(a), o) => Str(format!("{a}{}", o.clone().to_string(s)?).into()),
+		(o, Str(a)) => Str(format!("{}{a}", o.clone().to_string(s)?).into()),
 
 		(Obj(v1), Obj(v2)) => Obj(v2.extend_from(v1.clone())),
 		(Arr(a), Arr(b)) => {
modifiedcrates/jrsonnet-evaluator/src/function/arglike.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/function/arglike.rs
+++ b/crates/jrsonnet-evaluator/src/function/arglike.rs
@@ -108,7 +108,7 @@
 		handler: &mut dyn FnMut(usize, Thunk<Val>) -> Result<()>,
 	) -> Result<()> {
 		for (idx, el) in self.iter().enumerate() {
-			handler(idx, Thunk::evaluated(el.clone()))?
+			handler(idx, Thunk::evaluated(el.clone()))?;
 		}
 		Ok(())
 	}
modifiedcrates/jrsonnet-evaluator/src/function/parse.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/function/parse.rs
+++ b/crates/jrsonnet-evaluator/src/function/parse.rs
@@ -179,12 +179,7 @@
 		// FIXME: O(n) for arg existence check
 		let id = params
 			.iter()
-			.position(|p| {
-				p.name
-					.as_ref()
-					.map(|v| &v as &str == name as &str)
-					.unwrap_or(false)
-			})
+			.position(|p| p.name.as_ref().map_or(false, |v| v as &str == name as &str))
 			.ok_or_else(|| UnknownFunctionParameter((name as &str).to_owned()))?;
 		if replace(&mut passed_args[id], Some(arg)).is_some() {
 			throw!(BindingParameterASecondTime(name.clone()));
@@ -209,8 +204,7 @@
 					if param
 						.name
 						.as_ref()
-						.map(|v| &v as &str == name as &str)
-						.unwrap_or(false)
+						.map_or(false, |v| v as &str == name as &str)
 					{
 						found = true;
 					}
modifiedcrates/jrsonnet-evaluator/src/import.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/import.rs
+++ b/crates/jrsonnet-evaluator/src/import.rs
@@ -123,15 +123,11 @@
 		};
 		if meta.is_file() {
 			Ok(SourcePath::new(SourceFile::new(
-				path.canonicalize()
-					.map_err(|e| ImportIo(e.to_string()))?
-					.to_owned(),
+				path.canonicalize().map_err(|e| ImportIo(e.to_string()))?,
 			)))
 		} else if meta.is_dir() {
 			Ok(SourcePath::new(SourceDirectory::new(
-				path.canonicalize()
-					.map_err(|e| ImportIo(e.to_string()))?
-					.to_owned(),
+				path.canonicalize().map_err(|e| ImportIo(e.to_string()))?,
 			)))
 		} else {
 			unreachable!("this can't be a symlink")
modifiedcrates/jrsonnet-evaluator/src/integrations/serde.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/integrations/serde.rs
+++ b/crates/jrsonnet-evaluator/src/integrations/serde.rs
@@ -16,7 +16,7 @@
 			Self::Null => Val::Null,
 			Self::Bool(v) => Val::Bool(v),
 			Self::Number(n) => Val::Num(n.as_f64().ok_or_else(|| {
-				RuntimeError(format!("json number can't be represented as jsonnet: {}", n).into())
+				RuntimeError(format!("json number can't be represented as jsonnet: {n}").into())
 			})?),
 			Self::String(s) => Val::Str((&s as &str).into()),
 			Self::Array(a) => {
modifiedcrates/jrsonnet-evaluator/src/lib.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/lib.rs
+++ b/crates/jrsonnet-evaluator/src/lib.rs
@@ -594,7 +594,7 @@
 			.insert(name, TlaArg::String(value));
 	}
 	pub fn add_tla_code(&self, name: IStr, code: &str) -> Result<()> {
-		let source_name = format!("<top-level-arg:{}>", name);
+		let source_name = format!("<top-level-arg:{name}>");
 		let source = Source::new_virtual(source_name.into(), code.into());
 		let parsed = jrsonnet_parser::parse(
 			code,
modifiedcrates/jrsonnet-evaluator/src/obj.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/obj.rs
+++ b/crates/jrsonnet-evaluator/src/obj.rs
@@ -156,9 +156,9 @@
 	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
 		if let Some(super_obj) = self.0.sup.as_ref() {
 			if f.alternate() {
-				write!(f, "{:#?}", super_obj)?;
+				write!(f, "{super_obj:#?}")?;
 			} else {
-				write!(f, "{:?}", super_obj)?;
+				write!(f, "{super_obj:?}")?;
 			}
 			write!(f, " + ")?;
 		}
@@ -395,10 +395,9 @@
 			})?;
 		self.0.value_cache.borrow_mut().insert(
 			key,
-			match &value {
-				Some(v) => CacheValue::Cached(v.clone()),
-				None => CacheValue::NotFound,
-			},
+			value
+				.as_ref()
+				.map_or(CacheValue::NotFound, |v| CacheValue::Cached(v.clone())),
 		);
 		Ok(value)
 	}
modifiedcrates/jrsonnet-evaluator/src/stdlib/format.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/stdlib/format.rs
+++ b/crates/jrsonnet-evaluator/src/stdlib/format.rs
@@ -45,7 +45,7 @@
 		let mut i = 1;
 		while i < bytes.len() {
 			if bytes[i] == b')' {
-				return Ok((&str[1..i as usize], &str[i as usize + 1..]));
+				return Ok((&str[1..i], &str[i + 1..]));
 			}
 			i += 1;
 		}
@@ -310,6 +310,7 @@
 		nums
 	};
 	let neg = iv < 0.0;
+	#[allow(clippy::bool_to_int_with_if)]
 	let zp = padding.saturating_sub(if neg || blank || sign { 1 } else { 0 });
 	let zp2 = zp
 		.max(precision)
@@ -406,6 +407,7 @@
 	ensure_pt: bool,
 	trailing: bool,
 ) {
+	#[allow(clippy::bool_to_int_with_if)]
 	let dot_size = if precision == 0 && !ensure_pt { 0 } else { 1 };
 	padding = padding.saturating_sub(dot_size + precision);
 	render_decimal(out, n.floor(), padding, 0, blank, sign);
@@ -478,10 +480,7 @@
 	precision: Option<usize>,
 ) -> Result<()> {
 	let clfags = &code.cflags;
-	let (fpprec, iprec) = match precision {
-		Some(v) => (v, v),
-		None => (6, 0),
-	};
+	let (fpprec, iprec) = precision.map_or((6, 0), |v| (v, v));
 	let padding = if clfags.zero && !clfags.left {
 		width
 	} else {
@@ -586,8 +585,10 @@
 			}
 		}
 		ConvTypeV::Char => match value.clone() {
-			Val::Num(n) => tmp_out
-				.push(std::char::from_u32(n as u32).ok_or(InvalidUnicodeCodepointGot(n as u32))?),
+			Val::Num(n) => tmp_out.push(
+				std::char::from_u32(n as u32)
+					.ok_or_else(|| InvalidUnicodeCodepointGot(n as u32))?,
+			),
 			Val::Str(s) => {
 				if s.chars().count() != 1 {
 					throw!(RuntimeError(
modifiedcrates/jrsonnet-evaluator/src/stdlib/manifest.rsdiffbeforeafterboth
before · crates/jrsonnet-evaluator/src/stdlib/manifest.rs
1use crate::{2	error::{Error::*, Result},3	throw, State, Val,4};56#[derive(PartialEq, Eq, Clone, Copy)]7pub enum ManifestType {8	// Applied in manifestification9	Manifest,10	/// Used for std.manifestJson11	/// Empty array/objects extends to "[\n\n]" instead of "[ ]" as in manifest12	Std,13	/// No line breaks, used in `obj+''`14	ToString,15	/// Minified json16	Minify,17}1819pub struct ManifestJsonOptions<'s> {20	pub padding: &'s str,21	pub mtype: ManifestType,22	pub newline: &'s str,23	pub key_val_sep: &'s str,24	#[cfg(feature = "exp-preserve-order")]25	pub preserve_order: bool,26}2728pub fn manifest_json_ex(s: State, val: &Val, options: &ManifestJsonOptions<'_>) -> Result<String> {29	let mut out = String::new();30	manifest_json_ex_buf(s, val, &mut out, &mut String::new(), options)?;31	Ok(out)32}33fn manifest_json_ex_buf(34	s: State,35	val: &Val,36	buf: &mut String,37	cur_padding: &mut String,38	options: &ManifestJsonOptions<'_>,39) -> Result<()> {40	use std::fmt::Write;41	let mtype = options.mtype;42	match val {43		Val::Bool(v) => {44			if *v {45				buf.push_str("true");46			} else {47				buf.push_str("false");48			}49		}50		Val::Null => buf.push_str("null"),51		Val::Str(s) => escape_string_json_buf(s, buf),52		Val::Num(n) => write!(buf, "{}", n).unwrap(),53		Val::Arr(items) => {54			buf.push('[');55			if !items.is_empty() {56				if mtype != ManifestType::ToString && mtype != ManifestType::Minify {57					buf.push_str(options.newline);58				}5960				let old_len = cur_padding.len();61				cur_padding.push_str(options.padding);62				for (i, item) in items.iter(s.clone()).enumerate() {63					if i != 0 {64						buf.push(',');65						if mtype == ManifestType::ToString {66							buf.push(' ');67						} else if mtype != ManifestType::Minify {68							buf.push_str(options.newline);69						}70					}71					buf.push_str(cur_padding);72					manifest_json_ex_buf(s.clone(), &item?, buf, cur_padding, options)?;73				}74				cur_padding.truncate(old_len);7576				if mtype != ManifestType::ToString && mtype != ManifestType::Minify {77					buf.push_str(options.newline);78					buf.push_str(cur_padding);79				}80			} else if mtype == ManifestType::Std {81				buf.push_str("\n\n");82				buf.push_str(cur_padding);83			} else if mtype == ManifestType::ToString || mtype == ManifestType::Manifest {84				buf.push(' ');85			}86			buf.push(']');87		}88		Val::Obj(obj) => {89			obj.run_assertions(s.clone())?;90			buf.push('{');91			let fields = obj.fields(92				#[cfg(feature = "exp-preserve-order")]93				options.preserve_order,94			);95			if !fields.is_empty() {96				if mtype != ManifestType::ToString && mtype != ManifestType::Minify {97					buf.push_str(options.newline);98				}99100				let old_len = cur_padding.len();101				cur_padding.push_str(options.padding);102				for (i, field) in fields.into_iter().enumerate() {103					if i != 0 {104						buf.push(',');105						if mtype == ManifestType::ToString {106							buf.push(' ');107						} else if mtype != ManifestType::Minify {108							buf.push_str(options.newline);109						}110					}111					buf.push_str(cur_padding);112					escape_string_json_buf(&field, buf);113					buf.push_str(options.key_val_sep);114					s.push_description(115						|| format!("field <{}> manifestification", field.clone()),116						|| {117							let value = obj.get(s.clone(), field.clone())?.unwrap();118							manifest_json_ex_buf(s.clone(), &value, buf, cur_padding, options)?;119							Ok(Val::Null)120						},121					)?;122				}123				cur_padding.truncate(old_len);124125				if mtype != ManifestType::ToString && mtype != ManifestType::Minify {126					buf.push_str(options.newline);127					buf.push_str(cur_padding);128				}129			} else if mtype == ManifestType::Std {130				buf.push_str("\n\n");131				buf.push_str(cur_padding);132			} else if mtype == ManifestType::ToString || mtype == ManifestType::Manifest {133				buf.push(' ');134			}135			buf.push('}');136		}137		Val::Func(_) => throw!(RuntimeError("tried to manifest function".into())),138	};139	Ok(())140}141142pub fn escape_string_json(s: &str) -> String {143	let mut buf = String::new();144	escape_string_json_buf(s, &mut buf);145	buf146}147148fn escape_string_json_buf(s: &str, buf: &mut String) {149	use std::fmt::Write;150	buf.push('"');151	for c in s.chars() {152		match c {153			'"' => buf.push_str("\\\""),154			'\\' => buf.push_str("\\\\"),155			'\u{0008}' => buf.push_str("\\b"),156			'\u{000c}' => buf.push_str("\\f"),157			'\n' => buf.push_str("\\n"),158			'\r' => buf.push_str("\\r"),159			'\t' => buf.push_str("\\t"),160			c if c < 32 as char || (c >= 127 as char && c <= 159 as char) => {161				write!(buf, "\\u{:04x}", c as u32).unwrap();162			}163			c => buf.push(c),164		}165	}166	buf.push('"');167}168169pub struct ManifestYamlOptions<'s> {170	/// Padding before fields, i.e171	/// ```yaml172	/// a:173	///   b:174	/// ## <- this175	/// ```176	pub padding: &'s str,177	/// Padding before array elements in objects178	/// ```yaml179	/// a:180	///   - 1181	/// ## <- this182	/// ```183	pub arr_element_padding: &'s str,184	/// Should yaml keys appear unescaped, when possible185	/// ```yaml186	/// "safe_key": 1187	/// # vs188	/// safe_key: 1189	/// ```190	pub quote_keys: bool,191	/// If true - then order of fields is preserved as written,192	/// instead of sorting alphabetically193	#[cfg(feature = "exp-preserve-order")]194	pub preserve_order: bool,195}196197/// From <https://github.com/chyh1990/yaml-rust/blob/da52a68615f2ecdd6b7e4567019f280c433c1521/src/emitter.rs#L289>198/// With added date check199fn yaml_needs_quotes(string: &str) -> bool {200	fn need_quotes_spaces(string: &str) -> bool {201		string.starts_with(' ') || string.ends_with(' ')202	}203204	string.is_empty()205		|| need_quotes_spaces(string)206		|| string.starts_with(|c| matches!(c, '&' | '*' | '?' | '|' | '-' | '<' | '>' | '=' | '!' | '%' | '@'))207		|| string.contains(|c| matches!(c, ':' | '{' | '}' | '[' | ']' | ',' | '#' | '`' | '\"' | '\'' | '\\' | '\0'..='\x06' | '\t' | '\n' | '\r' | '\x0e'..='\x1a' | '\x1c'..='\x1f'))208		|| [209			// http://yaml.org/type/bool.html210			// Note: 'y', 'Y', 'n', 'N', is not quoted deliberately, as in libyaml. PyYAML also parse211			// them as string, not booleans, although it is violating the YAML 1.1 specification.212			// See https://github.com/dtolnay/serde-yaml/pull/83#discussion_r152628088.213			"yes", "Yes", "YES", "no", "No", "NO", "True", "TRUE", "true", "False", "FALSE", "false",214			"on", "On", "ON", "off", "Off", "OFF", // http://yaml.org/type/null.html215			"null", "Null", "NULL", "~",216		].contains(&string)217		|| (string.chars().all(|c| matches!(c, '0'..='9' | '-'))218			&& string.chars().filter(|c| *c == '-').count() == 2)219		|| string.starts_with('.')220		|| string.starts_with("0x")221		|| string.parse::<i64>().is_ok()222		|| string.parse::<f64>().is_ok()223}224225pub fn manifest_yaml_ex(s: State, val: &Val, options: &ManifestYamlOptions<'_>) -> Result<String> {226	let mut out = String::new();227	manifest_yaml_ex_buf(s, val, &mut out, &mut String::new(), options)?;228	Ok(out)229}230231#[allow(clippy::too_many_lines)]232fn manifest_yaml_ex_buf(233	s: State,234	val: &Val,235	buf: &mut String,236	cur_padding: &mut String,237	options: &ManifestYamlOptions<'_>,238) -> Result<()> {239	use std::fmt::Write;240	match val {241		Val::Bool(v) => {242			if *v {243				buf.push_str("true");244			} else {245				buf.push_str("false");246			}247		}248		Val::Null => buf.push_str("null"),249		Val::Str(s) => {250			if s.is_empty() {251				buf.push_str("\"\"");252			} else if let Some(s) = s.strip_suffix('\n') {253				buf.push('|');254				for line in s.split('\n') {255					buf.push('\n');256					buf.push_str(cur_padding);257					buf.push_str(options.padding);258					buf.push_str(line);259				}260			} else if !options.quote_keys && !yaml_needs_quotes(s) {261				buf.push_str(s);262			} else {263				escape_string_json_buf(s, buf);264			}265		}266		Val::Num(n) => write!(buf, "{}", *n).unwrap(),267		Val::Arr(a) => {268			if a.is_empty() {269				buf.push_str("[]");270			} else {271				for (i, item) in a.iter(s.clone()).enumerate() {272					if i != 0 {273						buf.push('\n');274						buf.push_str(cur_padding);275					}276					let item = item?;277					buf.push('-');278					match &item {279						Val::Arr(a) if !a.is_empty() => {280							buf.push('\n');281							buf.push_str(cur_padding);282							buf.push_str(options.padding);283						}284						_ => buf.push(' '),285					}286					let extra_padding = match &item {287						Val::Arr(a) => !a.is_empty(),288						Val::Obj(o) => !o.is_empty(),289						_ => false,290					};291					let prev_len = cur_padding.len();292					if extra_padding {293						cur_padding.push_str(options.padding);294					}295					manifest_yaml_ex_buf(s.clone(), &item, buf, cur_padding, options)?;296					cur_padding.truncate(prev_len);297				}298			}299		}300		Val::Obj(o) => {301			if o.is_empty() {302				buf.push_str("{}");303			} else {304				for (i, key) in o305					.fields(306						#[cfg(feature = "exp-preserve-order")]307						options.preserve_order,308					)309					.iter()310					.enumerate()311				{312					if i != 0 {313						buf.push('\n');314						buf.push_str(cur_padding);315					}316					if !options.quote_keys && !yaml_needs_quotes(key) {317						buf.push_str(key);318					} else {319						escape_string_json_buf(key, buf);320					}321					buf.push(':');322					let prev_len = cur_padding.len();323					let item = o.get(s.clone(), key.clone())?.expect("field exists");324					match &item {325						Val::Arr(a) if !a.is_empty() => {326							buf.push('\n');327							buf.push_str(cur_padding);328							buf.push_str(options.arr_element_padding);329							cur_padding.push_str(options.arr_element_padding);330						}331						Val::Obj(o) if !o.is_empty() => {332							buf.push('\n');333							buf.push_str(cur_padding);334							buf.push_str(options.padding);335							cur_padding.push_str(options.padding);336						}337						_ => buf.push(' '),338					}339					manifest_yaml_ex_buf(s.clone(), &item, buf, cur_padding, options)?;340					cur_padding.truncate(prev_len);341				}342			}343		}344		Val::Func(_) => throw!(RuntimeError("tried to manifest function".into())),345	}346	Ok(())347}
after · crates/jrsonnet-evaluator/src/stdlib/manifest.rs
1use crate::{2	error::{Error::*, Result},3	throw, State, Val,4};56#[derive(PartialEq, Eq, Clone, Copy)]7pub enum ManifestType {8	// Applied in manifestification9	Manifest,10	/// Used for std.manifestJson11	/// Empty array/objects extends to "[\n\n]" instead of "[ ]" as in manifest12	Std,13	/// No line breaks, used in `obj+''`14	ToString,15	/// Minified json16	Minify,17}1819pub struct ManifestJsonOptions<'s> {20	pub padding: &'s str,21	pub mtype: ManifestType,22	pub newline: &'s str,23	pub key_val_sep: &'s str,24	#[cfg(feature = "exp-preserve-order")]25	pub preserve_order: bool,26}2728pub fn manifest_json_ex(s: State, val: &Val, options: &ManifestJsonOptions<'_>) -> Result<String> {29	let mut out = String::new();30	manifest_json_ex_buf(s, val, &mut out, &mut String::new(), options)?;31	Ok(out)32}33fn manifest_json_ex_buf(34	s: State,35	val: &Val,36	buf: &mut String,37	cur_padding: &mut String,38	options: &ManifestJsonOptions<'_>,39) -> Result<()> {40	use std::fmt::Write;41	let mtype = options.mtype;42	match val {43		Val::Bool(v) => {44			if *v {45				buf.push_str("true");46			} else {47				buf.push_str("false");48			}49		}50		Val::Null => buf.push_str("null"),51		Val::Str(s) => escape_string_json_buf(s, buf),52		Val::Num(n) => write!(buf, "{n}").unwrap(),53		Val::Arr(items) => {54			buf.push('[');55			if !items.is_empty() {56				if mtype != ManifestType::ToString && mtype != ManifestType::Minify {57					buf.push_str(options.newline);58				}5960				let old_len = cur_padding.len();61				cur_padding.push_str(options.padding);62				for (i, item) in items.iter(s.clone()).enumerate() {63					if i != 0 {64						buf.push(',');65						if mtype == ManifestType::ToString {66							buf.push(' ');67						} else if mtype != ManifestType::Minify {68							buf.push_str(options.newline);69						}70					}71					buf.push_str(cur_padding);72					manifest_json_ex_buf(s.clone(), &item?, buf, cur_padding, options)?;73				}74				cur_padding.truncate(old_len);7576				if mtype != ManifestType::ToString && mtype != ManifestType::Minify {77					buf.push_str(options.newline);78					buf.push_str(cur_padding);79				}80			} else if mtype == ManifestType::Std {81				buf.push_str("\n\n");82				buf.push_str(cur_padding);83			} else if mtype == ManifestType::ToString || mtype == ManifestType::Manifest {84				buf.push(' ');85			}86			buf.push(']');87		}88		Val::Obj(obj) => {89			obj.run_assertions(s.clone())?;90			buf.push('{');91			let fields = obj.fields(92				#[cfg(feature = "exp-preserve-order")]93				options.preserve_order,94			);95			if !fields.is_empty() {96				if mtype != ManifestType::ToString && mtype != ManifestType::Minify {97					buf.push_str(options.newline);98				}99100				let old_len = cur_padding.len();101				cur_padding.push_str(options.padding);102				for (i, field) in fields.into_iter().enumerate() {103					if i != 0 {104						buf.push(',');105						if mtype == ManifestType::ToString {106							buf.push(' ');107						} else if mtype != ManifestType::Minify {108							buf.push_str(options.newline);109						}110					}111					buf.push_str(cur_padding);112					escape_string_json_buf(&field, buf);113					buf.push_str(options.key_val_sep);114					s.push_description(115						|| format!("field <{}> manifestification", field.clone()),116						|| {117							let value = obj.get(s.clone(), field.clone())?.unwrap();118							manifest_json_ex_buf(s.clone(), &value, buf, cur_padding, options)?;119							Ok(Val::Null)120						},121					)?;122				}123				cur_padding.truncate(old_len);124125				if mtype != ManifestType::ToString && mtype != ManifestType::Minify {126					buf.push_str(options.newline);127					buf.push_str(cur_padding);128				}129			} else if mtype == ManifestType::Std {130				buf.push_str("\n\n");131				buf.push_str(cur_padding);132			} else if mtype == ManifestType::ToString || mtype == ManifestType::Manifest {133				buf.push(' ');134			}135			buf.push('}');136		}137		Val::Func(_) => throw!(RuntimeError("tried to manifest function".into())),138	};139	Ok(())140}141142pub fn escape_string_json(s: &str) -> String {143	let mut buf = String::new();144	escape_string_json_buf(s, &mut buf);145	buf146}147148fn escape_string_json_buf(s: &str, buf: &mut String) {149	use std::fmt::Write;150	buf.push('"');151	for c in s.chars() {152		match c {153			'"' => buf.push_str("\\\""),154			'\\' => buf.push_str("\\\\"),155			'\u{0008}' => buf.push_str("\\b"),156			'\u{000c}' => buf.push_str("\\f"),157			'\n' => buf.push_str("\\n"),158			'\r' => buf.push_str("\\r"),159			'\t' => buf.push_str("\\t"),160			c if c < 32 as char || (c >= 127 as char && c <= 159 as char) => {161				write!(buf, "\\u{:04x}", c as u32).unwrap();162			}163			c => buf.push(c),164		}165	}166	buf.push('"');167}168169pub struct ManifestYamlOptions<'s> {170	/// Padding before fields, i.e171	/// ```yaml172	/// a:173	///   b:174	/// ## <- this175	/// ```176	pub padding: &'s str,177	/// Padding before array elements in objects178	/// ```yaml179	/// a:180	///   - 1181	/// ## <- this182	/// ```183	pub arr_element_padding: &'s str,184	/// Should yaml keys appear unescaped, when possible185	/// ```yaml186	/// "safe_key": 1187	/// # vs188	/// safe_key: 1189	/// ```190	pub quote_keys: bool,191	/// If true - then order of fields is preserved as written,192	/// instead of sorting alphabetically193	#[cfg(feature = "exp-preserve-order")]194	pub preserve_order: bool,195}196197/// From <https://github.com/chyh1990/yaml-rust/blob/da52a68615f2ecdd6b7e4567019f280c433c1521/src/emitter.rs#L289>198/// With added date check199fn yaml_needs_quotes(string: &str) -> bool {200	fn need_quotes_spaces(string: &str) -> bool {201		string.starts_with(' ') || string.ends_with(' ')202	}203204	string.is_empty()205		|| need_quotes_spaces(string)206		|| string.starts_with(|c| matches!(c, '&' | '*' | '?' | '|' | '-' | '<' | '>' | '=' | '!' | '%' | '@'))207		|| string.contains(|c| matches!(c, ':' | '{' | '}' | '[' | ']' | ',' | '#' | '`' | '\"' | '\'' | '\\' | '\0'..='\x06' | '\t' | '\n' | '\r' | '\x0e'..='\x1a' | '\x1c'..='\x1f'))208		|| [209			// http://yaml.org/type/bool.html210			// Note: 'y', 'Y', 'n', 'N', is not quoted deliberately, as in libyaml. PyYAML also parse211			// them as string, not booleans, although it is violating the YAML 1.1 specification.212			// See https://github.com/dtolnay/serde-yaml/pull/83#discussion_r152628088.213			"yes", "Yes", "YES", "no", "No", "NO", "True", "TRUE", "true", "False", "FALSE", "false",214			"on", "On", "ON", "off", "Off", "OFF", // http://yaml.org/type/null.html215			"null", "Null", "NULL", "~",216		].contains(&string)217		|| (string.chars().all(|c| matches!(c, '0'..='9' | '-'))218			&& string.chars().filter(|c| *c == '-').count() == 2)219		|| string.starts_with('.')220		|| string.starts_with("0x")221		|| string.parse::<i64>().is_ok()222		|| string.parse::<f64>().is_ok()223}224225pub fn manifest_yaml_ex(s: State, val: &Val, options: &ManifestYamlOptions<'_>) -> Result<String> {226	let mut out = String::new();227	manifest_yaml_ex_buf(s, val, &mut out, &mut String::new(), options)?;228	Ok(out)229}230231#[allow(clippy::too_many_lines)]232fn manifest_yaml_ex_buf(233	s: State,234	val: &Val,235	buf: &mut String,236	cur_padding: &mut String,237	options: &ManifestYamlOptions<'_>,238) -> Result<()> {239	use std::fmt::Write;240	match val {241		Val::Bool(v) => {242			if *v {243				buf.push_str("true");244			} else {245				buf.push_str("false");246			}247		}248		Val::Null => buf.push_str("null"),249		Val::Str(s) => {250			if s.is_empty() {251				buf.push_str("\"\"");252			} else if let Some(s) = s.strip_suffix('\n') {253				buf.push('|');254				for line in s.split('\n') {255					buf.push('\n');256					buf.push_str(cur_padding);257					buf.push_str(options.padding);258					buf.push_str(line);259				}260			} else if !options.quote_keys && !yaml_needs_quotes(s) {261				buf.push_str(s);262			} else {263				escape_string_json_buf(s, buf);264			}265		}266		Val::Num(n) => write!(buf, "{}", *n).unwrap(),267		Val::Arr(a) => {268			if a.is_empty() {269				buf.push_str("[]");270			} else {271				for (i, item) in a.iter(s.clone()).enumerate() {272					if i != 0 {273						buf.push('\n');274						buf.push_str(cur_padding);275					}276					let item = item?;277					buf.push('-');278					match &item {279						Val::Arr(a) if !a.is_empty() => {280							buf.push('\n');281							buf.push_str(cur_padding);282							buf.push_str(options.padding);283						}284						_ => buf.push(' '),285					}286					let extra_padding = match &item {287						Val::Arr(a) => !a.is_empty(),288						Val::Obj(o) => !o.is_empty(),289						_ => false,290					};291					let prev_len = cur_padding.len();292					if extra_padding {293						cur_padding.push_str(options.padding);294					}295					manifest_yaml_ex_buf(s.clone(), &item, buf, cur_padding, options)?;296					cur_padding.truncate(prev_len);297				}298			}299		}300		Val::Obj(o) => {301			if o.is_empty() {302				buf.push_str("{}");303			} else {304				for (i, key) in o305					.fields(306						#[cfg(feature = "exp-preserve-order")]307						options.preserve_order,308					)309					.iter()310					.enumerate()311				{312					if i != 0 {313						buf.push('\n');314						buf.push_str(cur_padding);315					}316					if !options.quote_keys && !yaml_needs_quotes(key) {317						buf.push_str(key);318					} else {319						escape_string_json_buf(key, buf);320					}321					buf.push(':');322					let prev_len = cur_padding.len();323					let item = o.get(s.clone(), key.clone())?.expect("field exists");324					match &item {325						Val::Arr(a) if !a.is_empty() => {326							buf.push('\n');327							buf.push_str(cur_padding);328							buf.push_str(options.arr_element_padding);329							cur_padding.push_str(options.arr_element_padding);330						}331						Val::Obj(o) if !o.is_empty() => {332							buf.push('\n');333							buf.push_str(cur_padding);334							buf.push_str(options.padding);335							cur_padding.push_str(options.padding);336						}337						_ => buf.push(' '),338					}339					manifest_yaml_ex_buf(s.clone(), &item, buf, cur_padding, options)?;340					cur_padding.truncate(prev_len);341				}342			}343		}344		Val::Func(_) => throw!(RuntimeError("tried to manifest function".into())),345	}346	Ok(())347}
modifiedcrates/jrsonnet-evaluator/src/stdlib/mod.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/stdlib/mod.rs
+++ b/crates/jrsonnet-evaluator/src/stdlib/mod.rs
@@ -12,7 +12,7 @@
 pub fn std_format(s: State, str: IStr, vals: Val) -> Result<String> {
 	s.push(
 		CallLocation::native(),
-		|| format!("std.format of {}", str),
+		|| format!("std.format of {str}"),
 		|| {
 			Ok(match vals {
 				Val::Arr(vals) => format_arr(s.clone(), &str, &vals.evaluated(s.clone())?)?,
modifiedcrates/jrsonnet-evaluator/src/trace/mod.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/trace/mod.rs
+++ b/crates/jrsonnet-evaluator/src/trace/mod.rs
@@ -16,12 +16,9 @@
 }
 
 impl PathResolver {
-	/// Will return Self::Relative(cwd), or Self::Absolute on cwd failure
+	/// Will return `Self::Relative(cwd)`, or `Self::Absolute` on cwd failure
 	pub fn new_cwd_fallback() -> Self {
-		match std::env::current_dir() {
-			Ok(v) => Self::Relative(v),
-			Err(_) => Self::Absolute,
-		}
+		std::env::current_dir().map_or(Self::Absolute, Self::Relative)
 	}
 	pub fn resolve(&self, from: &Path) -> String {
 		match self {
@@ -97,10 +94,10 @@
 			use std::fmt::Write;
 
 			writeln!(out)?;
-			let mut n = match path.source_path().path() {
-				Some(r) => self.resolver.resolve(r),
-				None => path.source_path().to_string(),
-			};
+			let mut n = path.source_path().path().map_or_else(
+				|| path.source_path().to_string(),
+				|r| self.resolver.resolve(r),
+			);
 			let mut offset = error.location.offset;
 			let is_eof = if offset >= path.code().len() {
 				offset = path.code().len().saturating_sub(1);
@@ -119,7 +116,7 @@
 
 			write!(n, ":").unwrap();
 			print_code_location(&mut n, &location, &location).unwrap();
-			write!(out, "{:<p$}{}", "", n, p = self.padding,)?;
+			write!(out, "{:<p$}{n}", "", p = self.padding)?;
 		}
 		let file_names = error
 			.trace()
@@ -185,10 +182,10 @@
 			let desc = &item.desc;
 			if let Some(source) = &item.location {
 				let start_end = source.0.map_source_locations(&[source.1, source.2]);
-				let resolved_path = match source.0.source_path().path() {
-					Some(r) => r.display().to_string(),
-					None => source.0.source_path().to_string(),
-				};
+				let resolved_path = source.0.source_path().path().map_or_else(
+					|| source.0.source_path().to_string(),
+					|r| r.display().to_string(),
+				);
 
 				write!(
 					out,
@@ -196,7 +193,7 @@
 					desc, resolved_path, start_end[0].line, start_end[0].column,
 				)?;
 			} else {
-				write!(out, "    during {}", desc)?;
+				write!(out, "    during {desc}")?;
 			}
 		}
 		Ok(())
@@ -252,7 +249,7 @@
 					desc,
 				)?;
 			} else {
-				write!(out, "{}", desc)?;
+				write!(out, "{desc}")?;
 			}
 		}
 		Ok(())
@@ -280,10 +277,10 @@
 			.take(end.line_end_offset - end.line_start_offset)
 			.collect();
 
-		let origin = match origin.source_path().path() {
-			Some(r) => self.resolver.resolve(r),
-			None => origin.source_path().to_string(),
-		};
+		let origin = origin.source_path().path().map_or_else(
+			|| origin.source_path().to_string(),
+			|r| self.resolver.resolve(r),
+		);
 		let snippet = Snippet {
 			opt: FormatOptions {
 				color: true,
@@ -308,7 +305,7 @@
 		};
 
 		let dl = DisplayList::from(snippet);
-		write!(out, "{}", dl)?;
+		write!(out, "{dl}")?;
 
 		Ok(())
 	}
modifiedcrates/jrsonnet-evaluator/src/typed/mod.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/typed/mod.rs
+++ b/crates/jrsonnet-evaluator/src/typed/mod.rs
@@ -21,8 +21,8 @@
 	UnionFailed(ComplexValType, TypeLocErrorList),
 	#[error(
 		"number out of bounds: {0} not in {}..{}",
-		.1.map(|v|v.to_string()).unwrap_or_else(|| "".to_owned()),
-		.2.map(|v|v.to_string()).unwrap_or_else(|| "".to_owned()),
+		.1.map(|v|v.to_string()).unwrap_or_default(),
+		.2.map(|v|v.to_string()).unwrap_or_default(),
 	)]
 	BoundsFailed(f64, Option<f64>, Option<f64>),
 }
@@ -65,7 +65,7 @@
 				writeln!(f)?;
 			}
 			out.clear();
-			write!(out, "{}", err)?;
+			write!(out, "{err}")?;
 
 			for (i, line) in out.lines().enumerate() {
 				if line.trim().is_empty() {
@@ -77,7 +77,7 @@
 					writeln!(f)?;
 					write!(f, "    ")?;
 				}
-				write!(f, "{}", line)?;
+				write!(f, "{line}")?;
 			}
 		}
 		Ok(())
@@ -125,8 +125,8 @@
 impl Display for ValuePathItem {
 	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
 		match self {
-			Self::Field(name) => write!(f, ".{:?}", name)?,
-			Self::Index(idx) => write!(f, "[{}]", idx)?,
+			Self::Field(name) => write!(f, ".{name:?}")?,
+			Self::Index(idx) => write!(f, "[{idx}]")?,
 		}
 		Ok(())
 	}
@@ -138,7 +138,7 @@
 	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
 		write!(f, "self")?;
 		for elem in self.0.iter().rev() {
-			write!(f, "{}", elem)?;
+			write!(f, "{elem}")?;
 		}
 		Ok(())
 	}
@@ -171,7 +171,7 @@
 					for (i, item) in a.iter(s.clone()).enumerate() {
 						push_type_description(
 							s.clone(),
-							|| format!("array index {}", i),
+							|| format!("array index {i}"),
 							|| ValuePathItem::Index(i as u64),
 							|| elem_type.check(s.clone(), &item.clone()?),
 						)?;
@@ -185,7 +185,7 @@
 					for (i, item) in a.iter(s.clone()).enumerate() {
 						push_type_description(
 							s.clone(),
-							|| format!("array index {}", i),
+							|| format!("array index {i}"),
 							|| ValuePathItem::Index(i as u64),
 							|| elem_type.check(s.clone(), &item.clone()?),
 						)?;
@@ -200,7 +200,7 @@
 						if let Some(got_v) = obj.get(s.clone(), (*k).into())? {
 							push_type_description(
 								s.clone(),
-								|| format!("property {}", k),
+								|| format!("property {k}"),
 								|| ValuePathItem::Field((*k).into()),
 								|| v.check(s.clone(), &got_v),
 							)?;
modifiedcrates/jrsonnet-evaluator/src/val.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/val.rs
+++ b/crates/jrsonnet-evaluator/src/val.rs
@@ -292,7 +292,7 @@
 				if index >= v.to() {
 					return Ok(None);
 				}
-				v.inner.get(s, index as usize)
+				v.inner.get(s, index)
 			}
 		}
 	}
@@ -332,7 +332,7 @@
 				if index >= s.to() {
 					return None;
 				}
-				s.inner.get_lazy(index as usize)
+				s.inner.get_lazy(index)
 			}
 		}
 	}
@@ -531,8 +531,9 @@
 	}
 }
 
-#[cfg(target_pointer_width = "64")]
-static_assertions::assert_eq_size!(Val, [u8; 32]);
+// Broken between stable and nightly, as there is new layout size optimization
+// #[cfg(target_pointer_width = "64")]
+// static_assertions::assert_eq_size!(Val, [u8; 24]);
 
 impl Val {
 	pub const fn as_bool(&self) -> Option<bool> {
modifiedcrates/jrsonnet-stdlib/src/encoding.rsdiffbeforeafterboth
--- a/crates/jrsonnet-stdlib/src/encoding.rs
+++ b/crates/jrsonnet-stdlib/src/encoding.rs
@@ -28,7 +28,7 @@
 
 #[builtin]
 pub fn builtin_base64_decode_bytes(input: IStr) -> Result<IBytes> {
-	Ok(base64::decode(&input.as_bytes())
+	Ok(base64::decode(input.as_bytes())
 		.map_err(|_| RuntimeError("bad base64".into()))?
 		.as_slice()
 		.into())
@@ -36,6 +36,6 @@
 
 #[builtin]
 pub fn builtin_base64_decode(input: IStr) -> Result<String> {
-	let bytes = base64::decode(&input.as_bytes()).map_err(|_| RuntimeError("bad base64".into()))?;
+	let bytes = base64::decode(input.as_bytes()).map_err(|_| RuntimeError("bad base64".into()))?;
 	Ok(String::from_utf8(bytes).map_err(|_| RuntimeError("bad utf8".into()))?)
 }
modifiedcrates/jrsonnet-stdlib/src/hash.rsdiffbeforeafterboth
--- a/crates/jrsonnet-stdlib/src/hash.rs
+++ b/crates/jrsonnet-stdlib/src/hash.rs
@@ -2,5 +2,5 @@
 
 #[builtin]
 pub fn builtin_md5(str: IStr) -> Result<String> {
-	Ok(format!("{:x}", md5::compute(&str.as_bytes())))
+	Ok(format!("{:x}", md5::compute(str.as_bytes())))
 }
modifiedcrates/jrsonnet-stdlib/src/lib.rsdiffbeforeafterboth
--- a/crates/jrsonnet-stdlib/src/lib.rs
+++ b/crates/jrsonnet-stdlib/src/lib.rs
@@ -366,7 +366,7 @@
 
 #[builtin]
 fn builtin_substr(str: IStr, from: usize, len: usize) -> Result<String> {
-	Ok(str.chars().skip(from as usize).take(len as usize).collect())
+	Ok(str.chars().skip(from).take(len).collect())
 }
 
 #[builtin(fields(
@@ -380,7 +380,7 @@
 		.ext_vars
 		.get(&x)
 		.cloned()
-		.ok_or(UndefinedExternalVariable(x))?
+		.ok_or_else(|| UndefinedExternalVariable(x))?
 		.evaluate_arg(s.clone(), ctx, true)?
 		.evaluate(s)?))
 }
@@ -402,7 +402,7 @@
 
 #[builtin]
 fn builtin_char(n: u32) -> Result<char> {
-	Ok(std::char::from_u32(n as u32).ok_or(InvalidUnicodeCodepointGot(n as u32))?)
+	Ok(std::char::from_u32(n).ok_or_else(|| InvalidUnicodeCodepointGot(n))?)
 }
 
 #[builtin(fields(