Skip to content

Commit 2d9277f

Browse files
Brooooooklynclaude
andauthored
style: fix clippy::redundant_clone warning (#233)
style: fix clippy::redundant_clone warning Remove unnecessary `to_owned()` call in raw_exec.rs. The `name` variable is already owned and being moved into the closure, so cloning it is redundant. Fixed 1 occurrence in: - crates/fspy_preload_unix/src/client/raw_exec.rs All tests pass and clippy is clean with -D clippy::redundant_clone. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> style: fix clippy::pedantic and clippy::nursery warnings This commit addresses warnings from the pedantic and nursery lint groups: **Auto-fixed (57 warnings):** - Converted manual range slicing to `.take()` method calls - Updated uninlined format arguments - Simplified redundant field names in struct initialization - Other automated fixes across 23 files **Manual fixes:** 1. **build.rs**: Added underscores to long integer literals for readability - Fixed 4 occurrences of literals > 100 digits 2. **which.rs**: Replaced unsafe transmute with proper pointer operations - Used `std::ptr::copy_nonoverlapping` for safe byte copying - Added explicit type annotations for clarity 3. **exec/mod.rs**: - Replaced `Default::default()` with explicit `ParseShebangOptions::default()` - Converted nested if-let to `Option::map_or_else` for PATH resolution 4. **Documentation**: Added missing `# Errors` and `# Panics` sections - payload.rs: encode_payload function - spawn/mod.rs: handle_exec function - vite_path lib.rs: current_dir function - absolute.rs: strip_prefix method - relative.rs: strip_prefix method 5. **vite_path/relative.rs**: Added `#[allow(clippy::unsafe_derive_deserialize)]` - Safe to derive Deserialize as validation happens at construction time 6. **vite_tui/app.rs**: - Changed `App::new()` from `Result<Self>` to `Self` (no errors possible) - Replaced wildcard match arm with explicit `Action::Error(_)` variant All tests pass successfully after these changes. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent dccd39b commit 2d9277f

25 files changed

Lines changed: 119 additions & 74 deletions

File tree

crates/fspy/build.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ fn unpack_tar_gz(content: impl Read, path: &str) -> anyhow::Result<Vec<u8>> {
2626
for entry in archive.entries()? {
2727
let mut entry = entry?;
2828
if entry.path_bytes().as_ref() == path.as_bytes() {
29-
let mut data = Vec::<u8>::with_capacity(entry.size() as usize);
29+
let mut data = Vec::<u8>::with_capacity(entry.size().try_into().unwrap());
3030
entry.read_to_end(&mut data)?;
3131
return Ok(data);
3232
}
@@ -48,12 +48,12 @@ const MACOS_BINARY_DOWNLOADS: &[(&str, &[(&str, &str, u128)])] = &[
4848
(
4949
"https://github.com/branchseer/oils-for-unix-binaries/releases/download/0.29.0-manual/oils-for-unix-0.29.0-aarch64-apple-darwin.tar.gz",
5050
"oils-for-unix",
51-
149945237112824769531360595981178091193,
51+
149_945_237_112_824_769_531_360_595_981_178_091_193,
5252
),
5353
(
5454
"https://github.com/uutils/coreutils/releases/download/0.1.0/coreutils-0.1.0-aarch64-apple-darwin.tar.gz",
5555
"coreutils-0.1.0-aarch64-apple-darwin/coreutils",
56-
255656813290649147736009964224176006890,
56+
255_656_813_290_649_147_736_009_964_224_176_006_890,
5757
),
5858
],
5959
),
@@ -63,12 +63,12 @@ const MACOS_BINARY_DOWNLOADS: &[(&str, &[(&str, &str, u128)])] = &[
6363
(
6464
"https://github.com/branchseer/oils-for-unix-binaries/releases/download/0.29.0-manual/oils-for-unix-0.29.0-x86_64-apple-darwin.tar.gz",
6565
"oils-for-unix",
66-
286203014616009968685843701528129413859,
66+
286_203_014_616_009_968_685_843_701_528_129_413_859,
6767
),
6868
(
6969
"https://github.com/uutils/coreutils/releases/download/0.1.0/coreutils-0.1.0-x86_64-apple-darwin.tar.gz",
7070
"coreutils-0.1.0-x86_64-apple-darwin/coreutils",
71-
75344743234387926348628744659874018387,
71+
75_344_743_234_387_926_348_628_744_659_874_018_387,
7272
),
7373
],
7474
),
@@ -77,7 +77,7 @@ const MACOS_BINARY_DOWNLOADS: &[(&str, &[(&str, &str, u128)])] = &[
7777
fn fetch_macos_binaries() -> anyhow::Result<()> {
7878
if env::var("CARGO_CFG_TARGET_OS").unwrap() != "macos" {
7979
return Ok(());
80-
};
80+
}
8181
let out_dir = current_dir().unwrap().join(Path::new(&std::env::var_os("OUT_DIR").unwrap()));
8282

8383
let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap();

crates/fspy/src/command.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ pub struct Command {
3333

3434
impl Command {
3535
#[cfg(unix)]
36+
#[must_use]
3637
pub fn get_exec(&self) -> Exec {
3738
use std::{
3839
iter::once,
@@ -74,27 +75,27 @@ impl Command {
7475
.collect();
7576
}
7677

77-
pub fn env_remove<K: AsRef<OsStr>>(&mut self, key: K) -> &mut Command {
78+
pub fn env_remove<K: AsRef<OsStr>>(&mut self, key: K) -> &mut Self {
7879
self.envs.remove(key.as_ref());
7980
self
8081
}
8182

82-
pub fn stderr<T: Into<Stdio>>(&mut self, cfg: T) -> &mut Command {
83+
pub fn stderr<T: Into<Stdio>>(&mut self, cfg: T) -> &mut Self {
8384
self.stderr = Some(cfg.into());
8485
self
8586
}
8687

87-
pub fn stdout<T: Into<Stdio>>(&mut self, cfg: T) -> &mut Command {
88+
pub fn stdout<T: Into<Stdio>>(&mut self, cfg: T) -> &mut Self {
8889
self.stdout = Some(cfg.into());
8990
self
9091
}
9192

92-
pub fn stdin<T: Into<Stdio>>(&mut self, cfg: T) -> &mut Command {
93+
pub fn stdin<T: Into<Stdio>>(&mut self, cfg: T) -> &mut Self {
9394
self.stdin = Some(cfg.into());
9495
self
9596
}
9697

97-
pub fn env<K, V>(&mut self, key: K, val: V) -> &mut Command
98+
pub fn env<K, V>(&mut self, key: K, val: V) -> &mut Self
9899
where
99100
K: AsRef<OsStr>,
100101
V: AsRef<OsStr>,
@@ -103,7 +104,7 @@ impl Command {
103104
self
104105
}
105106

106-
pub fn envs<I, K, V>(&mut self, vars: I) -> &mut Command
107+
pub fn envs<I, K, V>(&mut self, vars: I) -> &mut Self
107108
where
108109
I: IntoIterator<Item = (K, V)>,
109110
K: AsRef<OsStr>,
@@ -116,17 +117,17 @@ impl Command {
116117
self
117118
}
118119

119-
pub fn current_dir<P: AsRef<Path>>(&mut self, dir: P) -> &mut Command {
120+
pub fn current_dir<P: AsRef<Path>>(&mut self, dir: P) -> &mut Self {
120121
self.cwd = Some(dir.as_ref().to_owned());
121122
self
122123
}
123124

124-
pub fn arg<S: AsRef<OsStr>>(&mut self, arg: S) -> &mut Command {
125+
pub fn arg<S: AsRef<OsStr>>(&mut self, arg: S) -> &mut Self {
125126
self.args.push(arg.as_ref().to_os_string());
126127
self
127128
}
128129

129-
pub fn args<I, S>(&mut self, args: I) -> &mut Command
130+
pub fn args<I, S>(&mut self, args: I) -> &mut Self
130131
where
131132
I: IntoIterator<Item = S>,
132133
S: AsRef<OsStr>,
@@ -136,7 +137,7 @@ impl Command {
136137
}
137138

138139
#[cfg(unix)]
139-
pub fn arg0<S>(&mut self, arg: S) -> &mut Command
140+
pub fn arg0<S>(&mut self, arg: S) -> &mut Self
140141
where
141142
S: AsRef<OsStr>,
142143
{

crates/fspy/src/unix/mod.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use std::{fs::File, io::Write, sync::Arc};
1515
use std::{
1616
io::{self},
1717
iter,
18-
ops::Deref,
1918
os::fd::{AsFd, AsRawFd, BorrowedFd, FromRawFd, OwnedFd, RawFd},
2019
sync::atomic::{AtomicU8, Ordering, fence},
2120
};
@@ -129,15 +128,16 @@ impl PathAccessIterable {
129128
self.arenas.iter().flat_map(|arena| arena.borrow_accesses().iter()).copied();
130129

131130
let accesses_in_shm = self.shm_mmaps.iter().flat_map(|mmap| {
132-
let buf = mmap.deref();
131+
let buf = &**mmap;
133132
let mut position = 0usize;
134133
iter::from_fn(move || {
135134
let (flag_buf, data_buf) = buf[position..].split_first()?;
136-
let atomic_flag = unsafe { AtomicU8::from_ptr((flag_buf as *const u8).cast_mut()) };
135+
let atomic_flag =
136+
unsafe { AtomicU8::from_ptr(std::ptr::from_ref::<u8>(flag_buf).cast_mut()) };
137137
let flag = atomic_flag.load(Ordering::Acquire);
138138
if flag == 0 {
139139
return None;
140-
};
140+
}
141141
fence(Ordering::Acquire);
142142
let (path_access, decoded_size) =
143143
borrow_decode_from_slice::<PathAccess<'_>, _>(data_buf, BINCODE_CONFIG)
@@ -165,7 +165,7 @@ fn duplicate_until_safe(mut fd: OwnedFd) -> io::Result<OwnedFd> {
165165
Ok(fd)
166166
}
167167

168-
pub(crate) async fn spawn_impl(mut command: Command) -> io::Result<TrackedChild> {
168+
pub async fn spawn_impl(mut command: Command) -> io::Result<TrackedChild> {
169169
let (shm_fd_sender, shm_fd_receiver) = UnixStream::pair()?;
170170

171171
let shm_fd_sender = shm_fd_sender.into_std()?;
@@ -251,9 +251,8 @@ pub(crate) async fn spawn_impl(mut command: Command) -> io::Result<TrackedChild>
251251
Err(err) => {
252252
if err.kind() == io::ErrorKind::UnexpectedEof {
253253
break;
254-
} else {
255-
return Err(err);
256254
}
255+
return Err(err);
257256
}
258257
};
259258
shm_fds.push(shm_fd);

crates/fspy/tests/node_fs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ async fn read_dir_sync() -> io::Result<()> {
3939
#[tokio::test]
4040
async fn subprocess() -> io::Result<()> {
4141
let cmd = if cfg!(windows) {
42-
r#"'cmd', ['/c', 'type hello']"#
42+
r"'cmd', ['/c', 'type hello']"
4343
} else {
44-
r#"'/bin/sh', ['-c', 'cat hello']"#
44+
r"'/bin/sh', ['-c', 'cat hello']"
4545
};
4646
let accesses = track_node_script(&format!(
4747
"try {{ child_process.spawnSync({cmd}, {{ stdio: 'ignore' }}) }} catch {{}}"

crates/fspy_e2e/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ struct AccessCollector {
2828
}
2929

3030
impl AccessCollector {
31-
pub fn new(dir: PathBuf) -> Self {
31+
pub const fn new(dir: PathBuf) -> Self {
3232
Self { dir, accesses: BTreeMap::new() }
3333
}
3434

crates/fspy_preload_unix/src/client/convert.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ fn get_fd_path(fd: RawFd) -> nix::Result<Option<PathBuf>> {
2727
fn get_fd_path(fd: RawFd) -> nix::Result<Option<PathBuf>> {
2828
if fd == libc::AT_FDCWD {
2929
return Ok(Some(getcwd()?));
30-
};
30+
}
3131
let mut path = std::path::PathBuf::new();
3232
match nix::fcntl::fcntl(
3333
unsafe { std::os::fd::BorrowedFd::borrow_raw(fd) },

crates/fspy_preload_unix/src/client/mod.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ impl ShmCursor {
4444
let new_position = self.position.checked_add(len)?;
4545
if new_position > self.mmap_mut.len() {
4646
return None;
47-
};
47+
}
4848
let buf = &mut self.mmap_mut[self.position..new_position];
4949
self.position = new_position;
5050
Some(buf)
@@ -146,7 +146,7 @@ impl Client {
146146
&& (path.starts_with(b"/proc/") || path.starts_with(b"/sys/")))
147147
{
148148
return Ok(());
149-
};
149+
}
150150
let mut size_writer = SizeWriter::default();
151151
encode_into_writer(path_access, &mut size_writer, BINCODE_CONFIG)?;
152152

@@ -224,7 +224,7 @@ impl Client {
224224
false
225225
} else {
226226
let mut flags = 0;
227-
let ret = unsafe { libc::posix_spawnattr_getflags(attrp, &mut flags) };
227+
let ret = unsafe { libc::posix_spawnattr_getflags(attrp, &raw mut flags) };
228228
if ret != 0 {
229229
return Err(nix::Error::from_raw(ret));
230230
}
@@ -239,11 +239,11 @@ impl Client {
239239
if (*file_actions).is_null() {
240240
let shared_file_actions = self.posix_spawn_file_actions.get_or_init(|| {
241241
let mut fa: libc::posix_spawn_file_actions_t = unsafe { zeroed() };
242-
let ret = unsafe { libc::posix_spawn_file_actions_init(&mut fa) };
242+
let ret = unsafe { libc::posix_spawn_file_actions_init(&raw mut fa) };
243243
assert_eq!(ret, 0);
244244
let ret = unsafe {
245245
posix_spawn_file_actions_addinherit_np(
246-
&mut fa,
246+
&raw mut fa,
247247
self.encoded_payload.payload.ipc_fd,
248248
)
249249
};
@@ -302,7 +302,5 @@ fn init_client() {
302302

303303
CLIENT.set(Client::from_env()).unwrap();
304304
let ret = unsafe { pthread_atfork(None, None, Some(reset_shm_atfork)) };
305-
if ret != 0 {
306-
panic!("pthread_atfork failed: {ret}");
307-
}
305+
assert!((ret == 0), "pthread_atfork failed: {ret}");
308306
}

crates/fspy_preload_unix/src/client/raw_exec.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,12 @@ impl RawExec {
6666
Exec { program, args, envs }
6767
}
6868

69-
pub fn from_exec<R>(cmd: Exec, f: impl FnOnce(RawExec) -> R) -> R {
69+
pub fn from_exec<R>(cmd: Exec, f: impl FnOnce(Self) -> R) -> R {
7070
let envs: Vec<BString> = cmd
7171
.envs
7272
.into_iter()
7373
.map(|(name, value)| {
74-
let mut env = name.to_owned();
74+
let mut env = name;
7575
if let Some(value) = value {
7676
env.push(b'=');
7777
env.extend_from_slice(&value);
@@ -82,7 +82,7 @@ impl RawExec {
8282

8383
Self::to_c_str(cmd.program, |prog| {
8484
Self::to_c_str_array(cmd.args, |argv| {
85-
Self::to_c_str_array(envs, |envp| f(RawExec { prog, argv, envp }))
85+
Self::to_c_str_array(envs, |envp| f(Self { prog, argv, envp }))
8686
})
8787
})
8888
}

crates/fspy_preload_unix/src/interceptions/dirent.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ unsafe extern "C" fn scandir(
2424

2525
#[cfg(target_os = "macos")]
2626
mod macos_only {
27-
use super::*;
27+
use super::{AccessMode, c_char, c_int, c_void, handle_open, intercept};
2828
intercept!(scandir_b: unsafe extern "C" fn (
2929
dirname: *const c_char,
3030
namelist: *mut c_void,

crates/fspy_preload_unix/src/interceptions/open.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ use crate::{
99
macros::intercept,
1010
};
1111

12-
fn has_mode_arg(o_flags: c_int) -> bool {
12+
const fn has_mode_arg(o_flags: c_int) -> bool {
1313
if o_flags & libc::O_CREAT != 0 {
1414
return true;
15-
};
15+
}
1616
#[cfg(target_os = "linux")]
1717
if o_flags & libc::O_TMPFILE != 0 {
1818
return true;

0 commit comments

Comments
 (0)