Skip to content

Clippy cleanup #1529

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ build: &BUILD
- . $HOME/.cargo/env || true
- $TOOL +$TOOLCHAIN $BUILD $ZFLAGS --target $TARGET --all-targets
- $TOOL +$TOOLCHAIN doc $ZFLAGS --no-deps --target $TARGET
- $TOOL +$TOOLCHAIN clippy $ZFLAGS --target $TARGET -- -D warnings

# Tests that do require executing the binaries
test: &TEST
Expand All @@ -39,7 +40,9 @@ task:
setup_script:
- fetch https://sh.rustup.rs -o rustup.sh
- sh rustup.sh -y --profile=minimal --default-toolchain $TOOLCHAIN
- $HOME/.cargo/bin/rustup target add i686-unknown-freebsd
- . $HOME/.cargo/env
- rustup target add i686-unknown-freebsd
- rustup component add --toolchain $TOOLCHAIN clippy
<< : *TEST
i386_test_script:
- . $HOME/.cargo/env
Expand All @@ -60,6 +63,7 @@ task:
- curl --proto '=https' --tlsv1.2 -sSf -o rustup.sh https://sh.rustup.rs
- sh rustup.sh -y --profile=minimal --default-toolchain $TOOLCHAIN
- . $HOME/.cargo/env
- rustup component add --toolchain $TOOLCHAIN clippy
<< : *TEST
before_cache_script: rm -rf $CARGO_HOME/registry/index

Expand Down Expand Up @@ -142,6 +146,7 @@ task:
TARGET: x86_64-unknown-linux-musl
setup_script:
- rustup target add $TARGET
- rustup component add clippy
<< : *TEST
before_cache_script: rm -rf $CARGO_HOME/registry/index

Expand Down Expand Up @@ -224,6 +229,7 @@ task:
setup_script:
- rustup target add $TARGET
- rustup toolchain install $TOOLCHAIN --profile minimal --target $TARGET
- rustup component add --toolchain $TOOLCHAIN clippy
<< : *BUILD
before_cache_script: rm -rf $CARGO_HOME/registry/index

Expand Down
3 changes: 2 additions & 1 deletion src/dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl AsRawFd for Dir {
impl Drop for Dir {
fn drop(&mut self) {
let e = Errno::result(unsafe { libc::closedir(self.0.as_ptr()) });
if !std::thread::panicking() && e == Err(Error::from(Errno::EBADF)) {
if !std::thread::panicking() && e == Err(Errno::EBADF) {
panic!("Closing an invalid file descriptor!");
};
}
Expand Down Expand Up @@ -211,6 +211,7 @@ impl Entry {
target_os = "linux",
target_os = "macos",
target_os = "solaris")))]
#[allow(clippy::useless_conversion)] // Not useless on all OSes
pub fn ino(&self) -> u64 {
u64::from(self.0.d_fileno)
}
Expand Down
3 changes: 2 additions & 1 deletion src/errno.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@ impl Errno {
since = "0.22.0",
note = "It's a no-op now; just delete it."
)]
#[allow(clippy::wrong_self_convention)] // False positive
pub fn from_errno(errno: Errno) -> Error {
Error::from(errno)
errno
}

/// Create a new invalid argument error (`EINVAL`)
Expand Down
5 changes: 2 additions & 3 deletions src/fcntl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ fn inner_readlink<P: ?Sized + NixPath>(dirfd: Option<RawFd>, path: &P) -> Result
Some(next_size) => try_size = next_size,
// It's absurd that this would happen, but handle it sanely
// anyway.
None => break Err(super::Error::from(Errno::ENAMETOOLONG)),
None => break Err(Errno::ENAMETOOLONG),
}
}
}
Expand Down Expand Up @@ -646,7 +646,6 @@ pub fn fallocate(
))]
mod posix_fadvise {
use crate::errno::Errno;
use libc;
use std::os::unix::io::RawFd;
use crate::Result;

Expand Down Expand Up @@ -687,6 +686,6 @@ pub fn posix_fallocate(fd: RawFd, offset: libc::off_t, len: libc::off_t) -> Resu
match Errno::result(res) {
Err(err) => Err(err),
Ok(0) => Ok(()),
Ok(errno) => Err(crate::Error::from(Errno::from_i32(errno))),
Ok(errno) => Err(Errno::from_i32(errno)),
}
}
1 change: 0 additions & 1 deletion src/kmod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
//!
//! For more details see

use libc;
use std::ffi::CStr;
use std::os::unix::io::AsRawFd;

