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

difftreelog

style fix clippy warnings

Yaroslav Bolyukin2023-01-20parent: #974f2c1.patch.diff
in: master

16 files changed

modifiedcmds/jrsonnet/src/main.rsdiffbeforeafterboth
--- a/cmds/jrsonnet/src/main.rs
+++ b/cmds/jrsonnet/src/main.rs
@@ -5,7 +5,7 @@
 
 use clap::{CommandFactory, Parser};
 use clap_complete::Shell;
-use jrsonnet_cli::{ManifestOpts, OutputOpts, TraceOpts, MiscOpts, TlaOpts, StdOpts, GcOpts};
+use jrsonnet_cli::{GcOpts, ManifestOpts, MiscOpts, OutputOpts, StdOpts, TlaOpts, TraceOpts};
 use jrsonnet_evaluator::{
 	apply_tla,
 	error::{Error as JrError, ErrorKind},
@@ -133,16 +133,14 @@
 
 fn main_catch(opts: Opts) -> bool {
 	let s = State::default();
-	let trace = opts
-		.trace
-		.trace_format();
+	let trace = opts.trace.trace_format();
 	if let Err(e) = main_real(&s, opts) {
 		if let Error::Evaluation(e) = e {
 			let mut out = String::new();
 			trace.write_trace(&mut out, &e).expect("format error");
 			eprintln!("{out}")
 		} else {
-			eprintln!("{}", e);
+			eprintln!("{e}");
 		}
 		return false;
 	}
@@ -150,7 +148,7 @@
 }
 
 fn main_real(s: &State, opts: Opts) -> Result<(), Error> {
-	let _gc_leak_guard= opts.gc.leak_on_exit();
+	let _gc_leak_guard = opts.gc.leak_on_exit();
 	let _gc_print_stats = opts.gc.stats_printer();
 	let _stack_depth_override = opts.misc.stack_size_override();
 
@@ -220,7 +218,7 @@
 	} else {
 		let output = val.manifest(manifest_format)?;
 		if !output.is_empty() {
-			println!("{}", output);
+			println!("{output}");
 		}
 	}
 
modifiedcrates/jrsonnet-cli/src/lib.rsdiffbeforeafterboth
--- a/crates/jrsonnet-cli/src/lib.rs
+++ b/crates/jrsonnet-cli/src/lib.rs
@@ -6,7 +6,10 @@
 use std::{env, marker::PhantomData, path::PathBuf};
 
 use clap::Parser;
-use jrsonnet_evaluator::{error::Result, stack::{set_stack_depth_limit, StackDepthLimitOverrideGuard, limit_stack_depth}, FileImportResolver, State, ImportResolver};
+use jrsonnet_evaluator::{
+	stack::{limit_stack_depth, StackDepthLimitOverrideGuard},
+	FileImportResolver,
+};
 use jrsonnet_gcmodule::with_thread_object_space;
 pub use manifest::*;
 pub use stdlib::*;
@@ -71,6 +74,7 @@
 }
 impl GcOpts {
 	pub fn stats_printer(&self) -> Option<GcStatsPrinter> {
+		#[allow(clippy::unnecessary_lazy_evaluations/*, reason = "GcStatsPrinter has side-effect on Drop"*/)]
 		self.gc_print_stats.then(|| GcStatsPrinter {
 			collect_before_printing_stats: self.gc_collect_before_printing_stats,
 		})
@@ -96,7 +100,7 @@
 		eprintln!("=== GC STATS ===");
 		if self.collect_before_printing_stats {
 			let collected = jrsonnet_gcmodule::collect_thread_cycles();
-			eprintln!("Collected: {}", collected);
+			eprintln!("Collected: {collected}");
 		}
 		eprintln!("Tracked: {}", jrsonnet_gcmodule::count_thread_tracked())
 	}
modifiedcrates/jrsonnet-cli/src/manifest.rsdiffbeforeafterboth
--- a/crates/jrsonnet-cli/src/manifest.rs
+++ b/crates/jrsonnet-cli/src/manifest.rs
@@ -1,10 +1,8 @@
 use std::path::PathBuf;
 
 use clap::{Parser, ValueEnum};
-use jrsonnet_evaluator::{
-	error::Result,
-	manifest::{JsonFormat, ManifestFormat, StringFormat, ToStringFormat, YamlStreamFormat},
-	State,
+use jrsonnet_evaluator::manifest::{
+	JsonFormat, ManifestFormat, StringFormat, ToStringFormat, YamlStreamFormat,
 };
 use jrsonnet_stdlib::{TomlFormat, YamlFormat};
 
modifiedcrates/jrsonnet-cli/src/stdlib.rsdiffbeforeafterboth
--- a/crates/jrsonnet-cli/src/stdlib.rs
+++ b/crates/jrsonnet-cli/src/stdlib.rs
@@ -1,7 +1,7 @@
 use std::{fs::read_to_string, str::FromStr};
 
 use clap::Parser;
-use jrsonnet_evaluator::{error::Result, tb, trace::PathResolver, State};
+use jrsonnet_evaluator::{error::Result, trace::PathResolver, State};
 use jrsonnet_stdlib::ContextInitializer;
 
 #[derive(Clone)]
@@ -49,7 +49,7 @@
 				name: out[0].into(),
 				value: content,
 			}),
