From 81023afc5f536d0446f6123b1963aa5f3750504d Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Sat, 1 Feb 2025 01:37:41 -0500 Subject: [PATCH] chore: cleanup format args Manually clean up [`uninlined_format_args`](https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args) clippy lint. Some of these changes cause about 5% performance improvements because `format!("{}", &var)` does not need a reference and cannot be optimized by the compiler (but in thees cases the perf difference is less important) --- build.rs | 18 ++++++++---------- examples/android/lib.rs | 4 ++-- examples/cppgc-object.rs | 2 +- examples/process.rs | 4 ++-- src/support.rs | 9 +++------ tests/test_api.rs | 3 +-- tests/test_cppgc.rs | 2 +- 7 files changed, 18 insertions(+), 24 deletions(-) diff --git a/build.rs b/build.rs index f1d0ba52..a31f2385 100644 --- a/build.rs +++ b/build.rs @@ -134,7 +134,7 @@ fn acquire_lock() -> LockFile { let mut lockfile = LockFile::open(&lockfilepath) .expect("Couldn't open lib download lockfile."); lockfile.lock_with_pid().expect("Couldn't get lock"); - println!("lockfile: {:?}", &lockfilepath); + println!("lockfile: {lockfilepath:?}"); lockfile } @@ -414,9 +414,7 @@ fn static_lib_url() -> String { let target = env::var("TARGET").unwrap(); let profile = prebuilt_profile(); format!( - "{}/v{}/{}.gz", - base, - version, + "{base}/v{version}/{}.gz", static_lib_name(&format!("_{profile}_{target}")), ) } @@ -823,7 +821,7 @@ fn maybe_symlink_root_dir(dirs: &mut Dirs) { let symlink = &*out.join("gn_root"); let target = &*root.canonicalize().unwrap(); - println!("Creating symlink {:?} to {:?}", &symlink, &root); + println!("Creating symlink {symlink:?} to {root:?}"); let mut retries = 0; loop { @@ -831,19 +829,19 @@ fn maybe_symlink_root_dir(dirs: &mut Dirs) { Ok(existing) if existing == target => break, Ok(_) => remove_dir_all(symlink).expect("remove_dir_all failed"), Err(err) => { - println!("symlink.canonicalize failed: {:?}", err); + println!("symlink.canonicalize failed: {err:?}"); // we're having very strange issues on GHA when the cache // is restored, so trying this out temporarily if let Err(err) = remove_dir_all(symlink) { - eprintln!("remove_dir_all failed: {:?}", err); + eprintln!("remove_dir_all failed: {err:?}"); if let Err(err) = remove_file(symlink) { - eprintln!("remove_file failed: {:?}", err); + eprintln!("remove_file failed: {err:?}"); } } match symlink_dir(target, symlink) { Ok(_) => break, Err(err) => { - println!("symlink_dir failed: {:?}", err); + println!("symlink_dir failed: {err:?}"); retries += 1; std::thread::sleep(std::time::Duration::from_millis( 50 * retries, @@ -915,7 +913,7 @@ pub fn maybe_gen(gn_args: GnArgs) -> PathBuf { if !gn_out_dir.exists() || !gn_out_dir.join("build.ninja").exists() { let args = if let Ok(extra_args) = env::var("EXTRA_GN_ARGS") { - format!("{} {}", gn_args.join(" "), extra_args) + format!("{} {extra_args}", gn_args.join(" ")) } else { gn_args.join(" ") }; diff --git a/examples/android/lib.rs b/examples/android/lib.rs index 84ed6fa8..3a007c27 100644 --- a/examples/android/lib.rs +++ b/examples/android/lib.rs @@ -103,7 +103,7 @@ fn execute_script( .map(|value| value.to_rust_string_lossy(try_catch)) .unwrap_or_else(|| "no stack trace".into()); - panic!("{}", exception_string); + panic!("{exception_string}"); } } @@ -128,7 +128,7 @@ fn draw( .map(|value| value.to_rust_string_lossy(try_catch)) .unwrap_or_else(|| "no stack trace".into()); - panic!("{}", exception_string); + panic!("{exception_string}"); } }; diff --git a/examples/cppgc-object.rs b/examples/cppgc-object.rs index 8f09ea69..8f7af593 100644 --- a/examples/cppgc-object.rs +++ b/examples/cppgc-object.rs @@ -120,6 +120,6 @@ fn execute_script( .map(|value| value.to_rust_string_lossy(try_catch)) .unwrap_or_else(|| "no stack trace".into()); - panic!("{}", exception_string); + panic!("{exception_string}"); } } diff --git a/examples/process.rs b/examples/process.rs index 057cc823..9fbb655e 100644 --- a/examples/process.rs +++ b/examples/process.rs @@ -223,7 +223,7 @@ where .unwrap() .to_rust_string_lossy(try_catch); - panic!("{}", exception_string); + panic!("{exception_string}"); } } @@ -251,7 +251,7 @@ where .unwrap() .to_rust_string_lossy(try_catch); - panic!("{}", exception_string); + panic!("{exception_string}"); } } diff --git a/src/support.rs b/src/support.rs index bf7fcaec..ec4e9072 100644 --- a/src/support.rs +++ b/src/support.rs @@ -360,13 +360,10 @@ fn assert_shared_ptr_use_count_eq( }; assert!( ok, - "assertion failed: `{}<{}>` reference count does not match expectation\ - \n actual: {}\ - \n expected: {}", - wrapper_type_name, + "assertion failed: `{wrapper_type_name}<{}>` reference count does not match expectation\ + \n actual: {actual}\ + \n expected: {expected}", type_name::(), - actual, - expected ); } diff --git a/tests/test_api.rs b/tests/test_api.rs index 63abe80b..6952ac6e 100644 --- a/tests/test_api.rs +++ b/tests/test_api.rs @@ -6696,8 +6696,7 @@ impl v8::inspector::ChannelImpl for ChannelCounter { message: v8::UniquePtr, ) { println!( - "send_response call_id {} message {}", - call_id, + "send_response call_id {call_id} message {}", message.unwrap().string() ); self.count_send_response += 1; diff --git a/tests/test_cppgc.rs b/tests/test_cppgc.rs index e9622f90..56410c6b 100644 --- a/tests/test_cppgc.rs +++ b/tests/test_cppgc.rs @@ -236,6 +236,6 @@ fn execute_script( .map(|value| value.to_rust_string_lossy(scope)) .unwrap_or_else(|| "no stack trace".into()); - panic!("{}", exception_string); + panic!("{exception_string}"); } }