Skip to content

Commit

Permalink
Miscellaneous clippy fixes. (#928)
Browse files Browse the repository at this point in the history
  • Loading branch information
sunfishcode authored Nov 13, 2023
1 parent b28c5a8 commit ee297a1
Show file tree
Hide file tree
Showing 33 changed files with 328 additions and 331 deletions.
2 changes: 1 addition & 1 deletion src/backend/libc/fs/dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,5 +393,5 @@ fn dir_iterator_handles_io_errors() {
}

assert!(matches!(dir.next(), Some(Err(_))));
assert!(matches!(dir.next(), None));
assert!(dir.next().is_none());
}
30 changes: 15 additions & 15 deletions src/backend/linux_raw/arch/x86.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,10 @@ pub(in crate::backend) unsafe fn indirect_syscall5(
// clobbered as the return value anyway.
asm!(
"push esi",
"push DWORD PTR [eax + 0]",
"mov esi, DWORD PTR [eax + 4]",
"mov eax, DWORD PTR [eax + 8]",
"call DWORD PTR [esp]",
"push [eax + 0]",
"mov esi, [eax + 4]",
"mov eax, [eax + 8]",
"call [esp]",
"pop esi",
"pop esi",
inout("eax") &[callee as _, a3.to_asm(), nr.to_asm()] => r0,
Expand Down Expand Up @@ -186,11 +186,11 @@ pub(in crate::backend) unsafe fn indirect_syscall6(
asm!(
"push ebp",
"push esi",
"push DWORD PTR [eax + 0]",
"mov esi, DWORD PTR [eax + 4]",
"mov ebp, DWORD PTR [eax + 8]",
"mov eax, DWORD PTR [eax + 12]",
"call DWORD PTR [esp]",
"push [eax + 0]",
"mov esi, [eax + 4]",
"mov ebp, [eax + 8]",
"mov eax, [eax + 12]",
"call [esp]",
"pop esi",
"pop esi",
"pop ebp",
Expand Down Expand Up @@ -441,9 +441,9 @@ pub(in crate::backend) unsafe fn syscall6(
asm!(
"push ebp",
"push esi",
"mov esi, DWORD PTR [eax + 0]",
"mov ebp, DWORD PTR [eax + 4]",
"mov eax, DWORD PTR [eax + 8]",
"mov esi, [eax + 0]",
"mov ebp, [eax + 4]",
"mov eax, [eax + 8]",
"int $$0x80",
"pop esi",
"pop ebp",
Expand Down Expand Up @@ -472,9 +472,9 @@ pub(in crate::backend) unsafe fn syscall6_readonly(
asm!(
"push ebp",
"push esi",
"mov esi, DWORD PTR [eax + 0]",
"mov ebp, DWORD PTR [eax + 4]",
"mov eax, DWORD PTR [eax + 8]",
"mov esi, [eax + 0]",
"mov ebp, [eax + 4]",
"mov eax, [eax + 8]",
"int $$0x80",
"pop esi",
"pop ebp",
Expand Down
2 changes: 1 addition & 1 deletion src/backend/linux_raw/fs/dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,5 +292,5 @@ fn dir_iterator_handles_io_errors() {
crate::io::dup2(&file_fd, &mut dir.fd).unwrap();

assert!(matches!(dir.next(), Some(Err(_))));
assert!(matches!(dir.next(), None));
assert!(dir.next().is_none());
}
2 changes: 1 addition & 1 deletion src/backend/linux_raw/param/auxv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ impl Iterator for AuxFile {
Ok(0) => panic!("unexpected end of auxv file"),
Ok(n) => slice = &mut slice[n..],
Err(crate::io::Errno::INTR) => continue,
Err(err) => Err(err).unwrap(),
Err(err) => panic!("{:?}", err),
}
}
Some(unsafe { read_unaligned(buf.as_ptr().cast()) })
Expand Down
2 changes: 1 addition & 1 deletion tests/event/eventfd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fn test_eventfd() {
Ok(efd) => efd,
#[cfg(target_os = "freebsd")]
Err(rustix::io::Errno::NOSYS) => return, // FreeBSD 12 lacks `eventfd`
Err(e) => Err(e).unwrap(),
Err(err) => panic!("{:?}", err),
};

let child = thread::spawn(move || {
Expand Down
30 changes: 15 additions & 15 deletions tests/fs/chmodat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,24 @@ fn test_chmod() {
let tmp = tempfile::tempdir().unwrap();

let _ = open(
tmp.path().join("foo"),
tmp.path().join("file"),
OFlags::CREATE | OFlags::WRONLY,
Mode::RWXU,
)
.unwrap();
symlink(tmp.path().join("foo"), tmp.path().join("link")).unwrap();
symlink(tmp.path().join("file"), tmp.path().join("link")).unwrap();

let before = stat(tmp.path().join("foo")).unwrap();
let before = stat(tmp.path().join("file")).unwrap();
assert_ne!(before.st_mode as u64 & libc::S_IRWXU as u64, 0);

chmod(tmp.path().join("foo"), Mode::empty()).unwrap();
chmod(tmp.path().join("file"), Mode::empty()).unwrap();

let after = stat(tmp.path().join("foo")).unwrap();
let after = stat(tmp.path().join("file")).unwrap();
assert_eq!(after.st_mode as u64 & libc::S_IRWXU as u64, 0);

chmod(tmp.path().join("foo"), Mode::RWXU).unwrap();
chmod(tmp.path().join("file"), Mode::RWXU).unwrap();

let reverted = stat(tmp.path().join("foo")).unwrap();
let reverted = stat(tmp.path().join("file")).unwrap();
assert_ne!(reverted.st_mode as u64 & libc::S_IRWXU as u64, 0);
}

Expand All @@ -35,25 +35,25 @@ fn test_chmodat() {
let tmp = tempfile::tempdir().unwrap();
let dir = openat(CWD, tmp.path(), OFlags::RDONLY, Mode::RWXU).unwrap();

let _ = openat(&dir, "foo", OFlags::CREATE | OFlags::WRONLY, Mode::RWXU).unwrap();
symlinkat("foo", &dir, "link").unwrap();
let _ = openat(&dir, "file", OFlags::CREATE | OFlags::WRONLY, Mode::RWXU).unwrap();
symlinkat("file", &dir, "link").unwrap();

match chmodat(&dir, "link", Mode::empty(), AtFlags::SYMLINK_NOFOLLOW) {
Ok(()) => (),
Err(rustix::io::Errno::OPNOTSUPP) => return,
Err(e) => Err(e).unwrap(),
Err(err) => panic!("{:?}", err),
}

let before = statat(&dir, "foo", AtFlags::empty()).unwrap();
let before = statat(&dir, "file", AtFlags::empty()).unwrap();
assert_ne!(before.st_mode as u64 & libc::S_IRWXU as u64, 0);

chmodat(&dir, "foo", Mode::empty(), AtFlags::empty()).unwrap();
chmodat(&dir, "file", Mode::empty(), AtFlags::empty()).unwrap();

let after = statat(&dir, "foo", AtFlags::empty()).unwrap();
let after = statat(&dir, "file", AtFlags::empty()).unwrap();
assert_eq!(after.st_mode as u64 & libc::S_IRWXU as u64, 0);

chmodat(&dir, "foo", Mode::RWXU, AtFlags::empty()).unwrap();
chmodat(&dir, "file", Mode::RWXU, AtFlags::empty()).unwrap();

let reverted = statat(&dir, "foo", AtFlags::empty()).unwrap();
let reverted = statat(&dir, "file", AtFlags::empty()).unwrap();
assert_ne!(reverted.st_mode as u64 & libc::S_IRWXU as u64, 0);
}
4 changes: 2 additions & 2 deletions tests/fs/dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ fn dir_iterator_handles_dir_removal() {
drop(tmp);

let mut dir = rustix::fs::Dir::read_from(&fd).unwrap();
assert!(matches!(dir.next(), None));
assert!(dir.next().is_none());
}

// Like `dir_iterator_handles_dir_removal`, but close the directory after
Expand All @@ -105,5 +105,5 @@ fn dir_iterator_handles_dir_removal_after_open() {
// Drop the `TempDir`, which deletes the directory.
drop(tmp);

assert!(matches!(dir.next(), None));
assert!(dir.next().is_none());
}
14 changes: 7 additions & 7 deletions tests/fs/fcntl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ fn test_fcntl_apple() {

let tmp = tempfile::tempdir().unwrap();
let dir = openat(CWD, tmp.path(), OFlags::RDONLY, Mode::empty()).unwrap();
let foo = openat(
let file = openat(
&dir,
"foo",
"file",
OFlags::RDWR | OFlags::CREATE | OFlags::TRUNC,
Mode::RUSR | Mode::WUSR,
)
Expand All @@ -34,13 +34,13 @@ fn test_fcntl_apple() {
// It appears `fsync_rdadvise` at offset 0 length 0 doesn't work if the
// file has size zero, so write in some bytes.
assert_eq!(
rustix::io::write(&foo, b"data").expect("write"),
rustix::io::write(&file, b"data").expect("write"),
4,
"write failed"
);

rustix::fs::fcntl_rdadvise(&foo, 0, 0).unwrap();
rustix::fs::fcntl_fullfsync(&foo).unwrap();
rustix::fs::fcntl_nocache(&foo, true).unwrap();
rustix::fs::fcntl_global_nocache(&foo, true).unwrap();
rustix::fs::fcntl_rdadvise(&file, 0, 0).unwrap();
rustix::fs::fcntl_fullfsync(&file).unwrap();
rustix::fs::fcntl_nocache(&file, true).unwrap();
rustix::fs::fcntl_global_nocache(&file, true).unwrap();
}
2 changes: 1 addition & 1 deletion tests/fs/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fn test_file() {
)
}
}
Err(err) => Err(err).unwrap(),
Err(err) => panic!("{:?}", err),
}

// Check that `SYMLINK_FOLLOW` is rejected. Except on NetBSD which seems
Expand Down
8 changes: 4 additions & 4 deletions tests/fs/futimens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ fn test_futimens() {
let tmp = tempfile::tempdir().unwrap();
let dir = openat(CWD, tmp.path(), OFlags::RDONLY, Mode::empty()).unwrap();

let foo = openat(
let file = openat(
&dir,
"foo",
"file",
OFlags::CREATE | OFlags::WRONLY | OFlags::CLOEXEC,
Mode::empty(),
)
Expand All @@ -24,9 +24,9 @@ fn test_futimens() {
tv_nsec: 47000,
},
};
futimens(&foo, &times).unwrap();
futimens(&file, &times).unwrap();

let after = fstat(&foo).unwrap();
let after = fstat(&file).unwrap();

assert_eq!(times.last_modification.tv_sec as u64, after.st_mtime as u64);
#[cfg(not(target_os = "netbsd"))]
Expand Down
30 changes: 15 additions & 15 deletions tests/fs/invalid_offset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fn invalid_offset_seek() {
let dir = openat(CWD, tmp.path(), OFlags::RDONLY, Mode::empty()).unwrap();
let file = openat(
&dir,
"foo",
"file",
OFlags::WRONLY | OFlags::TRUNC | OFlags::CREATE,
Mode::RUSR | Mode::WUSR,
)
Expand Down Expand Up @@ -46,7 +46,7 @@ fn invalid_offset_fallocate() {
let dir = openat(CWD, tmp.path(), OFlags::RDONLY, Mode::empty()).unwrap();
let file = openat(
&dir,
"foo",
"file",
OFlags::WRONLY | OFlags::TRUNC | OFlags::CREATE,
Mode::RUSR | Mode::WUSR,
)
Expand All @@ -73,7 +73,7 @@ fn invalid_offset_fadvise() {
let dir = openat(CWD, tmp.path(), OFlags::RDONLY, Mode::empty()).unwrap();
let file = openat(
&dir,
"foo",
"file",
OFlags::WRONLY | OFlags::TRUNC | OFlags::CREATE,
Mode::RUSR | Mode::WUSR,
)
Expand Down Expand Up @@ -105,7 +105,7 @@ fn invalid_offset_pread() {
let dir = openat(CWD, tmp.path(), OFlags::RDONLY, Mode::empty()).unwrap();
let file = openat(
&dir,
"foo",
"file",
OFlags::RDWR | OFlags::TRUNC | OFlags::CREATE,
Mode::RUSR | Mode::WUSR,
)
Expand All @@ -125,7 +125,7 @@ fn invalid_offset_pwrite() {
let dir = openat(CWD, tmp.path(), OFlags::RDONLY, Mode::empty()).unwrap();
let file = openat(
&dir,
"foo",
"file",
OFlags::WRONLY | OFlags::TRUNC | OFlags::CREATE,
Mode::RUSR | Mode::WUSR,
)
Expand All @@ -143,39 +143,39 @@ fn invalid_offset_copy_file_range() {
use rustix::io::write;
let tmp = tempfile::tempdir().unwrap();
let dir = openat(CWD, tmp.path(), OFlags::RDONLY, Mode::empty()).unwrap();
let foo = openat(
let src = openat(
&dir,
"foo",
"src",
OFlags::RDWR | OFlags::TRUNC | OFlags::CREATE,
Mode::RUSR | Mode::WUSR,
)
.unwrap();
let bar = openat(
let dst = openat(
&dir,
"bar",
"dst",
OFlags::WRONLY | OFlags::TRUNC | OFlags::CREATE,
Mode::RUSR | Mode::WUSR,
)
.unwrap();
write(&foo, b"a").unwrap();
write(&src, b"a").unwrap();

let mut off_in = u64::MAX;
let mut off_out = 0;
copy_file_range(&foo, Some(&mut off_in), &bar, Some(&mut off_out), 1).unwrap_err();
copy_file_range(&src, Some(&mut off_in), &dst, Some(&mut off_out), 1).unwrap_err();

let mut off_in = i64::MAX as u64 + 1;
let mut off_out = 0;
copy_file_range(&foo, Some(&mut off_in), &bar, Some(&mut off_out), 1).unwrap_err();
copy_file_range(&src, Some(&mut off_in), &dst, Some(&mut off_out), 1).unwrap_err();

let mut off_in = 0;
let mut off_out = u64::MAX;
copy_file_range(&foo, Some(&mut off_in), &bar, Some(&mut off_out), 1).unwrap_err();
copy_file_range(&src, Some(&mut off_in), &dst, Some(&mut off_out), 1).unwrap_err();

let mut off_in = 0;
let mut off_out = i64::MAX as u64;
copy_file_range(&foo, Some(&mut off_in), &bar, Some(&mut off_out), 1).unwrap_err();
copy_file_range(&src, Some(&mut off_in), &dst, Some(&mut off_out), 1).unwrap_err();

let mut off_in = 0;
let mut off_out = i64::MAX as u64 + 1;
copy_file_range(&foo, Some(&mut off_in), &bar, Some(&mut off_out), 1).unwrap_err();
copy_file_range(&src, Some(&mut off_in), &dst, Some(&mut off_out), 1).unwrap_err();
}
2 changes: 1 addition & 1 deletion tests/fs/ioctl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ fn test_ioctl_ficlone() {
match rustix::fs::ioctl_ficlone(&dest, &src) {
Ok(()) | Err(io::Errno::OPNOTSUPP) => (),
Err(e) if e == io::Errno::from_raw_os_error(0x12) => (),
Err(err) => Err(err).unwrap(),
Err(err) => panic!("{:?}", err),
}
}
20 changes: 10 additions & 10 deletions tests/fs/linkat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,26 @@ fn test_link() {
let tmp = tempfile::tempdir().unwrap();

let _ = open(
tmp.path().join("foo"),
tmp.path().join("file"),
OFlags::CREATE | OFlags::WRONLY,
Mode::RUSR,
)
.unwrap();

link(tmp.path().join("foo"), tmp.path().join("link")).unwrap();
link(tmp.path().join("file"), tmp.path().join("link")).unwrap();

readlink(tmp.path().join("foo"), Vec::new()).unwrap_err();
readlink(tmp.path().join("file"), Vec::new()).unwrap_err();
readlink(tmp.path().join("link"), Vec::new()).unwrap_err();

assert_eq!(
stat(tmp.path().join("foo")).unwrap().st_ino,
stat(tmp.path().join("file")).unwrap().st_ino,
stat(tmp.path().join("link")).unwrap().st_ino
);

link(tmp.path().join("link"), tmp.path().join("another")).unwrap();

assert_eq!(
stat(tmp.path().join("foo")).unwrap().st_ino,
stat(tmp.path().join("file")).unwrap().st_ino,
stat(tmp.path().join("another")).unwrap().st_ino
);
}
Expand All @@ -37,22 +37,22 @@ fn test_linkat() {
let tmp = tempfile::tempdir().unwrap();
let dir = openat(CWD, tmp.path(), OFlags::RDONLY, Mode::empty()).unwrap();

let _ = openat(&dir, "foo", OFlags::CREATE | OFlags::WRONLY, Mode::RUSR).unwrap();
let _ = openat(&dir, "file", OFlags::CREATE | OFlags::WRONLY, Mode::RUSR).unwrap();

linkat(&dir, "foo", &dir, "link", AtFlags::empty()).unwrap();
linkat(&dir, "file", &dir, "link", AtFlags::empty()).unwrap();

readlinkat(&dir, "foo", Vec::new()).unwrap_err();
readlinkat(&dir, "file", Vec::new()).unwrap_err();
readlinkat(&dir, "link", Vec::new()).unwrap_err();

assert_eq!(
statat(&dir, "foo", AtFlags::empty()).unwrap().st_ino,
statat(&dir, "file", AtFlags::empty()).unwrap().st_ino,
statat(&dir, "link", AtFlags::empty()).unwrap().st_ino
);

linkat(&dir, "link", &dir, "another", AtFlags::empty()).unwrap();

assert_eq!(
statat(&dir, "foo", AtFlags::empty()).unwrap().st_ino,
statat(&dir, "file", AtFlags::empty()).unwrap().st_ino,
statat(&dir, "another", AtFlags::empty()).unwrap().st_ino
);
}
Loading

0 comments on commit ee297a1

Please sign in to comment.