-			Err(e) => Err(format!("{}", e)),
+			Err(e) => Err(format!("{e}")),
 		}
 	}
 }
@@ -86,8 +86,7 @@
 		if self.no_stdlib {
 			return Ok(None);
 		}
-		let ctx =
-			ContextInitializer::new(s.clone(), PathResolver::new_cwd_fallback());
+		let ctx = ContextInitializer::new(s.clone(), PathResolver::new_cwd_fallback());
 		for ext in self.ext_str.iter() {
 			ctx.add_ext_str((&ext.name as &str).into(), (&ext.value as &str).into());
 		}
modifiedcrates/jrsonnet-cli/src/tla.rsdiffbeforeafterboth
--- a/crates/jrsonnet-cli/src/tla.rs
+++ b/crates/jrsonnet-cli/src/tla.rs
@@ -3,7 +3,7 @@
 	error::{ErrorKind, Result},
 	function::TlaArg,
 	gc::GcHashMap,
-	IStr, State,
+	IStr,
 };
 use jrsonnet_parser::{ParserSettings, Source};
 
modifiedcrates/jrsonnet-cli/src/trace.rsdiffbeforeafterboth
--- a/crates/jrsonnet-cli/src/trace.rs
+++ b/crates/jrsonnet-cli/src/trace.rs
@@ -1,9 +1,5 @@
 use clap::{Parser, ValueEnum};
-use jrsonnet_evaluator::{
-	error::Result,
-	trace::{CompactFormat, ExplainingFormat, PathResolver, TraceFormat},
-	State,
-};
+use jrsonnet_evaluator::trace::{CompactFormat, ExplainingFormat, PathResolver, TraceFormat};
 
 #[derive(PartialEq, Eq, ValueEnum, Clone)]
 pub enum TraceFormatName {
modifiedcrates/jrsonnet-evaluator/src/error.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/error.rs
+++ b/crates/jrsonnet-evaluator/src/error.rs
@@ -274,6 +274,7 @@
 		f.debug_tuple("LocError").field(&self.0).finish()
 	}
 }
+impl std::error::Error for Error {}
 
 pub trait ErrorSource {
 	fn to_location(self) -> Option<ExprLocation>;
modifiedcrates/jrsonnet-evaluator/src/evaluate/operator.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/evaluate/operator.rs
+++ b/crates/jrsonnet-evaluator/src/evaluate/operator.rs
@@ -104,28 +104,15 @@
 					}
 				}
 			} else {
-				{
-					let ai = a.iter();
-					let bi = b.iter();
+				let ai = a.iter();
+				let bi = b.iter();
 
-					for (a, b) in ai.zip(bi) {
-						let ord = evaluate_compare_op(&a?, &b?, op)?;
-						if !ord.is_eq() {
-							return Ok(ord);
-						}
+				for (a, b) in ai.zip(bi) {
+					let ord = evaluate_compare_op(&a?, &b?, op)?;
+					if !ord.is_eq() {
+						return Ok(ord);
 					}
 				}
-				// {
-				// 	let ai = a.iter_expl();
-				// 	let bi = b.iter_expl();
-
-				// 	for (a, b) in ai.zip(bi) {
-				// 		let ord = evaluate_compare_op(&a?, &b?, op)?;
-				// 		if !ord.is_eq() {
-				// 			return Ok(ord);
-				// 		}
-				// 	}
-				// }
 			}
 			a.len().cmp(&b.len())
 		}
modifiedcrates/jrsonnet-evaluator/src/lib.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/lib.rs
+++ b/crates/jrsonnet-evaluator/src/lib.rs
@@ -36,6 +36,7 @@
 	clippy::use_self,
 	// https://github.com/rust-lang/rust-clippy/issues/8539
 	clippy::iter_with_drain,
+	clippy::type_repetition_in_bounds,
 	// ci is being run with nightly, but library should work on stable
 	clippy::missing_const_for_fn,
 )]
