From a259db16212f4f2f0de7a0fa760c0a3a58e06c5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Garillot?= Date: Sat, 9 Sep 2023 10:17:23 -0400 Subject: [PATCH] fix: inline format arguments (clippy) --- benches/sha256_ivc.rs | 2 +- examples/circom.rs | 8 +++--- examples/sha256.rs | 6 ++--- examples/sha256_ivc.rs | 2 +- fcomm/src/lib.rs | 4 +-- fcomm/tests/makefile_tests.rs | 2 +- lurk-macros/src/lib.rs | 17 ++++++------- src/circuit/circuit_frame.rs | 5 +--- src/circuit/gadgets/hashes.rs | 4 +-- src/cli/circom.rs | 5 +--- src/cli/repl.rs | 2 +- src/coprocessor/circom.rs | 2 +- src/eval/mod.rs | 2 +- src/field.rs | 2 +- src/hash.rs | 2 +- src/lem/mod.rs | 6 ++--- src/lem/path.rs | 6 ++--- src/lem/store.rs | 8 +++--- src/parser.rs | 6 ++--- src/parser/base.rs | 12 ++++----- src/parser/error.rs | 12 ++++----- src/parser/position.rs | 6 ++--- src/parser/string.rs | 12 ++++----- src/parser/syntax.rs | 2 +- src/public_parameters/mod.rs | 2 +- src/store.rs | 3 +-- src/symbol.rs | 10 ++++---- src/syntax.rs | 28 ++++++++++----------- src/z_data.rs | 4 +-- src/z_data/serde/de.rs | 47 +++++++++++++++-------------------- src/z_data/z_expr.rs | 18 +++++++------- src/z_data/z_ptr.rs | 2 +- tests/lurk-cli-tests.rs | 6 ++--- 33 files changed, 119 insertions(+), 136 deletions(-) diff --git a/benches/sha256_ivc.rs b/benches/sha256_ivc.rs index 9db2d75820..699d230d30 100644 --- a/benches/sha256_ivc.rs +++ b/benches/sha256_ivc.rs @@ -54,7 +54,7 @@ fn sha256_ivc( .map(|i| format!("(sha256 . {i})")) .collect::>() .join(" "); - let input = format!("'({})", input); + let input = format!("'({input})"); let program = format!( r#" (letrec ((encode-1 (lambda (term) diff --git a/examples/circom.rs b/examples/circom.rs index 0009b34c5c..74b8ab477e 100644 --- a/examples/circom.rs +++ b/examples/circom.rs @@ -109,7 +109,7 @@ fn main() { )], ); - let coproc_expr = format!("{}", sym_str); + let coproc_expr = format!("{sym_str}"); let expr = format!("({coproc_expr})"); let ptr = store.read(&expr).unwrap(); @@ -129,7 +129,7 @@ fn main() { .unwrap(); let pp_end = pp_start.elapsed(); - println!("Public parameters took {:?}", pp_end); + println!("Public parameters took {pp_end:?}"); println!("Beginning proof step..."); @@ -139,7 +139,7 @@ fn main() { .unwrap(); let proof_end = proof_start.elapsed(); - println!("Proofs took {:?}", proof_end); + println!("Proofs took {proof_end:?}"); println!("Verifying proof..."); @@ -147,7 +147,7 @@ fn main() { let res = proof.verify(&pp, num_steps, &z0, &zi).unwrap(); let verify_end = verify_start.elapsed(); - println!("Verify took {:?}", verify_end); + println!("Verify took {verify_end:?}"); if res { println!( diff --git a/examples/sha256.rs b/examples/sha256.rs index 44e537b917..dcb1f2eb9b 100644 --- a/examples/sha256.rs +++ b/examples/sha256.rs @@ -205,7 +205,7 @@ fn main() { .unwrap(); let pp_end = pp_start.elapsed(); - println!("Public parameters took {:?}", pp_end); + println!("Public parameters took {pp_end:?}"); if setup_only { return; @@ -222,7 +222,7 @@ fn main() { }); let proof_end = proof_start.elapsed(); - println!("Proofs took {:?}", proof_end); + println!("Proofs took {proof_end:?}"); println!("Verifying proof..."); @@ -230,7 +230,7 @@ fn main() { let res = proof.verify(&pp, num_steps, &z0, &zi).unwrap(); let verify_end = verify_start.elapsed(); - println!("Verify took {:?}", verify_end); + println!("Verify took {verify_end:?}"); if res { println!( diff --git a/examples/sha256_ivc.rs b/examples/sha256_ivc.rs index 0b74c8d043..1edf391512 100644 --- a/examples/sha256_ivc.rs +++ b/examples/sha256_ivc.rs @@ -36,7 +36,7 @@ fn sha256_ivc(store: &mut Store, n: usize, input: Vec) - .map(|i| i.to_string()) .collect::>() .join(" "); - let input = format!("'({})", input); + let input = format!("'({input})"); let program = format!( r#" (letrec ((encode-1 (lambda (term) diff --git a/fcomm/src/lib.rs b/fcomm/src/lib.rs index 86e53c8cf6..e61cf8d973 100644 --- a/fcomm/src/lib.rs +++ b/fcomm/src/lib.rs @@ -78,7 +78,7 @@ mod base64 { pub type NovaProofCache = FileMap>; pub fn nova_proof_cache(reduction_count: usize) -> NovaProofCache { - FileMap::>::new(format!("nova_proofs.{}", reduction_count)).unwrap() + FileMap::>::new(format!("nova_proofs.{reduction_count}")).unwrap() } pub type CommittedExpressionMap = FileMap, CommittedExpression>; @@ -1261,7 +1261,7 @@ mod test { Some(c) => commitment = c, _ => panic!("new commitment missing"), } - println!("Commitment: {:?}", commitment); + println!("Commitment: {commitment:?}"); } } diff --git a/fcomm/tests/makefile_tests.rs b/fcomm/tests/makefile_tests.rs index 6035b54803..5a46309f92 100644 --- a/fcomm/tests/makefile_tests.rs +++ b/fcomm/tests/makefile_tests.rs @@ -21,7 +21,7 @@ fn test_make_fcomm_examples() { let make_output = Command::new("make") .current_dir(examples_dir) - .arg(format!("-j{}", cpus)) + .arg(format!("-j{cpus}")) .output() .expect("Failed to run the make command, is make installed?"); diff --git a/lurk-macros/src/lib.rs b/lurk-macros/src/lib.rs index f0da16635b..15fe0d52b8 100644 --- a/lurk-macros/src/lib.rs +++ b/lurk-macros/src/lib.rs @@ -298,10 +298,10 @@ pub fn serde_test(args: TokenStream, input: TokenStream) -> TokenStream { } } - _ => panic!("invalid attribute {:?}", path), + _ => panic!("invalid attribute {path:?}"), }, - _ => panic!("invalid argument {:?}", arg), + _ => panic!("invalid argument {arg:?}"), } } @@ -318,7 +318,7 @@ pub fn serde_test(args: TokenStream, input: TokenStream) -> TokenStream { for (i, ty) in types.into_iter().enumerate() { let serde_test = { let test_name = Ident::new( - &format!("test_serde_roundtrip_{}_{}", name, i), + &format!("test_serde_roundtrip_{name}_{i}"), Span::mixed_site(), ); quote! { @@ -335,7 +335,7 @@ pub fn serde_test(args: TokenStream, input: TokenStream) -> TokenStream { let zdata_test = if test_zdata { let test_name = Ident::new( - &format!("test_zdata_roundtrip_{}_{}", name, i), + &format!("test_zdata_roundtrip_{name}_{i}"), Span::mixed_site(), ); quote! { @@ -398,7 +398,7 @@ fn get_type_from_attrs(attrs: &[syn::Attribute], attr_name: &str) -> syn::Result }) else { return Err(syn::Error::new( proc_macro2::Span::call_site(), - format!("Could not find attribute {}", attr_name), + format!("Could not find attribute {attr_name}"), )); }; @@ -406,7 +406,7 @@ fn get_type_from_attrs(attrs: &[syn::Attribute], attr_name: &str) -> syn::Result NestedMeta::Meta(Meta::Path(path)) => Ok(path), bad => Err(syn::Error::new_spanned( bad, - &format!("Could not parse {} attribute", attr_name)[..], + &format!("Could not parse {attr_name} attribute")[..], )), } } @@ -447,10 +447,7 @@ pub fn derive_try_from_repr(input: TokenStream) -> TokenStream { match res_ty { Err(e) => { // If no explicit repr were given for us, we can't pursue - panic!( - "TryFromRepr macro requires a repr parameter, which couldn't be parsed: {:?}", - e - ); + panic!("TryFromRepr macro requires a repr parameter, which couldn't be parsed: {e:?}"); } Ok(ty) => { let match_arms = try_from_match_arms(name, &variants, ty.clone()); diff --git a/src/circuit/circuit_frame.rs b/src/circuit/circuit_frame.rs index ed6b4dc319..df8b61d204 100644 --- a/src/circuit/circuit_frame.rs +++ b/src/circuit/circuit_frame.rs @@ -5123,10 +5123,7 @@ fn car_cdr_named>( maybe_cons.hash().get_value(), &allocated_digest.get_value() ); - panic!( - "tried to take car_cdr of a non-dummy cons ({:?}) but supplied wrong value", - name - ); + panic!("tried to take car_cdr of a non-dummy cons ({name:?}) but supplied wrong value"); } implies!(cs, &cons_not_dummy, &real_cons); diff --git a/src/circuit/gadgets/hashes.rs b/src/circuit/gadgets/hashes.rs index 13b8ad99e1..6d3bdeb8b1 100644 --- a/src/circuit/gadgets/hashes.rs +++ b/src/circuit/gadgets/hashes.rs @@ -344,7 +344,7 @@ impl<'a, F: LurkField> AllocatedConsWitness<'a, F> { } = &self.slots[index]; if !expect_dummy { match allocated_name { - Err(_) => panic!("requested {:?} but found a dummy allocation", name), + Err(_) => panic!("requested {name:?} but found a dummy allocation"), Ok(alloc_name) => assert_eq!( name, *alloc_name, "requested and allocated names don't match." @@ -478,7 +478,7 @@ impl<'a, F: LurkField> AllocatedContWitness<'a, F> { if !expect_dummy { match allocated_name { Err(_) => { - panic!("requested {:?} but found a dummy allocation", name) + panic!("requested {name:?} but found a dummy allocation") } Ok(alloc_name) => { assert_eq!( diff --git a/src/cli/circom.rs b/src/cli/circom.rs index d0945225d0..4a44fbd6d9 100644 --- a/src/cli/circom.rs +++ b/src/cli/circom.rs @@ -95,10 +95,7 @@ pub(crate) fn create_circom_gadget(circom_folder: Utf8PathBuf, name: String) -> default_field }; - println!( - "Running circom binary to generate r1cs and witness files to {:?}", - circom_gadget - ); + println!("Running circom binary to generate r1cs and witness files to {circom_gadget:?}"); fs::create_dir_all(&circom_gadget)?; let output = get_circom_binary()? .args(&[ diff --git a/src/cli/repl.rs b/src/cli/repl.rs index 527f79d33c..d384a2996b 100644 --- a/src/cli/repl.rs +++ b/src/cli/repl.rs @@ -713,7 +713,7 @@ impl Repl { pub(crate) fn load_file(&mut self, file_path: &Utf8Path) -> Result<()> { let input = read_to_string(file_path)?; - println!("Loading {}", file_path); + println!("Loading {file_path}"); let mut input = parser::Span::new(&input); loop { diff --git a/src/coprocessor/circom.rs b/src/coprocessor/circom.rs index ca97fc7425..c9a0955e7c 100644 --- a/src/coprocessor/circom.rs +++ b/src/coprocessor/circom.rs @@ -158,7 +158,7 @@ Then run `lurk coprocessor --name {name} <{}_FOLDER>` to instantiate a new gadge let name = gadget.name(); let circom_folder = circom_dir().join(name); - let r1cs = circom_folder.join(format!("{}.r1cs", name)); + let r1cs = circom_folder.join(format!("{name}.r1cs")); let wasm = circom_folder.join(name).with_extension("wasm"); let config = CircomConfig::::new(wasm, r1cs)?; diff --git a/src/eval/mod.rs b/src/eval/mod.rs index 5bdd52bceb..350f4fee7f 100644 --- a/src/eval/mod.rs +++ b/src/eval/mod.rs @@ -54,7 +54,7 @@ impl Write for IO { impl std::fmt::Display for IO { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> { - write!(f, "{:?}", self) + write!(f, "{self:?}") } } diff --git a/src/field.rs b/src/field.rs index 742f2fb0df..0640583e01 100644 --- a/src/field.rs +++ b/src/field.rs @@ -84,7 +84,7 @@ pub trait LurkField: PrimeField + PrimeFieldBits { let bytes = self.to_bytes(); let mut s = String::with_capacity(bytes.len() * 2); for b in bytes.iter().rev() { - s.push_str(&format!("{:02x?}", b)); + s.push_str(&format!("{b:02x?}")); } s } diff --git a/src/hash.rs b/src/hash.rs index 2f085bcc7a..00463144e5 100644 --- a/src/hash.rs +++ b/src/hash.rs @@ -24,7 +24,7 @@ impl From for HashArity { 4 => Self::A4, 6 => Self::A6, 8 => Self::A8, - _ => panic!("unsupported arity: {}", n), + _ => panic!("unsupported arity: {n}"), } } } diff --git a/src/lem/mod.rs b/src/lem/mod.rs index c652d62437..25ab477d3c 100644 --- a/src/lem/mod.rs +++ b/src/lem/mod.rs @@ -145,9 +145,9 @@ impl std::fmt::Display for Tag { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { use Tag::*; match self { - Expr(tag) => write!(f, "expr.{}", tag), - Cont(tag) => write!(f, "cont.{}", tag), - Ctrl(tag) => write!(f, "ctrl.{}", tag), + Expr(tag) => write!(f, "expr.{tag}"), + Cont(tag) => write!(f, "cont.{tag}"), + Ctrl(tag) => write!(f, "ctrl.{tag}"), } } } diff --git a/src/lem/path.rs b/src/lem/path.rs index b1a757efbf..0ad2f92a5f 100644 --- a/src/lem/path.rs +++ b/src/lem/path.rs @@ -13,9 +13,9 @@ pub(crate) enum PathNode { impl std::fmt::Display for PathNode { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - Self::Tag(tag) => write!(f, "Tag({})", tag), - Self::Lit(lit) => write!(f, "{:?}", lit), - Self::Bool(b) => write!(f, "Bool({})", b), + Self::Tag(tag) => write!(f, "Tag({tag})"), + Self::Lit(lit) => write!(f, "{lit:?}"), + Self::Bool(b) => write!(f, "Bool({b})"), Self::Default => write!(f, "Default"), } } diff --git a/src/lem/store.rs b/src/lem/store.rs index c65ac9d2fa..ace9fae303 100644 --- a/src/lem/store.rs +++ b/src/lem/store.rs @@ -377,17 +377,17 @@ impl Store { impl Ptr { pub fn dbg_display(self, store: &Store) -> String { if let Some(s) = store.fetch_string(&self) { - return format!("\"{}\"", s); + return format!("\"{s}\""); } if let Some(s) = store.fetch_symbol(&self) { - return format!("{}", s); + return format!("{s}"); } match self { Ptr::Leaf(tag, f) => { if let Some(x) = f.to_u64() { - format!("{}{}", tag, x) + format!("{tag}{x}") } else { - format!("{}{:?}", tag, f) + format!("{tag}{f:?}") } } Ptr::Tuple2(tag, x) => { diff --git a/src/parser.rs b/src/parser.rs index 9b44cf8fe8..5174b7f43f 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -44,7 +44,7 @@ impl Store { .parse(Span::new(input)) { Ok((_i, x)) => Ok(self.intern_syntax(x)), - Err(e) => Err(Error::Syntax(format!("{}", e))), + Err(e) => Err(Error::Syntax(format!("{e}"))), } } @@ -60,7 +60,7 @@ impl Store { .parse(Span::new(input)) { Ok((_i, x)) => Ok(self.intern_syntax(x)), - Err(e) => Err(Error::Syntax(format!("{}", e))), + Err(e) => Err(Error::Syntax(format!("{e}"))), } } @@ -73,7 +73,7 @@ impl Store { match preceded(parse_space, parse_maybe_meta(state, false)).parse(input) { Ok((i, Some((is_meta, x)))) => Ok((i, self.intern_syntax(x), is_meta)), Ok((_, None)) => Err(Error::NoInput), - Err(e) => Err(Error::Syntax(format!("{}", e))), + Err(e) => Err(Error::Syntax(format!("{e}"))), } } } diff --git a/src/parser/base.rs b/src/parser/base.rs index 2bd9f8f0ef..172d126562 100644 --- a/src/parser/base.rs +++ b/src/parser/base.rs @@ -196,19 +196,19 @@ pub mod tests { match (expected, p.parse(Span::<'a>::new(i))) { (Some(expected), Ok((_i, x))) if x == expected => (), (Some(expected), Ok((i, x))) => { - println!("input: {:?}", i); - println!("expected: {:?}", expected); - println!("detected: {:?}", x); + println!("input: {i:?}"); + println!("expected: {expected:?}"); + println!("detected: {x:?}"); unreachable!("unexpected parse result") } (Some(..), Err(e)) => { - println!("{}", e); + println!("{e}"); unreachable!("unexpected parse result") } (None, Ok((i, x))) => { - println!("input: {:?}", i); + println!("input: {i:?}"); println!("expected parse error"); - println!("detected: {:?}", x); + println!("detected: {x:?}"); unreachable!("unexpected parse result") } (None, Err(_e)) => (), diff --git a/src/parser/error.rs b/src/parser/error.rs index e378c3663e..8e83481594 100644 --- a/src/parser/error.rs +++ b/src/parser/error.rs @@ -22,12 +22,12 @@ impl fmt::Display for ParseErrorKind { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { Self::InvalidBase16EscapeSequence(seq, _) => { - write!(f, "Unknown base 16 string escape sequence {}.", seq) + write!(f, "Unknown base 16 string escape sequence {seq}.") } Self::ParseIntErr(e) => { - write!(f, "Error parsing number: {}", e) + write!(f, "Error parsing number: {e}") } - e => write!(f, "internal parser error {:?}", e), + e => write!(f, "internal parser error {e:?}"), } } } @@ -98,7 +98,7 @@ impl<'a, F: LurkField> fmt::Display for ParseError, F> { writeln!(&mut res, "^")?; if let Some(exp) = self.expected { - writeln!(&mut res, "Expected {}", exp)?; + writeln!(&mut res, "Expected {exp}")?; } let mut errs = self.errors.iter().filter(|x| !x.is_nom_err()).peekable(); @@ -109,12 +109,12 @@ impl<'a, F: LurkField> fmt::Display for ParseError, F> { Some(_) => { writeln!(&mut res, "Reported errors:")?; for kind in errs { - writeln!(&mut res, "- {}", kind)?; + writeln!(&mut res, "- {kind}")?; } } } - write!(f, "{}", res) + write!(f, "{res}") } } diff --git a/src/parser/position.rs b/src/parser/position.rs index cb4e7512e0..1aa8f688eb 100644 --- a/src/parser/position.rs +++ b/src/parser/position.rs @@ -47,8 +47,8 @@ impl Pos { upto_column: usize, ) -> String { let mut res = String::new(); - let gutter = format!("{}", upto_line).len(); - let pad = format!("{: >gutter$}", from_line, gutter = gutter).len() + 3 + from_column; + let gutter = format!("{upto_line}").len(); + let pad = format!("{from_line: >gutter$}").len() + 3 + from_column; res.push_str(&format!("{}▼\n", " ".to_owned().repeat(pad))); for (line_number, line) in input.lines().enumerate() { if ((line_number + 1) >= from_line) && ((line_number + 1) <= upto_line) { @@ -60,7 +60,7 @@ impl Pos { )); } } - let pad = format!("{: >gutter$}", upto_line, gutter = gutter).len() + 3 + upto_column; + let pad = format!("{upto_line: >gutter$}").len() + 3 + upto_column; res.push_str(&format!("{}▲", " ".to_owned().repeat(pad))); res } diff --git a/src/parser/string.rs b/src/parser/string.rs index cc0f44a5af..dba8f83643 100644 --- a/src/parser/string.rs +++ b/src/parser/string.rs @@ -212,19 +212,19 @@ pub mod tests { match (expected, p.parse(Span::new(i))) { (Some(expected), Ok((_i, x))) if x == expected => (), (Some(expected), Ok((i, x))) => { - println!("input: {:?}", i); - println!("expected: {:?}", expected); - println!("detected: {:?}", x); + println!("input: {i:?}"); + println!("expected: {expected:?}"); + println!("detected: {x:?}"); unreachable!("unexpected parse result") } (Some(..), Err(e)) => { - println!("{}", e); + println!("{e}"); unreachable!("unexpected parse result") } (None, Ok((i, x))) => { - println!("input: {:?}", i); + println!("input: {i:?}"); println!("expected parse error"); - println!("detected: {:?}", x); + println!("detected: {x:?}"); unreachable!("unexpected parse result") } (None, Err(_e)) => (), diff --git a/src/parser/syntax.rs b/src/parser/syntax.rs index 90f228c4e6..d39ce1660b 100644 --- a/src/parser/syntax.rs +++ b/src/parser/syntax.rs @@ -1007,7 +1007,7 @@ pub mod tests { #[test] fn test_minus_zero_symbol() { let x: Syntax = symbol!(["-0"]); - let text = format!("{}", x); + let text = format!("{x}"); let (_, res) = parse_syntax(State::default().rccell(), false, true)(Span::new(&text)) .expect("valid parse"); assert_eq!(x, res) diff --git a/src/public_parameters/mod.rs b/src/public_parameters/mod.rs index 9d0e70649f..f9134c1880 100644 --- a/src/public_parameters/mod.rs +++ b/src/public_parameters/mod.rs @@ -78,7 +78,7 @@ where Ok(mut bytes) => { if let Some((pp, remaining)) = unsafe { decode(&mut bytes) } { assert!(remaining.is_empty()); - eprintln!("Using disk-cached public params for lang {}", lang_key); + eprintln!("Using disk-cached public params for lang {lang_key}"); Ok(bind(pp)) } else { eprintln!("failed to decode bytes"); diff --git a/src/store.rs b/src/store.rs index cff2269626..2f87c108f6 100644 --- a/src/store.rs +++ b/src/store.rs @@ -1295,8 +1295,7 @@ impl Store { ExprTag::Cons => match self.fetch(ptr) { Some(Expression::Cons(car, cdr)) => Ok((car, cdr)), e => Err(Error(format!( - "Can only extract car_cdr from known Cons, instead got {:?} {:?}", - ptr, e, + "Can only extract car_cdr from known Cons, instead got {ptr:?} {e:?}", ))), }, ExprTag::Str => match self.fetch(ptr) { diff --git a/src/symbol.rs b/src/symbol.rs index e9fbed3061..8b5cdd8aef 100644 --- a/src/symbol.rs +++ b/src/symbol.rs @@ -178,7 +178,7 @@ impl Symbol { let mut res = String::new(); for x in xs.chars() { if ESCAPE_CHARS.chars().any(|c| c == x) { - res.push_str(&format!("\\{}", x)); + res.push_str(&format!("\\{x}")); } else if Self::is_whitespace(x) { res.push_str(&format!("{}", x.escape_unicode())); } else { @@ -419,8 +419,8 @@ pub mod test { let a_b = a.direct_child("b"); let a_b_path = vec!["a", "b"]; - assert_eq!(".a", format!("{}", a)); - assert_eq!(".a.b", format!("{}", a_b)); + assert_eq!(".a", format!("{a}")); + assert_eq!(".a.b", format!("{a_b}")); assert_eq!(&a_b_path, &a_b.path); assert_eq!(Some(a.clone()), a_b.direct_parent()); assert_eq!(Some(root.clone()), a.direct_parent()); @@ -437,8 +437,8 @@ pub mod test { assert!(!root.is_keyword()); assert!(key_root.is_keyword()); - assert_eq!(".apple", format!("{}", apple)); - assert_eq!(":orange", format!("{}", orange)); + assert_eq!(".apple", format!("{apple}")); + assert_eq!(":orange", format!("{orange}")); assert!(!apple.is_keyword()); assert!(orange.is_keyword()); assert_eq!(key_root, orange.direct_parent().unwrap()); diff --git a/src/syntax.rs b/src/syntax.rs index 413ad171ce..6553df92cd 100644 --- a/src/syntax.rs +++ b/src/syntax.rs @@ -68,25 +68,25 @@ impl Arbitrary for Syntax { impl fmt::Display for Syntax { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { - Self::Num(_, x) => write!(f, "{}", x), - Self::UInt(_, x) => write!(f, "{}u64", x), - Self::Symbol(_, x) => write!(f, "{}", x), + Self::Num(_, x) => write!(f, "{x}"), + Self::UInt(_, x) => write!(f, "{x}u64"), + Self::Symbol(_, x) => write!(f, "{x}"), Self::String(_, x) => write!(f, "\"{}\"", x.escape_default()), Self::Char(_, x) => { if *x == '(' || *x == ')' { - write!(f, "'\\{}'", x) + write!(f, "'\\{x}'") } else { write!(f, "'{}'", x.escape_default()) } } - Self::Quote(_, x) => write!(f, "'{}", x), + Self::Quote(_, x) => write!(f, "'{x}"), Self::List(_, xs) => { let mut iter = xs.iter().peekable(); write!(f, "(")?; while let Some(x) = iter.next() { match iter.peek() { - Some(_) => write!(f, "{} ", x)?, - None => write!(f, "{}", x)?, + Some(_) => write!(f, "{x} ")?, + None => write!(f, "{x}")?, } } write!(f, ")") @@ -96,7 +96,7 @@ impl fmt::Display for Syntax { write!(f, "(")?; while let Some(x) = iter.next() { match iter.peek() { - Some(_) => write!(f, "{} ", x)?, + Some(_) => write!(f, "{x} ")?, None => write!(f, "{} . {}", x, *end)?, } } @@ -226,28 +226,28 @@ mod test { // Quote tests let expr = list!(lurk_sym_ptr!(s, quote), list!(sym!(f), sym!(x), sym!(y))); let output = s.fetch_syntax(expr).unwrap(); - assert_eq!("(.lurk.quote (.f .x .y))", &format!("{}", output)); + assert_eq!("(.lurk.quote (.f .x .y))", &format!("{output}")); let expr = list!(lurk_sym_ptr!(s, quote), list!(sym!(f), sym!(x), sym!(y))); let output = s.fetch_syntax(expr).unwrap(); - assert_eq!("(.lurk.quote (.f .x .y))", &format!("{}", output)); + assert_eq!("(.lurk.quote (.f .x .y))", &format!("{output}")); let expr = list!(lurk_sym_ptr!(s, quote), sym!(f), sym!(x), sym!(y)); let output = s.fetch_syntax(expr).unwrap(); - assert_eq!("(.lurk.quote .f .x .y)", &format!("{}", output)); + assert_eq!("(.lurk.quote .f .x .y)", &format!("{output}")); // List tests let expr = list!(); let output = s.fetch_syntax(expr).unwrap(); - assert_eq!(".lurk.nil", &format!("{}", output)); + assert_eq!(".lurk.nil", &format!("{output}")); let expr = improper!(sym!(x), sym!(y), sym!(z)); let output = s.fetch_syntax(expr).unwrap(); - assert_eq!("(.x .y . .z)", &format!("{}", output)); + assert_eq!("(.x .y . .z)", &format!("{output}")); let expr = improper!(sym!(x), sym!(y), lurk_sym_ptr!(s, nil)); let output = s.fetch_syntax(expr).unwrap(); - assert_eq!("(.x .y)", &format!("{}", output)); + assert_eq!("(.x .y)", &format!("{output}")); } #[test] diff --git a/src/z_data.rs b/src/z_data.rs index dc564d0c33..d073c8ad96 100644 --- a/src/z_data.rs +++ b/src/z_data.rs @@ -62,7 +62,7 @@ impl Display for ZData { .map(|x| format!("{:02x?}", x)) .collect::>() .join(", "); - write!(f, "a:{}", xs_str)?; + write!(f, "a:{xs_str}")?; } Self::Cell(xs) => { let xs_str = xs @@ -70,7 +70,7 @@ impl Display for ZData { .map(|x| format!("{}", x)) .collect::>() .join(", "); - write!(f, "c:{}", xs_str)?; + write!(f, "c:{xs_str}")?; } } write!(f, "]")?; diff --git a/src/z_data/serde/de.rs b/src/z_data/serde/de.rs index cae6dc8040..c363c6dac6 100644 --- a/src/z_data/serde/de.rs +++ b/src/z_data/serde/de.rs @@ -49,9 +49,9 @@ impl<'de, 'a> de::Deserializer<'de> for &'a mut Deserializer<'de> { ZData::Atom(x) if x.len() == 1 => match x[0] { 0u8 => visitor.visit_bool(false), 1u8 => visitor.visit_bool(true), - err => Err(SerdeError::Type(format!("expected bool, got: {}", err))), + err => Err(SerdeError::Type(format!("expected bool, got: {err}"))), }, - err => Err(SerdeError::Type(format!("expected bool, got: {}", err))), + err => Err(SerdeError::Type(format!("expected bool, got: {err}"))), } } @@ -105,7 +105,7 @@ impl<'de, 'a> de::Deserializer<'de> for &'a mut Deserializer<'de> { { match self.input { ZData::Atom(x) if x.len() == 1 => visitor.visit_u8(x[0]), - err => Err(SerdeError::Type(format!("expected u8, got: {}", err))), + err => Err(SerdeError::Type(format!("expected u8, got: {err}"))), } } @@ -119,7 +119,7 @@ impl<'de, 'a> de::Deserializer<'de> for &'a mut Deserializer<'de> { let a: [u8; 2] = x.clone().try_into().unwrap(); visitor.visit_u16(u16::from_le_bytes(a)) } - err => Err(SerdeError::Type(format!("expected u16, got: {}", err))), + err => Err(SerdeError::Type(format!("expected u16, got: {err}"))), } } @@ -133,7 +133,7 @@ impl<'de, 'a> de::Deserializer<'de> for &'a mut Deserializer<'de> { let a: [u8; 4] = x.clone().try_into().unwrap(); visitor.visit_u32(u32::from_le_bytes(a)) } - err => Err(SerdeError::Type(format!("expected u32: got {}", err))), + err => Err(SerdeError::Type(format!("expected u32: got {err}"))), } } @@ -147,7 +147,7 @@ impl<'de, 'a> de::Deserializer<'de> for &'a mut Deserializer<'de> { let a: [u8; 8] = x.clone().try_into().unwrap(); visitor.visit_u64(u64::from_le_bytes(a)) } - err => Err(SerdeError::Type(format!("expected u64: got {}", err))), + err => Err(SerdeError::Type(format!("expected u64: got {err}"))), } } @@ -182,10 +182,7 @@ impl<'de, 'a> de::Deserializer<'de> for &'a mut Deserializer<'de> { .map_err(|e| SerdeError::Type(format!("expected char: {}", e)))?; match char::from_u32(num) { Some(a) => visitor.visit_char(a), - None => Err(SerdeError::Type(format!( - "failed to get char from: {}", - num - ))), + None => Err(SerdeError::Type(format!("failed to get char from: {num}"))), } } @@ -203,12 +200,12 @@ impl<'de, 'a> de::Deserializer<'de> for &'a mut Deserializer<'de> { v.push(char::deserialize(&mut Deserializer::from_z_data(zd))?) } err => { - return Err(SerdeError::Type(format!("expected string, got: {}", err))) + return Err(SerdeError::Type(format!("expected string, got: {err}"))) } } } } - err => return Err(SerdeError::Type(format!("expected string, got: {}", err))), + err => return Err(SerdeError::Type(format!("expected string, got: {err}"))), } visitor.visit_str(&v.into_iter().collect::()) } @@ -228,7 +225,7 @@ impl<'de, 'a> de::Deserializer<'de> for &'a mut Deserializer<'de> { { match self.input { ZData::Atom(x) => visitor.visit_bytes(x), - err => Err(SerdeError::Type(format!("expected bytes, got: {}", err))), + err => Err(SerdeError::Type(format!("expected bytes, got: {err}"))), } } @@ -248,11 +245,11 @@ impl<'de, 'a> de::Deserializer<'de> for &'a mut Deserializer<'de> { match self.input { ZData::Atom(x) => match x.as_slice() { [] => visitor.visit_none(), - err => Err(SerdeError::Type(format!("expected Option, got: {:?}", err))), + err => Err(SerdeError::Type(format!("expected Option, got: {err:?}"))), }, ZData::Cell(xs) => match xs.as_slice() { [a] => visitor.visit_some(&mut Deserializer::from_z_data(a)), - err => Err(SerdeError::Type(format!("expected Option, got: {:?}", err))), + err => Err(SerdeError::Type(format!("expected Option, got: {err:?}"))), }, } } @@ -265,12 +262,9 @@ impl<'de, 'a> de::Deserializer<'de> for &'a mut Deserializer<'de> { match self.input { ZData::Atom(x) => match x.as_slice() { [] => visitor.visit_none(), - err => Err(SerdeError::Type(format!( - "expected Unit (), got: {:?}", - err - ))), + err => Err(SerdeError::Type(format!("expected Unit (), got: {err:?}"))), }, - err => Err(SerdeError::Type(format!("expected Unit (), got: {}", err))), + err => Err(SerdeError::Type(format!("expected Unit (), got: {err}"))), } } @@ -305,7 +299,7 @@ impl<'de, 'a> de::Deserializer<'de> for &'a mut Deserializer<'de> { { match self.input { ZData::Cell(xs) => visitor.visit_seq(SeqAccess::new(xs, 0)), - err => Err(SerdeError::Type(format!("expected sequence, got: {}", err))), + err => Err(SerdeError::Type(format!("expected sequence, got: {err}"))), } } @@ -337,7 +331,7 @@ impl<'de, 'a> de::Deserializer<'de> for &'a mut Deserializer<'de> { { match self.input { ZData::Cell(xs) => visitor.visit_map(MapAccess::new(xs)), - err => Err(SerdeError::Type(format!("expected map, got: {}", err))), + err => Err(SerdeError::Type(format!("expected map, got: {err}"))), } } @@ -370,9 +364,9 @@ impl<'de, 'a> de::Deserializer<'de> for &'a mut Deserializer<'de> { let variant = String::from(variants[idx_vec[0] as usize]); visitor.visit_enum(Enum::new(self, variant, 1)) } - err => Err(SerdeError::Type(format!("expected enum, got: {}", err))), + err => Err(SerdeError::Type(format!("expected enum, got: {err}"))), }, - err => Err(SerdeError::Type(format!("expected enum, got: {}", err))), + err => Err(SerdeError::Type(format!("expected enum, got: {err}"))), } } @@ -515,8 +509,7 @@ impl<'de, 'a> de::VariantAccess<'de> for Enum<'a, 'de> { ZData::Cell(xs) if xs.len() > 1 => Deserializer::from_z_data(&xs[1]), err => { return Err(SerdeError::Type(format!( - "expected newtype variant, got: {}", - err + "expected newtype variant, got: {err}" ))) } }; @@ -529,7 +522,7 @@ impl<'de, 'a> de::VariantAccess<'de> for Enum<'a, 'de> { { match self.de.input { ZData::Cell(xs) => visitor.visit_seq(SeqAccess::new(xs, self.index)), - err => Err(SerdeError::Type(format!("expected sequence, got: {}", err))), + err => Err(SerdeError::Type(format!("expected sequence, got: {err}"))), } } diff --git a/src/z_data/z_expr.rs b/src/z_data/z_expr.rs index 016b7900fe..47487ba7bc 100644 --- a/src/z_data/z_expr.rs +++ b/src/z_data/z_expr.rs @@ -55,25 +55,25 @@ impl std::fmt::Display for ZExpr { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { ZExpr::Nil => write!(f, "nil"), - ZExpr::Cons(x, y) => write!(f, "({} . {})", x, y), - ZExpr::Str(x, y) => write!(f, "(str {} {})", x, y), - ZExpr::Sym(x, y) => write!(f, "(sym {} {})", x, y), - ZExpr::Key(x, y) => write!(f, "(key {} {})", x, y), + ZExpr::Cons(x, y) => write!(f, "({x} . {y})"), + ZExpr::Str(x, y) => write!(f, "(str {x} {y})"), + ZExpr::Sym(x, y) => write!(f, "(sym {x} {y})"), + ZExpr::Key(x, y) => write!(f, "(key {x} {y})"), ZExpr::Comm(ff, x) => { write!(f, "(comm {} {})", ff.trimmed_hex_digits(), x) } ZExpr::EmptyStr => write!(f, "emptystr"), ZExpr::RootSym => write!(f, "rootsym"), ZExpr::RootKey => write!(f, "rootkey"), - ZExpr::Thunk(val, cont) => write!(f, "(thunk {} {})", val, cont), + ZExpr::Thunk(val, cont) => write!(f, "(thunk {val} {cont})"), ZExpr::Fun { arg, body, closed_env, - } => write!(f, "(fun {} {} {})", arg, body, closed_env), - ZExpr::Char(x) => write!(f, "(char {})", x), - ZExpr::Num(x) => write!(f, "(num {:?})", x), - ZExpr::UInt(x) => write!(f, "(uint {})", x), + } => write!(f, "(fun {arg} {body} {closed_env})"), + ZExpr::Char(x) => write!(f, "(char {x})"), + ZExpr::Num(x) => write!(f, "(num {x:?})"), + ZExpr::UInt(x) => write!(f, "(uint {x})"), } } } diff --git a/src/z_data/z_ptr.rs b/src/z_data/z_ptr.rs index f69899b351..00856c8eab 100644 --- a/src/z_data/z_ptr.rs +++ b/src/z_data/z_ptr.rs @@ -110,7 +110,7 @@ impl ZPtr { pub fn to_base32(&self) -> String { let tag_b32 = Base32Unpadded::encode_string(&self.0.into().to_le_bytes()); let val_b32 = Base32Unpadded::encode_string(self.1.to_repr().as_ref()); - format!("{}z{}", tag_b32, val_b32) + format!("{tag_b32}z{val_b32}") } /// Converts a base32-encoded string to a ZPtr diff --git a/tests/lurk-cli-tests.rs b/tests/lurk-cli-tests.rs index 9c3f35943e..66c1acb047 100644 --- a/tests/lurk-cli-tests.rs +++ b/tests/lurk-cli-tests.rs @@ -65,13 +65,13 @@ fn test_config_file() { let mut config_file = File::create(&config_dir).unwrap(); config_file - .write_all(format!("public_params = \"{}\"\n", public_params_dir).as_bytes()) + .write_all(format!("public_params = \"{public_params_dir}\"\n").as_bytes()) .unwrap(); config_file - .write_all(format!("proofs = \"{}\"\n", proofs_dir).as_bytes()) + .write_all(format!("proofs = \"{proofs_dir}\"\n").as_bytes()) .unwrap(); config_file - .write_all(format!("commits = \"{}\"\n", commits_dir).as_bytes()) + .write_all(format!("commits = \"{commits_dir}\"\n").as_bytes()) .unwrap(); // Overwrite proof dir with env var