git.delta.rocks / jrsonnet / refs/commits / 4e0dbf427e61

difftreelog

style update rustfmt

Yaroslav Bolyukin2023-07-26parent: #f883d5e.patch.diff
in: master

9 files changed

modifiedcmds/jrsonnet/src/main.rsdiffbeforeafterboth
--- a/cmds/jrsonnet/src/main.rs
+++ b/cmds/jrsonnet/src/main.rs
@@ -208,7 +208,10 @@
 			create_dir_all(dir)?;
 		}
 		let Val::Obj(obj) = val else {
-			throw!("value should be object for --multi manifest, got {}", val.value_type())
+			throw!(
+				"value should be object for --multi manifest, got {}",
+				val.value_type()
+			)
 		};
 		for (field, data) in obj.iter(
 			#[cfg(feature = "exp-preserve-order")]
modifiedcrates/jrsonnet-evaluator/src/arr/spec.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/arr/spec.rs
+++ b/crates/jrsonnet-evaluator/src/arr/spec.rs
@@ -178,7 +178,9 @@
 			ArrayThunk::Waiting(..) => {}
 		};
 
-		let ArrayThunk::Waiting(expr) = replace(&mut self.0.cached.borrow_mut()[index], ArrayThunk::Pending) else {
+		let ArrayThunk::Waiting(expr) =
+			replace(&mut self.0.cached.borrow_mut()[index], ArrayThunk::Pending)
+		else {
 			unreachable!()
 		};
 
@@ -489,7 +491,9 @@
 			ArrayThunk::Waiting(..) => {}
 		};
 
