Skip to content

Commit 515e99b

Browse files
authored
Merge pull request #1529 from asomers/clippy-9-2021
Clippy cleanup
2 parents f0d6d04 + a09b1c8 commit 515e99b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+154
-189
lines changed

.cirrus.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ build: &BUILD
1818
- . $HOME/.cargo/env || true
1919
- $TOOL +$TOOLCHAIN $BUILD $ZFLAGS --target $TARGET --all-targets
2020
- $TOOL +$TOOLCHAIN doc $ZFLAGS --no-deps --target $TARGET
21+
- $TOOL +$TOOLCHAIN clippy $ZFLAGS --target $TARGET -- -D warnings
2122

2223
# Tests that do require executing the binaries
2324
test: &TEST
@@ -39,7 +40,9 @@ task:
3940
setup_script:
4041
- fetch https://sh.rustup.rs -o rustup.sh
4142
- sh rustup.sh -y --profile=minimal --default-toolchain $TOOLCHAIN
42-
- $HOME/.cargo/bin/rustup target add i686-unknown-freebsd
43+
- . $HOME/.cargo/env
44+
- rustup target add i686-unknown-freebsd
45+
- rustup component add --toolchain $TOOLCHAIN clippy
4346
<< : *TEST
4447
i386_test_script:
4548
- . $HOME/.cargo/env
@@ -60,6 +63,7 @@ task:
6063
- curl --proto '=https' --tlsv1.2 -sSf -o rustup.sh https://sh.rustup.rs
6164
- sh rustup.sh -y --profile=minimal --default-toolchain $TOOLCHAIN
6265
- . $HOME/.cargo/env
66+
- rustup component add --toolchain $TOOLCHAIN clippy
6367
<< : *TEST
6468
before_cache_script: rm -rf $CARGO_HOME/registry/index
6569

@@ -142,6 +146,7 @@ task:
142146
TARGET: x86_64-unknown-linux-musl
143147
setup_script:
144148
- rustup target add $TARGET
149+
- rustup component add clippy
145150
<< : *TEST
146151
before_cache_script: rm -rf $CARGO_HOME/registry/index
147152

@@ -224,6 +229,7 @@ task:
224229
setup_script:
225230
- rustup target add $TARGET
226231
- rustup toolchain install $TOOLCHAIN --profile minimal --target $TARGET
232+
- rustup component add --toolchain $TOOLCHAIN clippy
227233
<< : *BUILD
228234
before_cache_script: rm -rf $CARGO_HOME/registry/index
229235

src/dir.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ impl AsRawFd for Dir {
8484
impl Drop for Dir {
8585
fn drop(&mut self) {
8686
let e = Errno::result(unsafe { libc::closedir(self.0.as_ptr()) });
87-
if !std::thread::panicking() && e == Err(Error::from(Errno::EBADF)) {
87+
if !std::thread::panicking() && e == Err(Errno::EBADF) {
8888
panic!("Closing an invalid file descriptor!");
8989
};
9090
}
@@ -211,6 +211,7 @@ impl Entry {
211211
target_os = "linux",
212212
target_os = "macos",
213213
target_os = "solaris")))]
214+
#[allow(clippy::useless_conversion)] // Not useless on all OSes
214215
pub fn ino(&self) -> u64 {
215216
u64::from(self.0.d_fileno)
216217
}

src/errno.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,9 @@ impl Errno {
7272
since = "0.22.0",
7373
note = "It's a no-op now; just delete it."
7474
)]
75+
#[allow(clippy::wrong_self_convention)] // False positive
7576
pub fn from_errno(errno: Errno) -> Error {
76-
Error::from(errno)
77+
errno
7778
}
7879

7980
/// Create a new invalid argument error (`EINVAL`)

src/fcntl.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ fn inner_readlink<P: ?Sized + NixPath>(dirfd: Option<RawFd>, path: &P) -> Result
325325
Some(next_size) => try_size = next_size,
326326
// It's absurd that this would happen, but handle it sanely
327327
// anyway.
328-
None => break Err(super::Error::from(Errno::ENAMETOOLONG)),
328+
None => break Err(Errno::ENAMETOOLONG),
329329
}
330330
}
331331
}
@@ -646,7 +646,6 @@ pub fn fallocate(
646646
))]
647647
mod posix_fadvise {
648648
use crate::errno::Errno;
649-
use libc;
650649
use std::os::unix::io::RawFd;
651650
use crate::Result;
652651

@@ -687,6 +686,6 @@ pub fn posix_fallocate(fd: RawFd, offset: libc::off_t, len: libc::off_t) -> Resu
687686
match Errno::result(res) {
688687
Err(err) => Err(err),
689688
Ok(0) => Ok(()),
690-
Ok(errno) => Err(crate::Error::from(Errno::from_i32(errno))),
689+
Ok(errno) => Err(Errno::from_i32(errno)),
691690
}
692691
}

src/kmod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
//!
33
//! For more details see
44
5-
use libc;
65
use std::ffi::CStr;
76
use std::os::unix::io::AsRawFd;
87

src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ impl NixPath for CStr {
160160
where F: FnOnce(&CStr) -> T {
161161
// Equivalence with the [u8] impl.
162162
if self.len() >= PATH_MAX as usize {
163-
return Err(Error::from(Errno::ENAMETOOLONG))
163+
return Err(Errno::ENAMETOOLONG)
164164
}
165165

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

183183
if self.len() >= PATH_MAX as usize {
184-
return Err(Error::from(Errno::ENAMETOOLONG))
184+
return Err(Errno::ENAMETOOLONG)
185185
}
186186

187187
match self.iter().position(|b| *b == 0) {
188-
Some(_) => Err(Error::from(Errno::EINVAL)),
188+
Some(_) => Err(Errno::EINVAL),
189189
None => {
190190
unsafe {
191191
// TODO: Replace with bytes::copy_memory. rust-lang/rust#24028

src/mount/bsd.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ impl<'a> Nmount<'a> {
383383
Some(CStr::from_bytes_with_nul(sl).unwrap())
384384
}
385385
};
386-
Err(NmountError::new(error.into(), errmsg))
386+
Err(NmountError::new(error, errmsg))
387387
}
388388
}
389389
}

src/mount/linux.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![allow(missing_docs)]
12
use libc::{self, c_ulong, c_int};
23
use crate::{Result, NixPath};
34
use crate::errno::Errno;

src/mount/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
//! Mount file systems
22
#[cfg(any(target_os = "android", target_os = "linux"))]
3-
#[allow(missing_docs)]
43
mod linux;
54

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

108
#[cfg(any(target_os = "dragonfly",

src/mqueue.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ pub fn mq_setattr(mqd: mqd_t, newattr: &MqAttr) -> Result<MqAttr> {
155155
/// Convenience function.
156156
/// Sets the `O_NONBLOCK` attribute for a given message queue descriptor
157157
/// Returns the old attributes
158+
#[allow(clippy::useless_conversion)] // Not useless on all OSes
158159
pub fn mq_set_nonblock(mqd: mqd_t) -> Result<MqAttr> {
159160
let oldattr = mq_getattr(mqd)?;
160161
let newattr = MqAttr::new(mq_attr_member_t::from(MQ_OFlag::O_NONBLOCK.bits()),

0 commit comments

Comments
 (0)