modifiedcrates/jrsonnet-evaluator/src/obj.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/obj.rs
+++ b/crates/jrsonnet-evaluator/src/obj.rs
@@ -54,7 +54,7 @@
 
 #[cfg(feature = "exp-preserve-order")]
 mod ordering {
-	use std::cmp::Reverse;
+	use std::cmp::{Ordering, Reverse};
 
 	use jrsonnet_gcmodule::Trace;
 
@@ -81,12 +81,10 @@
 			Self(Reverse(depth), index)
 		}
 		pub fn collide(self, other: Self) -> Self {
-			if self.0 .0 > other.0 .0 {
-				self
-			} else if self.0 .0 < other.0 .0 {
-				other
-			} else {
-				unreachable!("object can't have two fields with same name")
+			match self.0 .0.cmp(&other.0 .0) {
+				Ordering::Greater => self,
+				Ordering::Less => other,
+				Ordering::Equal => unreachable!("object can't have two fields with the same name"),
 			}
 		}
 	}
@@ -188,6 +186,12 @@
 	pub fn new_empty() -> Self {
 		Self::new(None, Cc::new(GcHashMap::new()), Cc::new(Vec::new()))
 	}
+	pub fn builder() -> ObjValueBuilder {
+		ObjValueBuilder::new()
+	}
+	pub fn builder_with_capacity(capacity: usize) -> ObjValueBuilder {
+		ObjValueBuilder::with_capacity(capacity)
+	}
 	#[must_use]
 	pub fn extend_from(&self, sup: Self) -> Self {
 		match &self.0.sup {
@@ -304,7 +308,7 @@
 						break;
 					}
 					fields[j] = fields[k].clone();
-					j = k
+					j = k;
 				}
 				fields[j] = x;
 			}
modifiedcrates/jrsonnet-evaluator/src/val.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/val.rs
+++ b/crates/jrsonnet-evaluator/src/val.rs
@@ -33,6 +33,7 @@
 	Pending,
 }
 
+/// Lazily evaluated value
 #[allow(clippy::module_name_repetitions)]
 #[derive(Clone, Trace)]
 pub struct Thunk<T: Trace>(Cc<RefCell<ThunkInner<T>>>);
@@ -57,6 +58,13 @@
 		self.evaluate()?;
 		Ok(())
 	}
+
+	/// Evaluate thunk, or return cached value
+	///
+	/// # Errors
+	///
+	/// - Lazy value evaluation returned error
+	/// - This method was called during inner value evaluation
 	pub fn evaluate(&self) -> Result<T> {
 		match &*self.0.borrow() {
 			ThunkInner::Computed(v) => return Ok(v.clone()),
@@ -132,7 +140,7 @@
 	}
 }
 
-/// Represents a Jsonnet value, which can be spliced or indexed (string or array).
+/// Represents a Jsonnet value, which can be sliced or indexed (string or array).
 #[allow(clippy::module_name_repetitions)]
 pub enum IndexableVal {
 	/// String.
@@ -247,6 +255,16 @@
 		}
 	}
 }
