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
--- a/crates/jrsonnet-evaluator/src/stdlib/manifest.rs
+++ b/crates/jrsonnet-evaluator/src/stdlib/manifest.rs
@@ -49,7 +49,7 @@
 		}
 		Val::Null => buf.push_str("null"),
 		Val::Str(s) => escape_string_json_buf(s, buf),
-		Val::Num(n) => write!(buf, "{}", n).unwrap(),
+		Val::Num(n) => write!(buf, "{n}").unwrap(),
 		Val::Arr(items) => {
 			buf.push('[');
 			if !items.is_empty() {
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
before · crates/jrsonnet-evaluator/src/trace/mod.rs
1use std::path::{Path, PathBuf};23use jrsonnet_parser::{CodeLocation, Source};45use crate::{error::Error, LocError, State};67/// The way paths should be displayed8#[derive(Clone)]9pub enum PathResolver {10	/// Only filename11	FileName,12	/// Absolute path13	Absolute,14	/// Path relative to base directory15	Relative(PathBuf),16}1718impl PathResolver {19	/// Will return Self::Relative(cwd), or Self::Absolute on cwd failure20	pub fn new_cwd_fallback() -> Self {21		match std::env::current_dir() {22			Ok(v) => Self::Relative(v),23			Err(_) => Self::Absolute,24		}25	}26	pub fn resolve(&self, from: &Path) -> String {27		match self {28			Self::FileName => from29				.file_name()30				.expect("file name exists")31				.to_string_lossy()32				.into_owned(),33			Self::Absolute => from.to_string_lossy().into_owned(),34			Self::Relative(base) => {35				if from.is_relative() {36					return from.to_string_lossy().into_owned();37				}38				pathdiff::diff_paths(from, base)39					.expect("base is absolute")40					.to_string_lossy()41					.into_owned()42			}43		}44	}45}4647/// Implements pretty-printing of traces48#[allow(clippy::module_name_repetitions)]49pub trait TraceFormat {50	fn write_trace(51		&self,52		out: &mut dyn std::fmt::Write,53		s: &State,54		error: &LocError,55	) -> Result<(), std::fmt::Error>;56}5758fn print_code_location(59	out: &mut impl std::fmt::Write,60	start: &CodeLocation,61	end: &CodeLocation,62) -> Result<(), std::fmt::Error> {63	if start.line == end.line {64		if start.column == end.column {65			write!(out, "{}:{}", start.line, end.column.saturating_sub(1))?;66		} else {67			write!(out, "{}:{}-{}", start.line, start.column - 1, end.column)?;68		}69	} else {70		write!(71			out,72			"{}:{}-{}:{}",73			start.line,74			end.column.saturating_sub(1),75			start.line,76			end.column77		)?;78	}79	Ok(())80}8182/// vanilla-like jsonnet formatting83pub struct CompactFormat {84	pub resolver: PathResolver,85	pub padding: usize,86}8788impl TraceFormat for CompactFormat {89	fn write_trace(90		&self,91		out: &mut dyn std::fmt::Write,92		_s: &State,93		error: &LocError,94	) -> Result<(), std::fmt::Error> {95		write!(out, "{}", error.error())?;96		if let Error::ImportSyntaxError { path, error } = error.error() {97			use std::fmt::Write;9899			writeln!(out)?;100			let mut n = match path.source_path().path() {101				Some(r) => self.resolver.resolve(r),102				None => path.source_path().to_string(),103			};104			let mut offset = error.location.offset;105			let is_eof = if offset >= path.code().len() {106				offset = path.code().len().saturating_sub(1);107				true108			} else {109				false110			};111			let mut location = path112				.map_source_locations(&[offset as u32])113				.into_iter()114				.next()115				.unwrap();116			if is_eof {117				location.column += 1;118			}119120			write!(n, ":").unwrap();121			print_code_location(&mut n, &location, &location).unwrap();122			write!(out, "{:<p$}{}", "", n, p = self.padding,)?;123		}124		let file_names = error125			.trace()126			.0127			.iter()128			.map(|el| &el.location)129			.map(|location| {130				use std::fmt::Write;131				#[allow(clippy::option_if_let_else)]132				if let Some(location) = location {133					let mut resolved_path = match location.0.source_path().path() {134						Some(r) => self.resolver.resolve(r),135						None => location.0.source_path().to_string(),136					};137					// TODO: Process all trace elements first138					let location = location.0.map_source_locations(&[location.1, location.2]);139					write!(resolved_path, ":").unwrap();140					print_code_location(&mut resolved_path, &location[0], &location[1]).unwrap();141					write!(resolved_path, ":").unwrap();142					Some(resolved_path)143				} else {144					None145				}146			})147			.collect::<Vec<_>>();148		let align = file_names149			.iter()150			.flatten()151			.map(String::len)152			.max()153			.unwrap_or(0);154		for (el, file) in error.trace().0.iter().zip(file_names) {155			writeln!(out)?;156			if let Some(file) = file {157				write!(158					out,159					"{:<p$}{:<w$} {}",160					"",161					file,162					el.desc,163					p = self.padding,164					w = align165				)?;166			} else {167				write!(out, "{:<p$}{}", "", el.desc, p = self.padding,)?;168			}169		}170		Ok(())171	}172}173174pub struct JsFormat;175impl TraceFormat for JsFormat {176	fn write_trace(177		&self,178		out: &mut dyn std::fmt::Write,179		_s: &State,180		error: &LocError,181	) -> Result<(), std::fmt::Error> {182		write!(out, "{}", error.error())?;183		for item in &error.trace().0 {184			writeln!(out)?;185			let desc = &item.desc;186			if let Some(source) = &item.location {187				let start_end = source.0.map_source_locations(&[source.1, source.2]);188				let resolved_path = match source.0.source_path().path() {189					Some(r) => r.display().to_string(),190					None => source.0.source_path().to_string(),191				};192193				write!(194					out,195					"    at {} ({}:{}:{})",196					desc, resolved_path, start_end[0].line, start_end[0].column,197				)?;198			} else {199				write!(out, "    during {}", desc)?;200			}201		}202		Ok(())203	}204}205206/// rustc-like trace displaying207#[cfg(feature = "explaining-traces")]208pub struct ExplainingFormat {209	pub resolver: PathResolver,210}211#[cfg(feature = "explaining-traces")]212impl TraceFormat for ExplainingFormat {213	fn write_trace(214		&self,215		out: &mut dyn std::fmt::Write,216		_s: &State,217		error: &LocError,218	) -> Result<(), std::fmt::Error> {219		write!(out, "{}", error.error())?;220		if let Error::ImportSyntaxError { path, error } = error.error() {221			writeln!(out)?;222			let offset = error.location.offset;223			let location = path224				.map_source_locations(&[offset as u32])225				.into_iter()226				.next()227				.unwrap();228			let mut end_location = location.clone();229			end_location.offset += 1;230231			self.print_snippet(232				out,233				path.code(),234				path,235				&location,236				&end_location,237				"syntax error",238			)?;239		}240		let trace = &error.trace();241		for item in &trace.0 {242			writeln!(out)?;243			let desc = &item.desc;244			if let Some(source) = &item.location {245				let start_end = source.0.map_source_locations(&[source.1, source.2]);246				self.print_snippet(247					out,248					source.0.code(),249					&source.0,250					&start_end[0],251					&start_end[1],252					desc,253				)?;254			} else {255				write!(out, "{}", desc)?;256			}257		}258		Ok(())259	}260}261262impl ExplainingFormat {263	fn print_snippet(264		&self,265		out: &mut dyn std::fmt::Write,266		source: &str,267		origin: &Source,268		start: &CodeLocation,269		end: &CodeLocation,270		desc: &str,271	) -> Result<(), std::fmt::Error> {272		use annotate_snippets::{273			display_list::{DisplayList, FormatOptions},274			snippet::{AnnotationType, Slice, Snippet, SourceAnnotation},275		};276277		let source_fragment: String = source278			.chars()279			.skip(start.line_start_offset)280			.take(end.line_end_offset - end.line_start_offset)281			.collect();282283		let origin = match origin.source_path().path() {284			Some(r) => self.resolver.resolve(r),285			None => origin.source_path().to_string(),286		};287		let snippet = Snippet {288			opt: FormatOptions {289				color: true,290				..FormatOptions::default()291			},292			title: None,293			footer: vec![],294			slices: vec![Slice {295				source: &source_fragment,296				line_start: start.line,297				origin: Some(&origin),298				fold: false,299				annotations: vec![SourceAnnotation {300					label: desc,301					annotation_type: AnnotationType::Error,302					range: (303						start.offset - start.line_start_offset,304						(end.offset - start.line_start_offset).min(source_fragment.len()),305					),306				}],307			}],308		};309310		let dl = DisplayList::from(snippet);311		write!(out, "{}", dl)?;312313		Ok(())314	}315}
after · crates/jrsonnet-evaluator/src/trace/mod.rs
1use std::path::{Path, PathBuf};23use jrsonnet_parser::{CodeLocation, Source};45use crate::{error::Error, LocError, State};67/// The way paths should be displayed8#[derive(Clone)]9pub enum PathResolver {10	/// Only filename11	FileName,12	/// Absolute path13	Absolute,14	/// Path relative to base directory15	Relative(PathBuf),16}1718impl PathResolver {19	/// Will return `Self::Relative(cwd)`, or `Self::Absolute` on cwd failure20	pub fn new_cwd_fallback() -> Self {21		std::env::current_dir().map_or(Self::Absolute, Self::Relative)22	}23	pub fn resolve(&self, from: &Path) -> String {24		match self {25			Self::FileName => from26				.file_name()27				.expect("file name exists")28				.to_string_lossy()29				.into_owned(),30			Self::Absolute => from.to_string_lossy().into_owned(),31			Self::Relative(base) => {32				if from.is_relative() {33					return from.to_string_lossy().into_owned();34				}35				pathdiff::diff_paths(from, base)36					.expect("base is absolute")37					.to_string_lossy()38					.into_owned()39			}40		}41	}42}4344/// Implements pretty-printing of traces45#[allow(clippy::module_name_repetitions)]46pub trait TraceFormat {47	fn write_trace(48		&self,49		out: &mut dyn std::fmt::Write,50		s: &State,51		error: &LocError,52	) -> Result<(), std::fmt::Error>;53}5455fn print_code_location(56	out: &mut impl std::fmt::Write,57	start: &CodeLocation,58	end: &CodeLocation,59) -> Result<(), std::fmt::Error> {60	if start.line == end.line {61		if start.column == end.column {62			write!(out, "{}:{}", start.line, end.column.saturating_sub(1))?;63		} else {64			write!(out, "{}:{}-{}", start.line, start.column - 1, end.column)?;65		}66	} else {67		write!(68			out,69			"{}:{}-{}:{}",70			start.line,71			end.column.saturating_sub(1),72			start.line,73			end.column74		)?;75	}76	Ok(())77}7879/// vanilla-like jsonnet formatting80pub struct CompactFormat {81	pub resolver: PathResolver,82	pub padding: usize,83}8485impl TraceFormat for CompactFormat {86	fn write_trace(87		&self,88		out: &mut dyn std::fmt::Write,89		_s: &State,90		error: &LocError,91	) -> Result<(), std::fmt::Error> {92		write!(out, "{}", error.error())?;93		if let Error::ImportSyntaxError { path, error } = error.error() {94			use std::fmt::Write;9596			writeln!(out)?;97			let mut n = path.source_path().path().map_or_else(98				|| path.source_path().to_string(),99				|r| self.resolver.resolve(r),100			);101			let mut offset = error.location.offset;102			let is_eof = if offset >= path.code().len() {103				offset = path.code().len().saturating_sub(1);104				true105			} else {106				false107			};108			let mut location = path109				.map_source_locations(&[offset as u32])110				.into_iter()111				.next()112				.unwrap();113			if is_eof {114				location.column += 1;115			}116117			write!(n, ":").unwrap();118			print_code_location(&mut n, &location, &location).unwrap();119			write!(out, "{:<p$}{n}", "", p = self.padding)?;120		}121		let file_names = error122			.trace()123			.0124			.iter()125			.map(|el| &el.location)126			.map(|location| {127				use std::fmt::Write;128				#[allow(clippy::option_if_let_else)]129				if let Some(location) = location {130					let mut resolved_path = match location.0.source_path().path() {131						Some(r) => self.resolver.resolve(r),132						None => location.0.source_path().to_string(),133					};134					// TODO: Process all trace elements first135					let location = location.0.map_source_locations(&[location.1, location.2]);136					write!(resolved_path, ":").unwrap();137					print_code_location(&mut resolved_path, &location[0], &location[1]).unwrap();138					write!(resolved_path, ":").unwrap();139					Some(resolved_path)140				} else {141					None142				}143			})144			.collect::<Vec<_>>();145		let align = file_names146			.iter()147			.flatten()148			.map(String::len)149			.max()150			.unwrap_or(0);151		for (el, file) in error.trace().0.iter().zip(file_names) {152			writeln!(out)?;153			if let Some(file) = file {154				write!(155					out,156					"{:<p$}{:<w$} {}",157					"",158					file,159					el.desc,160					p = self.padding,161					w = align162				)?;163			} else {164				write!(out, "{:<p$}{}", "", el.desc, p = self.padding,)?;165			}166		}167		Ok(())168	}169}170171pub struct JsFormat;172impl TraceFormat for JsFormat {173	fn write_trace(174		&self,175		out: &mut dyn std::fmt::Write,176		_s: &State,177		error: &LocError,178	) -> Result<(), std::fmt::Error> {179		write!(out, "{}", error.error())?;180		for item in &error.trace().0 {181			writeln!(out)?;182			let desc = &item.desc;183			if let Some(source) = &item.location {184				let start_end = source.0.map_source_locations(&[source.1, source.2]);185				let resolved_path = source.0.source_path().path().map_or_else(186					|| source.0.source_path().to_string(),187					|r| r.display().to_string(),188				);189190				write!(191					out,192					"    at {} ({}:{}:{})",193					desc, resolved_path, start_end[0].line, start_end[0].column,194				)?;195			} else {196				write!(out, "    during {desc}")?;197			}198		}199		Ok(())200	}201}202203/// rustc-like trace displaying204#[cfg(feature = "explaining-traces")]205pub struct ExplainingFormat {206	pub resolver: PathResolver,207}208#[cfg(feature = "explaining-traces")]209impl TraceFormat for ExplainingFormat {210	fn write_trace(211		&self,212		out: &mut dyn std::fmt::Write,213		_s: &State,214		error: &LocError,215	) -> Result<(), std::fmt::Error> {216		write!(out, "{}", error.error())?;217		if let Error::ImportSyntaxError { path, error } = error.error() {218			writeln!(out)?;219			let offset = error.location.offset;220			let location = path221				.map_source_locations(&[offset as u32])222				.into_iter()223				.next()224				.unwrap();225			let mut end_location = location.clone();226			end_location.offset += 1;227228			self.print_snippet(229				out,230				path.code(),231				path,232				&location,233				&end_location,234				"syntax error",235			)?;236		}237		let trace = &error.trace();238		for item in &trace.0 {239			writeln!(out)?;240			let desc = &item.desc;241			if let Some(source) = &item.location {242				let start_end = source.0.map_source_locations(&[source.1, source.2]);243				self.print_snippet(244					out,245					source.0.code(),246					&source.0,247					&start_end[0],248					&start_end[1],249					desc,250				)?;251			} else {252				write!(out, "{desc}")?;253			}254		}255		Ok(())256	}257}258259impl ExplainingFormat {260	fn print_snippet(261		&self,262		out: &mut dyn std::fmt::Write,263		source: &str,264		origin: &Source,265		start: &CodeLocation,266		end: &CodeLocation,267		desc: &str,268	) -> Result<(), std::fmt::Error> {269		use annotate_snippets::{270			display_list::{DisplayList, FormatOptions},271			snippet::{AnnotationType, Slice, Snippet, SourceAnnotation},272		};273274		let source_fragment: String = source275			.chars()276			.skip(start.line_start_offset)277			.take(end.line_end_offset - end.line_start_offset)278			.collect();279280		let origin = origin.source_path().path().map_or_else(281			|| origin.source_path().to_string(),282			|r| self.resolver.resolve(r),283		);284		let snippet = Snippet {285			opt: FormatOptions {286				color: true,287				..FormatOptions::default()288			},289			title: None,290			footer: vec![],291			slices: vec![Slice {292				source: &source_fragment,293				line_start: start.line,294				origin: Some(&origin),295				fold: false,296				annotations: vec![SourceAnnotation {297					label: desc,298					annotation_type: AnnotationType::Error,299					range: (300						start.offset - start.line_start_offset,301						(end.offset - start.line_start_offset).min(source_fragment.len()),302					),303				}],304			}],305		};306307		let dl = DisplayList::from(snippet);308		write!(out, "{dl}")?;309310		Ok(())311	}312}
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(