Expand Down
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ impl NixPath for CStr {
where F: FnOnce(&CStr) -> T {
// Equivalence with the [u8] impl.
if self.len() >= PATH_MAX as usize {
return Err(Error::from(Errno::ENAMETOOLONG))
return Err(Errno::ENAMETOOLONG)
}

Ok(f(self))
Expand All @@ -181,11 +181,11 @@ impl NixPath for [u8] {
let mut buf = [0u8; PATH_MAX as usize];

if self.len() >= PATH_MAX as usize {
return Err(Error::from(Errno::ENAMETOOLONG))
return Err(Errno::ENAMETOOLONG)
}

match self.iter().position(|b| *b == 0) {
Some(_) => Err(Error::from(Errno::EINVAL)),
Some(_) => Err(Errno::EINVAL),
None => {
unsafe {
// TODO: Replace with bytes::copy_memory. rust-lang/rust#24028
Expand Down
2 changes: 1 addition & 1 deletion src/mount/bsd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ impl<'a> Nmount<'a> {
Some(CStr::from_bytes_with_nul(sl).unwrap())
}
};
Err(NmountError::new(error.into(), errmsg))
Err(NmountError::new(error, errmsg))
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/mount/linux.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![allow(missing_docs)]
use libc::{self, c_ulong, c_int};
use crate::{Result, NixPath};
use crate::errno::Errno;
Expand Down
2 changes: 0 additions & 2 deletions src/mount/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
//! Mount file systems
#[cfg(any(target_os = "android", target_os = "linux"))]
#[allow(missing_docs)]
mod linux;

#[cfg(any(target_os = "android", target_os = "linux"))]
#[allow(missing_docs)]
pub use self::linux::*;

#[cfg(any(target_os = "dragonfly",
Expand Down
1 change: 1 addition & 0 deletions src/mqueue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ pub fn mq_setattr(mqd: mqd_t, newattr: &MqAttr) -> Result<MqAttr> {
/// Convenience function.
/// Sets the `O_NONBLOCK` attribute for a given message queue descriptor
/// Returns the old attributes
#[allow(clippy::useless_conversion)] // Not useless on all OSes
pub fn mq_set_nonblock(mqd: mqd_t) -> Result<MqAttr> {
let oldattr = mq_getattr(mqd)?;
let newattr = MqAttr::new(mq_attr_member_t::from(MQ_OFlag::O_NONBLOCK.bits()),
Expand Down
12 changes: 6 additions & 6 deletions src/pty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::os::unix::prelude::*;

use crate::sys::termios::Termios;
use crate::unistd::{self, ForkResult, Pid};
use crate::{Result, Error, fcntl};
use crate::{Result, fcntl};
use crate::errno::Errno;

/// Representation of a master/slave pty pair
Expand Down Expand Up @@ -99,7 +99,7 @@ impl io::Write for PtyMaster {
#[inline]
pub fn grantpt(fd: &PtyMaster) -> Result<()> {
if unsafe { libc::grantpt(fd.as_raw_fd()) } < 0 {
return Err(Error::from(Errno::last()));
return Err(Errno::last());
}

Ok(())
Expand Down Expand Up @@ -145,7 +145,7 @@ pub fn posix_openpt(flags: fcntl::OFlag) -> Result<PtyMaster> {
};

if fd < 0 {
return Err(Error::from(Errno::last()));
return Err(Errno::last());
}

Ok(PtyMaster(fd))
Expand All @@ -171,7 +171,7 @@ pub fn posix_openpt(flags: fcntl::OFlag) -> Result<PtyMaster> {
pub unsafe fn ptsname(fd: &PtyMaster) -> Result<String> {
let name_ptr = libc::ptsname(fd.as_raw_fd());
if name_ptr.is_null() {
return Err(Error::from(Errno::last()));
return Err(Errno::last());
}

let name = CStr::from_ptr(name_ptr);
Expand All @@ -195,7 +195,7 @@ pub fn ptsname_r(fd: &PtyMaster) -> Result<String> {
let cname = unsafe {
let cap = name_buf.capacity();
if libc::ptsname_r(fd.as_raw_fd(), name_buf_ptr, cap) != 0 {
return Err(Error::last());
return Err(crate::Error::last());
}
CStr::from_ptr(name_buf.as_ptr())
};
Expand All @@ -213,7 +213,7 @@ pub fn ptsname_r(fd: &PtyMaster) -> Result<String> {
#[inline]
pub fn unlockpt(fd: &PtyMaster) -> Result<()> {
if unsafe { libc::unlockpt(fd.as_raw_fd()) } < 0 {
return Err(Error::from(Errno::last()));
return Err(Errno::last());
}

Ok(())
Expand Down
8 changes: 4 additions & 4 deletions src/sched.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ mod sched_linux_like {
use std::option::Option;
use std::os::unix::io::RawFd;
use crate::unistd::Pid;
use crate::{Error, Result};
use crate::Result;

// For some functions taking with a parameter of type CloneFlags,
// only a subset of these flags have an effect.
Expand Down Expand Up @@ -109,7 +109,7 @@ mod sched_linux_like {
/// `field` is the CPU id to test
pub fn is_set(&self, field: usize) -> Result<bool> {
if field >= CpuSet::count() {
Err(Error::from(Errno::EINVAL))
Err(Errno::EINVAL)
} else {
Ok(unsafe { libc::CPU_ISSET(field, &self.cpu_set) })
}
Expand All @@ -119,7 +119,7 @@ mod sched_linux_like {
/// `field` is the CPU id to add
pub fn set(&mut self, field: usize) -> Result<()> {
if field >= CpuSet::count() {
Err(Error::from(Errno::EINVAL))
Err(Errno::EINVAL)
} else {
unsafe { libc::CPU_SET(field, &mut self.cpu_set); }
Ok(())
Expand All @@ -130,7 +130,7 @@ mod sched_linux_like {
/// `field` is the CPU id to remove
pub fn unset(&mut self, field: usize) -> Result<()> {
if field >= CpuSet::count() {
Err(Error::from(Errno::EINVAL))
Err(Errno::EINVAL)
} else {
unsafe { libc::CPU_CLR(field, &mut self.cpu_set);}
Ok(())
Expand Down
Loading