+impl From<&str> for StrValue {
+	fn from(value: &str) -> Self {
+		Self::Flat(value.into())
+	}
+}
+impl From<String> for StrValue {
+	fn from(value: String) -> Self {
+		Self::Flat(value.into())
+	}
+}
 impl Display for StrValue {
 	fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
 		match self {
modifiedcrates/jrsonnet-parser/src/source.rsdiffbeforeafterboth
--- a/crates/jrsonnet-parser/src/source.rs
+++ b/crates/jrsonnet-parser/src/source.rs
@@ -33,8 +33,8 @@
 		}
 		fn dyn_eq(&self, other: &dyn $T) -> bool {
 			let Some(other) = other.as_any().downcast_ref::<Self>() else {
-												return false
-											};
+				return false
+			};
 			let this = <Self as $T>::as_any(self)
 				.downcast_ref::<Self>()
 				.expect("restricted by impl");
modifiedcrates/jrsonnet-stdlib/src/lib.rsdiffbeforeafterboth
before · crates/jrsonnet-stdlib/src/lib.rs
1use std::{2	cell::{Ref, RefCell, RefMut},3	collections::HashMap,4	rc::Rc,5};67use jrsonnet_evaluator::{8	error::{ErrorKind::*, Result},9	function::{builtin::Builtin, CallLocation, FuncVal, TlaArg},10	gc::{GcHashMap, TraceBox},11	tb,12	trace::PathResolver,13	Context, ContextBuilder, IStr, ObjValue, ObjValueBuilder, State, Thunk, Val,14};15use jrsonnet_gcmodule::{Cc, Trace};16use jrsonnet_parser::Source;1718mod expr;19mod types;20pub use types::*;21mod arrays;22pub use arrays::*;23mod math;24pub use math::*;25mod operator;26pub use operator::*;27mod sort;28pub use sort::*;29mod hash;30pub use hash::*;31mod encoding;32pub use encoding::*;33mod objects;34pub use objects::*;35mod manifest;36pub use manifest::*;37mod parse;38pub use parse::*;39mod strings;40pub use strings::*;41mod misc;42pub use misc::*;43mod sets;44pub use sets::*;4546pub fn stdlib_uncached(settings: Rc<RefCell<Settings>>) -> ObjValue {47	let mut builder = ObjValueBuilder::new();4849	let expr = expr::stdlib_expr();50	let eval = jrsonnet_evaluator::evaluate(ContextBuilder::dangerous_empty_state().build(), &expr)51		.expect("stdlib.jsonnet should have no errors")52		.as_obj()53		.expect("stdlib.jsonnet should evaluate to object");5455	builder.with_super(eval);5657	for (name, builtin) in [58		// Types59		("type", builtin_type::INST),60		("isString", builtin_is_string::INST),61		("isNumber", builtin_is_number::INST),62		("isBoolean", builtin_is_boolean::INST),63		("isObject", builtin_is_object::INST),64		("isArray", builtin_is_array::INST),65		("isFunction", builtin_is_function::INST),66		// Arrays67		("makeArray", builtin_make_array::INST),68		("repeat", builtin_repeat::INST),69		("slice", builtin_slice::INST),70		("map", builtin_map::INST),71		("flatMap", builtin_flatmap::INST),72		("filter", builtin_filter::INST),73		("foldl", builtin_foldl::INST),74		("foldr", builtin_foldr::INST),75		("range", builtin_range::INST),76		("join", builtin_join::INST),77		("reverse", builtin_reverse::INST),78		("any", builtin_any::INST),79		("all", builtin_all::INST),80		("member", builtin_member::INST),81		("count", builtin_count::INST),82		// Math83		("abs", builtin_abs::INST),84		("sign", builtin_sign::INST),85		("max", builtin_max::INST),86		("min", builtin_min::INST),87		("modulo", builtin_modulo::INST),88		("floor", builtin_floor::INST),89		("ceil", builtin_ceil::INST),90		("log", builtin_log::INST),91		("pow", builtin_pow::INST),92		("sqrt", builtin_sqrt::INST),93		("sin", builtin_sin::INST),94		("cos", builtin_cos::INST),95		("tan", builtin_tan::INST),96		("asin", builtin_asin::INST),97		("acos", builtin_acos::INST),98		("atan", builtin_atan::INST),99		("exp", builtin_exp::INST),100		("mantissa", builtin_mantissa::INST),101		("exponent", builtin_exponent::INST),102		// Operator103		("mod", builtin_mod::INST),104		("primitiveEquals", builtin_primitive_equals::INST),105		("equals", builtin_equals::INST),106		("format", builtin_format::INST),107		// Sort108		("sort", builtin_sort::INST),109		// Hash110		("md5", builtin_md5::INST),111		#[cfg(feature = "exp-more-hashes")]112		("sha256", builtin_sha256::INST),113		// Encoding114		("encodeUTF8", builtin_encode_utf8::INST),115		("decodeUTF8", builtin_decode_utf8::INST),116		("base64", builtin_base64::INST),117		("base64Decode", builtin_base64_decode::INST),118		("base64DecodeBytes", builtin_base64_decode_bytes::INST),119		// Objects120		("objectFieldsEx", builtin_object_fields_ex::INST),121		("objectHasEx", builtin_object_has_ex::INST),122		// Manifest123		("escapeStringJson", builtin_escape_string_json::INST),124		("manifestJsonEx", builtin_manifest_json_ex::INST),125		("manifestYamlDoc", builtin_manifest_yaml_doc::INST),126		("manifestTomlEx", builtin_manifest_toml_ex::INST),127		// Parsing128		("parseJson", builtin_parse_json::INST),129		("parseYaml", builtin_parse_yaml::INST),130		// Strings131		("codepoint", builtin_codepoint::INST),132		("substr", builtin_substr::INST),133		("char", builtin_char::INST),134		("strReplace", builtin_str_replace::INST),135		("splitLimit", builtin_splitlimit::INST),136		("asciiUpper", builtin_ascii_upper::INST),137		("asciiLower", builtin_ascii_lower::INST),138		("findSubstr", builtin_find_substr::INST),139		("parseInt", builtin_parse_int::INST),140		("parseOctal", builtin_parse_octal::INST),141		("parseHex", builtin_parse_hex::INST),142		// Misc143		("length", builtin_length::INST),144		("startsWith", builtin_starts_with::INST),145		("endsWith", builtin_ends_with::INST),146		// Sets147		("setMember", builtin_set_member::INST),148	]149	.iter()150	.cloned()151	{152		builder153			.member(name.into())154			.hide()155			.value(Val::Func(FuncVal::StaticBuiltin(builtin)))156			.expect("no conflict");157	}158159	builder160		.member("extVar".into())161		.hide()162		.value(Val::Func(FuncVal::builtin(builtin_ext_var {163			settings: settings.clone(),164		})))165		.expect("no conflict");166	builder167		.member("native".into())168		.hide()169		.value(Val::Func(FuncVal::builtin(builtin_native {170			settings: settings.clone(),171		})))172		.expect("no conflict");173	builder174		.member("trace".into())175		.hide()176		.value(Val::Func(FuncVal::builtin(builtin_trace { settings })))177		.expect("no conflict");178179	builder180		.member("id".into())181		.hide()182		.value(Val::Func(FuncVal::Id))183		.expect("no conflict");184185	builder.build()186}187188pub trait TracePrinter {189	fn print_trace(&self, loc: CallLocation, value: IStr);190}191192pub struct StdTracePrinter {193	resolver: PathResolver,194}195impl StdTracePrinter {196	pub fn new(resolver: PathResolver) -> Self {197		Self { resolver }198	}199}200impl TracePrinter for StdTracePrinter {201	fn print_trace(&self, loc: CallLocation, value: IStr) {202		eprint!("TRACE:");203		if let Some(loc) = loc.0 {204			let locs = loc.0.map_source_locations(&[loc.1]);205			eprint!(206				" {}:{}",207				match loc.0.source_path().path() {208					Some(p) => self.resolver.resolve(p),209					None => loc.0.source_path().to_string(),210				},211				locs[0].line212			);213		}214		eprintln!(" {}", value);215	}216}217218pub struct Settings {219	/// Used for `std.extVar`220	pub ext_vars: HashMap<IStr, TlaArg>,221	/// Used for `std.native`222	pub ext_natives: HashMap<IStr, Cc<TraceBox<dyn Builtin>>>,223	/// Helper to add globals without implementing custom ContextInitializer224	pub globals: GcHashMap<IStr, Thunk<Val>>,225	/// Used for `std.trace`226	pub trace_printer: Box<dyn TracePrinter>,227	/// Used for `std.thisFile`228	pub path_resolver: PathResolver,229}230231fn extvar_source(name: &str, code: impl Into<IStr>) -> Source {232	let source_name = format!("<extvar:{}>", name);233	Source::new_virtual(source_name.into(), code.into())234}235236#[derive(Trace)]237pub struct ContextInitializer {238	// When we don't need to support legacy-this-file, we can reuse same context for all files239	#[cfg(not(feature = "legacy-this-file"))]240	context: Context,241	// Otherwise, we can only keep first stdlib layer, and then stack thisFile on top of it242	#[cfg(feature = "legacy-this-file")]243	stdlib_obj: ObjValue,244	settings: Rc<RefCell<Settings>>,245}246impl ContextInitializer {247	pub fn new(s: State, resolver: PathResolver) -> Self {248		let settings = Settings {249			ext_vars: Default::default(),250			ext_natives: Default::default(),251			globals: Default::default(),252			trace_printer: Box::new(StdTracePrinter::new(resolver.clone())),253			path_resolver: resolver,254		};255		let settings = Rc::new(RefCell::new(settings));256		Self {257			#[cfg(not(feature = "legacy-this-file"))]258			context: {259				let mut context = ContextBuilder::with_capacity(s, 1);260				context.bind(261					"std".into(),262					Thunk::evaluated(Val::Obj(stdlib_uncached(settings.clone()))),263				);264				context.build()265			},266			#[cfg(feature = "legacy-this-file")]267			stdlib_obj: stdlib_uncached(settings.clone()),268			settings,269		}270	}271	pub fn settings(&self) -> Ref<Settings> {272		self.settings.borrow()273	}274	pub fn settings_mut(&self) -> RefMut<Settings> {275		self.settings.borrow_mut()276	}277	pub fn add_ext_var(&self, name: IStr, value: Val) {278		self.settings_mut()279			.ext_vars280			.insert(name, TlaArg::Val(value));281	}282	pub fn add_ext_str(&self, name: IStr, value: IStr) {283		self.settings_mut()284			.ext_vars285			.insert(name, TlaArg::String(value));286	}287	pub fn add_ext_code(&self, name: &str, code: impl Into<IStr>) -> Result<()> {288		let code = code.into();289		let source = extvar_source(name, code.clone());290		let parsed = jrsonnet_parser::parse(291			&code,292			&jrsonnet_parser::ParserSettings {293				source: source.clone(),294			},295		)296		.map_err(|e| ImportSyntaxError {297			path: source,298			error: Box::new(e),299		})?;300		// self.data_mut().volatile_files.insert(source_name, code);301		self.settings_mut()302			.ext_vars303			.insert(name.into(), TlaArg::Code(parsed));304		Ok(())305	}306	pub fn add_native(&self, name: IStr, cb: impl Builtin) {307		self.settings_mut()308			.ext_natives309			.insert(name, Cc::new(tb!(cb)));310	}311}312impl jrsonnet_evaluator::ContextInitializer for ContextInitializer {313	#[cfg(not(feature = "legacy-this-file"))]314	fn initialize(&self, _s: State, _source: Source) -> jrsonnet_evaluator::Context {315		let out = self.context.clone();316		let globals = &self.settings().globals;317		if globals.is_empty() {318			return out;319		}320321		let mut out = ContextBuilder::extend(out);322		for (k, v) in globals.iter() {323			out.bind(k.clone(), v.clone());324		}325		out.build()326	}327	#[cfg(feature = "legacy-this-file")]328	fn initialize(&self, s: State, source: Source) -> Context {329		use jrsonnet_evaluator::val::StrValue;330331		let mut builder = ObjValueBuilder::new();332		builder.with_super(self.stdlib_obj.clone());333		builder334			.member("thisFile".into())335			.hide()336			.value(Val::Str(StrValue::Flat(337				match source.source_path().path() {338					Some(p) => self.settings().path_resolver.resolve(p).into(),339					None => source.source_path().to_string().into(),340				},341			)))342			.expect("this object builder is empty");343		let stdlib_with_this_file = builder.build();344345		let mut context = ContextBuilder::with_capacity(s, 1);346		context.bind(347			"std".into(),348			Thunk::evaluated(Val::Obj(stdlib_with_this_file)),349		);350		for (k, v) in self.settings().globals.iter() {351			context.bind(k.clone(), v.clone());352		}353		context.build()354	}355	fn as_any(&self) -> &dyn std::any::Any {356		self357	}358}359360pub trait StateExt {361	/// This method was previously implemented in jrsonnet-evaluator itself362	fn with_stdlib(&self);363	fn add_global(&self, name: IStr, value: Thunk<Val>);364}365366impl StateExt for State {367	fn with_stdlib(&self) {368		let initializer = ContextInitializer::new(self.clone(), PathResolver::new_cwd_fallback());369		self.settings_mut().context_initializer = tb!(initializer)370	}371	fn add_global(&self, name: IStr, value: Thunk<Val>) {372		self.settings()373			.context_initializer374			.as_any()375			.downcast_ref::<ContextInitializer>()376			.expect("not standard context initializer")377			.settings_mut()378			.globals379			.insert(name, value);380	}381}
modifiedcrates/jrsonnet-stdlib/src/misc.rsdiffbeforeafterboth
--- a/crates/jrsonnet-stdlib/src/misc.rs
+++ b/crates/jrsonnet-stdlib/src/misc.rs
@@ -46,7 +46,7 @@
 		.ext_natives
 		.get(&x)
 		.cloned()
-		.map_or(Val::Null, |v| Val::Func(FuncVal::Builtin(v.clone())))
+		.map_or(Val::Null, |v| Val::Func(FuncVal::Builtin(v)))
 }
 
 #[builtin(fields(
modifiedcrates/jrsonnet-stdlib/src/parse.rsdiffbeforeafterboth
--- a/crates/jrsonnet-stdlib/src/parse.rs
+++ b/crates/jrsonnet-stdlib/src/parse.rs
@@ -8,7 +8,7 @@
 #[builtin]
 pub fn builtin_parse_json(str: IStr) -> Result<Val> {
 	let value: Val = serde_json::from_str(&str)
-		.map_err(|e| RuntimeError(format!("failed to parse json: {}", e).into()))?;
+		.map_err(|e| RuntimeError(format!("failed to parse json: {e}").into()))?;
 	Ok(value)
 }
 
@@ -22,7 +22,7 @@
 	let mut out = vec![];
 	for item in value {
 		let val = Val::deserialize(item)
-			.map_err(|e| RuntimeError(format!("failed to parse yaml: {}", e).into()))?;
+			.map_err(|e| RuntimeError(format!("failed to parse yaml: {e}").into()))?;
 		out.push(val);
 	}
 	Ok(if out.is_empty() {
modifiedcrates/jrsonnet-types/src/lib.rsdiffbeforeafterboth
--- a/crates/jrsonnet-types/src/lib.rs
+++ b/crates/jrsonnet-types/src/lib.rs
@@ -150,7 +150,7 @@
 		if should_add_braces {
 			write!(f, "(")?;
 		}
-		write!(f, "{}", v)?;
+		write!(f, "{v}")?;
 		if should_add_braces {
 			write!(f, ")")?;
 		}
@@ -162,7 +162,7 @@
 	if *a == ComplexValType::Any {
 		write!(f, "array")?
 	} else {
-		write!(f, "Array<{}>", a)?
+		write!(f, "Array<{a}>")?
 	}
 	Ok(())
 }
@@ -171,7 +171,7 @@
 	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
 		match self {
 			ComplexValType::Any => write!(f, "any")?,
-			ComplexValType::Simple(s) => write!(f, "{}", s)?,
+			ComplexValType::Simple(s) => write!(f, "{s}")?,
 			ComplexValType::Char => write!(f, "char")?,
 			ComplexValType::BoundedNumber(a, b) => write!(
 				f,
@@ -187,7 +187,7 @@
 					if i != 0 {
 						write!(f, ", ")?;
 					}
-					write!(f, "{}: {}", k, v)?;
+					write!(f, "{k}: {v}")?;
 				}
 				write!(f, "}}")?;
 			}