summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlan Somers <asomers@gmail.com>2021-05-30 12:27:39 -0600
committerAlan Somers <asomers@gmail.com>2021-05-30 20:12:41 -0600
commit7b7d9540056f6378820caf955a0335268184d6b7 (patch)
treef27fa7b8dbb4d089c0f7bda9569bfab8ead1b4dc /src
parenta55dd4537286c8fbd96e3e21e18c56a38f8124b9 (diff)
downloadnix-7b7d9540056f6378820caf955a0335268184d6b7.zip
misc Clippy cleanup
* Fix race conditions in the tests. Two tests were grabbing a mutex but immediately dropping it. Thank you, Clippy. * Remove vestigial Windows support. Remove some code added to support Windows in 2015. Nix is no longer intended to ever run on Windows. * Various other minor Clippy lints.
Diffstat (limited to 'src')
-rw-r--r--src/errno.rs2
-rw-r--r--src/fcntl.rs6
-rw-r--r--src/sys/aio.rs8
-rw-r--r--src/sys/ptrace/bsd.rs16
-rw-r--r--src/sys/select.rs2
-rw-r--r--src/sys/socket/mod.rs2
-rw-r--r--src/time.rs6
-rw-r--r--src/unistd.rs54
8 files changed, 44 insertions, 52 deletions
diff --git a/src/errno.rs b/src/errno.rs
index 0e8839e6..9275febe 100644
--- a/src/errno.rs
+++ b/src/errno.rs
@@ -94,7 +94,7 @@ impl ErrnoSentinel for i64 {
}
impl ErrnoSentinel for *mut c_void {
- fn sentinel() -> Self { (-1 as isize) as *mut c_void }
+ fn sentinel() -> Self { -1isize as *mut c_void }
}
impl ErrnoSentinel for libc::sighandler_t {
diff --git a/src/fcntl.rs b/src/fcntl.rs
index 2532724b..ce30b7d1 100644
--- a/src/fcntl.rs
+++ b/src/fcntl.rs
@@ -166,7 +166,7 @@ libc_bitflags!(
);
// The conversion is not identical on all operating systems.
-#[allow(clippy::identity_conversion)]
+#[allow(clippy::useless_conversion)]
pub fn open<P: ?Sized + NixPath>(path: &P, oflag: OFlag, mode: Mode) -> Result<RawFd> {
let fd = path.with_nix_path(|cstr| {
unsafe { libc::open(cstr.as_ptr(), oflag.bits(), mode.bits() as c_uint) }
@@ -176,7 +176,7 @@ pub fn open<P: ?Sized + NixPath>(path: &P, oflag: OFlag, mode: Mode) -> Result<R
}
// The conversion is not identical on all operating systems.
-#[allow(clippy::identity_conversion)]
+#[allow(clippy::useless_conversion)]
#[cfg(not(target_os = "redox"))]
pub fn openat<P: ?Sized + NixPath>(
dirfd: RawFd,
@@ -264,7 +264,7 @@ fn inner_readlink<P: ?Sized + NixPath>(dirfd: Option<RawFd>, path: &P) -> Result
Some(dirfd) => super::sys::stat::fstatat(dirfd, path, AtFlags::AT_SYMLINK_NOFOLLOW),
None => super::sys::stat::lstat(path)
}
- .and_then(|x| Ok(x.st_size))
+ .map(|x| x.st_size)
.unwrap_or(0);
let mut try_size = if reported_size > 0 {
// Note: even if `lstat`'s apparently valid answer turns out to be
diff --git a/src/sys/aio.rs b/src/sys/aio.rs
index 7868a294..a03caa45 100644
--- a/src/sys/aio.rs
+++ b/src/sys/aio.rs
@@ -513,7 +513,7 @@ impl<'a> AioCb<'a> {
}
}
- fn error_unpinned(self: &mut Self) -> Result<()> {
+ fn error_unpinned(&mut self) -> Result<()> {
let r = unsafe {
libc::aio_error(&mut self.aiocb.0 as *mut libc::aiocb)
};
@@ -645,7 +645,7 @@ impl<'a> AioCb<'a> {
SigEvent::from(&self.aiocb.0.aio_sigevent)
}
- fn aio_return_unpinned(self: &mut Self) -> Result<isize> {
+ fn aio_return_unpinned(&mut self) -> Result<isize> {
unsafe {
let p: *mut libc::aiocb = &mut self.aiocb.0;
self.in_progress = false;
@@ -838,6 +838,10 @@ unsafe impl<'a> Sync for LioCb<'a> {}
#[cfg(not(any(target_os = "ios", target_os = "macos")))]
impl<'a> LioCb<'a> {
+ pub fn is_empty(&self) -> bool {
+ self.aiocbs.is_empty()
+ }
+
/// Return the number of individual [`AioCb`]s contained.
pub fn len(&self) -> usize {
self.aiocbs.len()
diff --git a/src/sys/ptrace/bsd.rs b/src/sys/ptrace/bsd.rs
index e85afc76..141dfbc4 100644
--- a/src/sys/ptrace/bsd.rs
+++ b/src/sys/ptrace/bsd.rs
@@ -133,16 +133,14 @@ pub fn kill(pid: Pid) -> Result<()> {
/// use nix::unistd::Pid;
/// use nix::sys::signal::Signal;
/// use nix::sys::wait::*;
-/// fn main() {
-/// // If a process changes state to the stopped state because of a SIGUSR1
-/// // signal, this will step the process forward and forward the user
-/// // signal to the stopped process
-/// match waitpid(Pid::from_raw(-1), None) {
-/// Ok(WaitStatus::Stopped(pid, Signal::SIGUSR1)) => {
-/// let _ = step(pid, Signal::SIGUSR1);
-/// }
-/// _ => {},
+/// // If a process changes state to the stopped state because of a SIGUSR1
+/// // signal, this will step the process forward and forward the user
+/// // signal to the stopped process
+/// match waitpid(Pid::from_raw(-1), None) {
+/// Ok(WaitStatus::Stopped(pid, Signal::SIGUSR1)) => {
+/// let _ = step(pid, Signal::SIGUSR1);
/// }
+/// _ => {},
/// }
/// ```
#[cfg(
diff --git a/src/sys/select.rs b/src/sys/select.rs
index 19ae2f1c..5eb64234 100644
--- a/src/sys/select.rs
+++ b/src/sys/select.rs
@@ -50,12 +50,10 @@ impl FdSet {
///
/// ```
/// # use nix::sys::select::FdSet;
- /// # fn main() {
/// let mut set = FdSet::new();
/// set.insert(4);
/// set.insert(9);
/// assert_eq!(set.highest(), Some(9));
- /// # }
/// ```
///
/// [`select`]: fn.select.html
diff --git a/src/sys/socket/mod.rs b/src/sys/socket/mod.rs
index e4baeb5d..69070463 100644
--- a/src/sys/socket/mod.rs
+++ b/src/sys/socket/mod.rs
@@ -710,7 +710,7 @@ impl ControlMessageOwned {
},
(_, _) => {
let sl = slice::from_raw_parts(p, len);
- let ucmsg = UnknownCmsg(*header, Vec::<u8>::from(&sl[..]));
+ let ucmsg = UnknownCmsg(*header, Vec::<u8>::from(sl));
ControlMessageOwned::Unknown(ucmsg)
}
}
diff --git a/src/time.rs b/src/time.rs
index e6c3f8de..f7da654a 100644
--- a/src/time.rs
+++ b/src/time.rs
@@ -185,9 +185,9 @@ impl ClockId {
pub const CLOCK_VIRTUAL: ClockId = ClockId(libc::CLOCK_VIRTUAL);
}
-impl Into<clockid_t> for ClockId {
- fn into(self) -> clockid_t {
- self.as_raw()
+impl From<ClockId> for clockid_t {
+ fn from(clock_id: ClockId) -> Self {
+ clock_id.as_raw()
}
}
diff --git a/src/unistd.rs b/src/unistd.rs
index 11907fa9..8e361bad 100644
--- a/src/unistd.rs
+++ b/src/unistd.rs
@@ -450,15 +450,13 @@ pub fn fchdir(dirfd: RawFd) -> Result<()> {
/// use nix::sys::stat;
/// use tempfile::tempdir;
///
-/// fn main() {
-/// let tmp_dir1 = tempdir().unwrap();
-/// let tmp_dir2 = tmp_dir1.path().join("new_dir");
-///
-/// // create new directory and give read, write and execute rights to the owner
-/// match unistd::mkdir(&tmp_dir2, stat::Mode::S_IRWXU) {
-/// Ok(_) => println!("created {:?}", tmp_dir2),
-/// Err(err) => println!("Error creating directory: {}", err),
-/// }
+/// let tmp_dir1 = tempdir().unwrap();
+/// let tmp_dir2 = tmp_dir1.path().join("new_dir");
+///
+/// // create new directory and give read, write and execute rights to the owner
+/// match unistd::mkdir(&tmp_dir2, stat::Mode::S_IRWXU) {
+/// Ok(_) => println!("created {:?}", tmp_dir2),
+/// Err(err) => println!("Error creating directory: {}", err),
/// }
/// ```
#[inline]
@@ -490,15 +488,13 @@ pub fn mkdir<P: ?Sized + NixPath>(path: &P, mode: Mode) -> Result<()> {
/// use nix::sys::stat;
/// use tempfile::tempdir;
///
-/// fn main() {
-/// let tmp_dir = tempdir().unwrap();
-/// let fifo_path = tmp_dir.path().join("foo.pipe");
+/// let tmp_dir = tempdir().unwrap();
+/// let fifo_path = tmp_dir.path().join("foo.pipe");
///
-/// // create new fifo and give read, write and execute rights to the owner
-/// match unistd::mkfifo(&fifo_path, stat::Mode::S_IRWXU) {
-/// Ok(_) => println!("created {:?}", fifo_path),
-/// Err(err) => println!("Error creating fifo: {}", err),
-/// }
+/// // create new fifo and give read, write and execute rights to the owner
+/// match unistd::mkfifo(&fifo_path, stat::Mode::S_IRWXU) {
+/// Ok(_) => println!("created {:?}", fifo_path),
+/// Err(err) => println!("Error creating fifo: {}", err),
/// }
/// ```
#[inline]
@@ -587,11 +583,9 @@ fn reserve_double_buffer_size<T>(buf: &mut Vec<T>, limit: usize) -> Result<()> {
/// ```rust
/// use nix::unistd;
///
-/// fn main() {
-/// // assume that we are allowed to get current directory
-/// let dir = unistd::getcwd().unwrap();
-/// println!("The current directory is {:?}", dir);
-/// }
+/// // assume that we are allowed to get current directory
+/// let dir = unistd::getcwd().unwrap();
+/// println!("The current directory is {:?}", dir);
/// ```
#[inline]
pub fn getcwd() -> Result<PathBuf> {
@@ -624,6 +618,8 @@ pub fn getcwd() -> Result<PathBuf> {
}
/// Computes the raw UID and GID values to pass to a `*chown` call.
+// The cast is not unnecessary on all platforms.
+#[allow(clippy::unnecessary_cast)]
fn chown_raw_ids(owner: Option<Uid>, group: Option<Gid>) -> (libc::uid_t, libc::gid_t) {
// According to the POSIX specification, -1 is used to indicate that owner and group
// are not to be changed. Since uid_t and gid_t are unsigned types, we have to wrap
@@ -969,20 +965,16 @@ pub fn gethostname(buffer: &mut [u8]) -> Result<&CStr> {
/// use std::os::unix::io::AsRawFd;
/// use nix::unistd::close;
///
-/// fn main() {
-/// let f = tempfile::tempfile().unwrap();
-/// close(f.as_raw_fd()).unwrap(); // Bad! f will also close on drop!
-/// }
+/// let f = tempfile::tempfile().unwrap();
+/// close(f.as_raw_fd()).unwrap(); // Bad! f will also close on drop!
/// ```
///
/// ```rust
/// use std::os::unix::io::IntoRawFd;
/// use nix::unistd::close;
///
-/// fn main() {
-/// let f = tempfile::tempfile().unwrap();
-/// close(f.into_raw_fd()).unwrap(); // Good. into_raw_fd consumes f
-/// }
+/// let f = tempfile::tempfile().unwrap();
+/// close(f.into_raw_fd()).unwrap(); // Good. into_raw_fd consumes f
/// ```
pub fn close(fd: RawFd) -> Result<()> {
let res = unsafe { libc::close(fd) };
@@ -1563,7 +1555,7 @@ pub fn getgrouplist(user: &CStr, group: Gid) -> Result<Vec<Gid>> {
// groups as possible, but Linux manpages do not mention this
// behavior.
reserve_double_buffer_size(&mut groups, ngroups_max as usize)
- .or_else(|_| Err(Error::invalid_argument()))?;
+ .map_err(|_| Error::invalid_argument())?;
}
}
}