-		let ArrayThunk::Waiting(_) = replace(&mut self.0.cached.borrow_mut()[index], ArrayThunk::Pending) else {
+		let ArrayThunk::Waiting(_) =
+			replace(&mut self.0.cached.borrow_mut()[index], ArrayThunk::Pending)
+		else {
 			unreachable!()
 		};
 
modifiedcrates/jrsonnet-evaluator/src/manifest.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/manifest.rs
+++ b/crates/jrsonnet-evaluator/src/manifest.rs
@@ -276,7 +276,10 @@
 impl ManifestFormat for StringFormat {
 	fn manifest_buf(&self, val: Val, out: &mut String) -> Result<()> {
 		let Val::Str(s) = val else {
-			throw!("output should be string for string manifest format, got {}", val.value_type())
+			throw!(
+				"output should be string for string manifest format, got {}",
+				val.value_type()
+			)
 		};
 		write!(out, "{s}").unwrap();
 		Ok(())
@@ -290,7 +293,10 @@
 impl<I: ManifestFormat> ManifestFormat for YamlStreamFormat<I> {
 	fn manifest_buf(&self, val: Val, out: &mut String) -> Result<()> {
 		let Val::Arr(arr) = val else {
-			throw!("output should be array for yaml stream format, got {}", val.value_type())
+			throw!(
+				"output should be array for yaml stream format, got {}",
+				val.value_type()
+			)
 		};
 		if !arr.is_empty() {
 			for v in arr.iter() {
modifiedcrates/jrsonnet-evaluator/src/val.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/val.rs
+++ b/crates/jrsonnet-evaluator/src/val.rs
@@ -72,7 +72,8 @@
 			ThunkInner::Pending => return Err(InfiniteRecursionDetected.into()),
 			ThunkInner::Waiting(..) => (),
 		};
-		let ThunkInner::Waiting(value) = replace(&mut *self.0.borrow_mut(), ThunkInner::Pending) else {
+		let ThunkInner::Waiting(value) = replace(&mut *self.0.borrow_mut(), ThunkInner::Pending)
+		else {
 			unreachable!();
 		};
 		let new_value = match value.0.get() {
modifiedcrates/jrsonnet-macros/src/lib.rsdiffbeforeafterboth
--- a/crates/jrsonnet-macros/src/lib.rs
+++ b/crates/jrsonnet-macros/src/lib.rs
@@ -51,7 +51,7 @@
 
 fn extract_type_from_option(ty: &Type) -> Result<Option<&Type>> {
 	let Some(args) = type_is_path(ty, "Option") else {
-		return Ok(None)
+		return Ok(None);
 	};
 	// It should have only on angle-bracketed param ("<String>"):
 	let PathArguments::AngleBracketed(params) = args else {
@@ -63,7 +63,7 @@
 		return Err(Error::new(
 			generic_arg.span(),
 			"option generic should be a type",
-		))
+		));
 	};
 	Ok(Some(ty))
 }
@@ -210,7 +210,7 @@
 		return Err(Error::new(
 			fun.sig.span(),
 			"builtin should return something",
-		))
+		));
 	};
 
 	let name = fun.sig.ident.to_string();
modifiedcrates/jrsonnet-parser/src/lib.rsdiffbeforeafterboth
--- a/crates/jrsonnet-parser/src/lib.rs
+++ b/crates/jrsonnet-parser/src/lib.rs
@@ -630,7 +630,7 @@
 					el!(
 						Apply(
 							el!(
-								Index{
+								Index {
 									indexable: el!(Var("std".into()), 1, 4),
 									index: el!(Str("deepJoin".into()), 5, 13),
 									#[cfg(feature = "exp-null-coaelse")]
modifiedcrates/jrsonnet-parser/src/source.rsdiffbeforeafterboth
before · crates/jrsonnet-parser/src/source.rs
1use std::{2	any::Any,3	fmt::{self, Debug, Display},4	hash::{Hash, Hasher},5	path::{Path, PathBuf},6	rc::Rc,7};89use jrsonnet_gcmodule::{Trace, Tracer};10use jrsonnet_interner::IStr;11#[cfg(feature = "serde")]12use serde::{Deserialize, Serialize};13#[cfg(feature = "structdump")]14use structdump::Codegen;1516use crate::location::{location_to_offset, offset_to_location, CodeLocation};1718macro_rules! any_ext_methods {19	($T:ident) => {20		fn as_any(&self) -> &dyn Any;21		fn dyn_hash(&self, hasher: &mut dyn Hasher);22		fn dyn_eq(&self, other: &dyn $T) -> bool;23		fn dyn_debug(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result;24	};25}26macro_rules! any_ext_impl {27	($T:ident) => {28		fn as_any(&self) -> &dyn Any {29			self30		}31		fn dyn_hash(&self, mut hasher: &mut dyn Hasher) {32			self.hash(&mut hasher)33		}34		fn dyn_eq(&self, other: &dyn $T) -> bool {35			let Some(other) = other.as_any().downcast_ref::<Self>() else {36				return false37			};38			let this = <Self as $T>::as_any(self)39				.downcast_ref::<Self>()40				.expect("restricted by impl");41			this == other42		}43		fn dyn_debug(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {44			<Self as std::fmt::Debug>::fmt(self, fmt)45		}46	};47}48macro_rules! any_ext {49	($T:ident) => {50		impl Hash for dyn $T {51			fn hash<H: Hasher>(&self, state: &mut H) {52				self.dyn_hash(state)53			}54		}55		impl PartialEq for dyn $T {56			fn eq(&self, other: &Self) -> bool {57				self.dyn_eq(other)58			}59		}60		impl Eq for dyn $T {}61	};62}63pub trait SourcePathT: Trace + Debug + Display {64	/// This method should be checked by resolver before panicking with bad SourcePath input65	/// if `true` - then resolver may threat this path as default, and default is usally a CWD66	fn is_default(&self) -> bool;67	fn path(&self) -> Option<&Path>;68	any_ext_methods!(SourcePathT);69}70any_ext!(SourcePathT);7172/// Represents location of a file73///74/// Standard CLI only operates using75/// - [`SourceFile`] - for any file76/// - [`SourceDirectory`] - for resolution from CWD77/// - [`SourceVirtual`] - for stdlib/ext-str78///79/// From all of those, only [`SourceVirtual`] may be constructed manually, any other path kind should be only obtained80/// from assigned `ImportResolver`81/// However, you should always check `is_default` method return, as it will return true for any paths, where default82/// search location is applicable83///84/// Resolver may also return custom implementations of this trait, for example it may return http url in case of remotely loaded files85#[derive(Eq, Debug, Clone)]86pub struct SourcePath(Rc<dyn SourcePathT>);87impl SourcePath {88	pub fn new(inner: impl SourcePathT) -> Self {89		Self(Rc::new(inner))90	}91	pub fn downcast_ref<T: SourcePathT>(&self) -> Option<&T> {92		self.0.as_any().downcast_ref()93	}94	pub fn is_default(&self) -> bool {95		self.0.is_default()96	}97	pub fn path(&self) -> Option<&Path> {98		self.0.path()99	}100}101impl Hash for SourcePath {102	fn hash<H: Hasher>(&self, state: &mut H) {103		self.0.hash(state);104	}105}106impl PartialEq for SourcePath {107	#[allow(clippy::op_ref)]108	fn eq(&self, other: &Self) -> bool {109		&*self.0 == &*other.0110	}111}112impl Trace for SourcePath {113	fn trace(&self, tracer: &mut Tracer) {114		(*self.0).trace(tracer)115	}116117	fn is_type_tracked() -> bool118	where119		Self: Sized,120	{121		true122	}123}124impl Display for SourcePath {125	fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {126		write!(f, "{}", self.0)127	}128}129impl Default for SourcePath {130	fn default() -> Self {131		Self(Rc::new(SourceDefault))132	}133}134135#[cfg(feature = "structdump")]136impl Codegen for SourcePath {137	fn gen_code(138		&self,139		res: &mut structdump::CodegenResult,140		unique: bool,141	) -> structdump::TokenStream {142		let source_virtual = self143			.0144			.as_any()145			.downcast_ref::<SourceVirtual>()146			.expect("can only codegen for virtual source paths!")147			.0148			.clone();149		let val = res.add_value(source_virtual, false);150		res.add_code(151			structdump::quote! {152				structdump_import::SourcePath::new(structdump_import::SourceVirtual(#val))153			},154			Some(structdump::quote!(SourcePath)),155			unique,156		)157	}158}159160#[derive(Trace, Hash, PartialEq, Eq, Debug)]161struct SourceDefault;162impl Display for SourceDefault {163	fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {164		write!(f, "<default>")165	}166}167impl SourcePathT for SourceDefault {168	fn is_default(&self) -> bool {169		true170	}171	fn path(&self) -> Option<&Path> {172		None173	}174	any_ext_impl!(SourcePathT);175}176177/// Represents path to the file on the disk178/// Directories shouldn't be put here, as resolution for files differs from resolution for directories:179///180/// When `file` is being resolved from `SourceFile(a/b/c)`, it should be resolved to `SourceFile(a/b/file)`,181/// however if it is being resolved from `SourceDirectory(a/b/c)`, then it should be resolved to `SourceDirectory(a/b/c/file)`182#[derive(Trace, Hash, PartialEq, Eq, Debug)]183pub struct SourceFile(PathBuf);184impl SourceFile {185	pub fn new(path: PathBuf) -> Self {186		Self(path)187	}188	pub fn path(&self) -> &Path {189		&self.0190	}191}192impl Display for SourceFile {193	fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {194		write!(f, "{}", self.0.display())195	}196}197impl SourcePathT for SourceFile {198	fn is_default(&self) -> bool {199		false200	}201	fn path(&self) -> Option<&Path> {202		Some(&self.0)203	}204	any_ext_impl!(SourcePathT);205}206207/// Represents path to the directory on the disk208///209/// See also [`SourceFile`]210#[derive(Trace, Hash, PartialEq, Eq, Debug)]211pub struct SourceDirectory(PathBuf);212impl SourceDirectory {213	pub fn new(path: PathBuf) -> Self {214		Self(path)215	}216	pub fn path(&self) -> &Path {217		&self.0218	}219}220impl Display for SourceDirectory {221	fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {222		write!(f, "{}", self.0.display())223	}224}225impl SourcePathT for SourceDirectory {226	fn is_default(&self) -> bool {227		false228	}229	fn path(&self) -> Option<&Path> {230		Some(&self.0)231	}232	any_ext_impl!(SourcePathT);233}234235/// Represents virtual file, whose are located in memory, and shouldn't be cached236///237/// It is used for --ext-code=.../--tla-code=.../standard library source code by default,238/// and user can construct arbitrary values by hand, without asking import resolver239#[cfg_attr(feature = "structdump", derive(Codegen))]240#[derive(Trace, Hash, PartialEq, Eq, Debug, Clone)]241pub struct SourceVirtual(pub IStr);242impl Display for SourceVirtual {243	fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {244		write!(f, "{}", self.0)245	}246}247impl SourcePathT for SourceVirtual {248	fn is_default(&self) -> bool {249		true250	}251	fn path(&self) -> Option<&Path> {252		None253	}254	any_ext_impl!(SourcePathT);255}256257/// Either real file, or virtual258/// Hash of FileName always have same value as raw Path, to make it possible to use with raw_entry_mut259#[cfg_attr(feature = "structdump", derive(Codegen))]260#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]261#[derive(Clone, PartialEq, Eq, Debug)]262pub struct Source(pub Rc<(SourcePath, IStr)>);263264impl Trace for Source {265	fn trace(&self, _tracer: &mut Tracer) {}266267	fn is_type_tracked() -> bool {268		false269	}270}271272impl Source {273	pub fn new(path: SourcePath, code: IStr) -> Self {274		Self(Rc::new((path, code)))275	}276277	pub fn new_virtual(name: IStr, code: IStr) -> Self {278		Self::new(SourcePath::new(SourceVirtual(name)), code)279	}280281	pub fn code(&self) -> &str {282		&self.0 .1283	}284285	pub fn source_path(&self) -> &SourcePath {286		&self.0 .0287	}288289	pub fn map_source_locations<const S: usize>(&self, locs: &[u32; S]) -> [CodeLocation; S] {290		offset_to_location(&self.0 .1, locs)291	}292	pub fn map_from_source_location(&self, line: usize, column: usize) -> Option<usize> {293		location_to_offset(&self.0 .1, line, column)294	}295}
modifiedflake.lockdiffbeforeafterboth
--- a/flake.lock
+++ b/flake.lock
@@ -20,11 +20,11 @@
     },
     "nixpkgs": {
       "locked": {
-        "lastModified": 1689162265,
-        "narHash": "sha256-kdW79sfwX2TTX8yFBNUsEYOG+gQuAOHU+WcUtxMUnlc=",
+        "lastModified": 1690394427,
+        "narHash": "sha256-ZT1ABAZVdJycCJMUHu533dvcMuxqUGDnp6N2zLcFrv4=",
         "owner": "nixos",
         "repo": "nixpkgs",
-        "rev": "1941c7d8f1219c615a1d6dae826e0d6fab89acca",
+        "rev": "78df3591ec67310b8cc4b753e1496999da2678cf",
         "type": "github"
       },
       "original": {
@@ -50,11 +50,11 @@
         ]
       },
       "locked": {
-        "lastModified": 1689129196,
-        "narHash": "sha256-/z/Al4sFcIh5oPQWA9MclQmJR9g3RO8UDiHGaj/T9R8=",
+        "lastModified": 1690338181,
+        "narHash": "sha256-Sz2oQ9aNS3MVncnCMndr0302G26UrFUfPynoH2iLjsg=",
         "owner": "oxalica",
         "repo": "rust-overlay",
-        "rev": "db8d909c9526d4406579ee7343bf2d7de3d15eac",
+        "rev": "b7f0b7b58b3c6f14a1377ec31a3d78b23ab843ec",
         "type": "github"
       },
       "original": {
modifiedflake.nixdiffbeforeafterboth
--- a/flake.nix
+++ b/flake.nix
@@ -16,7 +16,7 @@
           inherit system;
           overlays = [ rust-overlay.overlays.default ];
         };
-        rust = ((pkgs.rustChannelOf { date = "2023-06-26"; channel = "nightly"; }).default.override {
+        rust = ((pkgs.rustChannelOf { date = "2023-07-23"; channel = "nightly"; }).default.override {
           extensions = [ "rust-src" "miri" "rust-analyzer" ];
         });
       in