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()),

src/pty.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use std::os::unix::prelude::*;
1010

1111
use crate::sys::termios::Termios;
1212
use crate::unistd::{self, ForkResult, Pid};
13-
use crate::{Result, Error, fcntl};
13+
use crate::{Result, fcntl};
1414
use crate::errno::Errno;
1515

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

105105
Ok(())
@@ -145,7 +145,7 @@ pub fn posix_openpt(flags: fcntl::OFlag) -> Result<PtyMaster> {
145145
};
146146

147147
if fd < 0 {
148-
return Err(Error::from(Errno::last()));
148+
return Err(Errno::last());
149149
}
150150

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

177177
let name = CStr::from_ptr(name_ptr);
@@ -195,7 +195,7 @@ pub fn ptsname_r(fd: &PtyMaster) -> Result<String> {
195195
let cname = unsafe {
196196
let cap = name_buf.capacity();
197197
if libc::ptsname_r(fd.as_raw_fd(), name_buf_ptr, cap) != 0 {
198-
return Err(Error::last());
198+
return Err(crate::Error::last());
199199
}
200200
CStr::from_ptr(name_buf.as_ptr())
201201
};
@@ -213,7 +213,7 @@ pub fn ptsname_r(fd: &PtyMaster) -> Result<String> {
213213
#[inline]
214214
pub fn unlockpt(fd: &PtyMaster) -> Result<()> {
215215
if unsafe { libc::unlockpt(fd.as_raw_fd()) } < 0 {
216-
return Err(Error::from(Errno::last()));
216+
return Err(Errno::last());
217217
}
218218

219219
Ok(())

src/sched.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ mod sched_linux_like {
1515
use std::option::Option;
1616
use std::os::unix::io::RawFd;
1717
use crate::unistd::Pid;
18-
use crate::{Error, Result};
18+
use crate::Result;
1919

2020
// For some functions taking with a parameter of type CloneFlags,
2121
// only a subset of these flags have an effect.
@@ -109,7 +109,7 @@ mod sched_linux_like {
109109
/// `field` is the CPU id to test
110110
pub fn is_set(&self, field: usize) -> Result<bool> {
111111
if field >= CpuSet::count() {
112-
Err(Error::from(Errno::EINVAL))
112+
Err(Errno::EINVAL)
113113
} else {
114114
Ok(unsafe { libc::CPU_ISSET(field, &self.cpu_set) })
115115
}
@@ -119,7 +119,7 @@ mod sched_linux_like {
119119
/// `field` is the CPU id to add
120120
pub fn set(&mut self, field: usize) -> Result<()> {
121121
if field >= CpuSet::count() {
122-
Err(Error::from(Errno::EINVAL))
122+
Err(Errno::EINVAL)
123123
} else {
124124
unsafe { libc::CPU_SET(field, &mut self.cpu_set); }
125125
Ok(())
@@ -130,7 +130,7 @@ mod sched_linux_like {
130130
/// `field` is the CPU id to remove
131131
pub fn unset(&mut self, field: usize) -> Result<()> {
132132
if field >= CpuSet::count() {
133-
Err(Error::from(Errno::EINVAL))
133+
Err(Errno::EINVAL)
134134
} else {
135135
unsafe { libc::CPU_CLR(field, &mut self.cpu_set);}
136136
Ok(())

0 commit comments

Comments
 (0)