Skip to content

Commit dad7770

Browse files
committed
Merge #818
818: Clippy cleanup r=Susurrus a=Susurrus Various fixes for errors and warnings pointed out by clippy.
2 parents 5d50aca + 8db68be commit dad7770

Some content is hidden

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

42 files changed

+299
-349
lines changed

src/errno.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,6 @@ mod consts {
675675
use self::Errno::*;
676676

677677
match e {
678-
0 => UnknownErrno,
679678
libc::EPERM => EPERM,
680679
libc::ENOENT => ENOENT,
681680
libc::ESRCH => ESRCH,
@@ -940,7 +939,6 @@ mod consts {
940939
use self::Errno::*;
941940

942941
match e {
943-
0 => UnknownErrno,
944942
libc::EPERM => EPERM,
945943
libc::ENOENT => ENOENT,
946944
libc::ESRCH => ESRCH,
@@ -1168,7 +1166,6 @@ mod consts {
11681166
use self::Errno::*;
11691167

11701168
match e {
1171-
0 => UnknownErrno,
11721169
libc::EPERM => EPERM,
11731170
libc::ENOENT => ENOENT,
11741171
libc::ESRCH => ESRCH,
@@ -1391,7 +1388,6 @@ mod consts {
13911388
use self::Errno::*;
13921389

13931390
match e {
1394-
0 => UnknownErrno,
13951391
libc::EPERM => EPERM,
13961392
libc::ENOENT => ENOENT,
13971393
libc::ESRCH => ESRCH,
@@ -1607,7 +1603,6 @@ mod consts {
16071603
use self::Errno::*;
16081604

16091605
match e {
1610-
0 => UnknownErrno,
16111606
libc::EPERM => EPERM,
16121607
libc::ENOENT => ENOENT,
16131608
libc::ESRCH => ESRCH,
@@ -1819,7 +1814,6 @@ mod consts {
18191814
use self::Errno::*;
18201815

18211816
match e {
1822-
0 => UnknownErrno,
18231817
libc::EPERM => EPERM,
18241818
libc::ENOENT => ENOENT,
18251819
libc::ESRCH => ESRCH,

src/fcntl.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,7 @@ pub fn openat<P: ?Sized + NixPath>(dirfd: RawFd, path: &P, oflag: OFlag, mode: M
152152
Errno::result(fd)
153153
}
154154

155-
fn wrap_readlink_result<'a>(buffer: &'a mut[u8], res: ssize_t)
156-
-> Result<&'a OsStr> {
155+
fn wrap_readlink_result(buffer: &mut[u8], res: ssize_t) -> Result<&OsStr> {
157156
match Errno::result(res) {
158157
Err(err) => Err(err),
159158
Ok(len) => {

src/lib.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -128,22 +128,22 @@ impl From<std::string::FromUtf8Error> for Error {
128128

129129
impl error::Error for Error {
130130
fn description(&self) -> &str {
131-
match self {
132-
&Error::InvalidPath => "Invalid path",
133-
&Error::InvalidUtf8 => "Invalid UTF-8 string",
134-
&Error::UnsupportedOperation => "Unsupported Operation",
135-
&Error::Sys(ref errno) => errno.desc(),
131+
match *self {
132+
Error::InvalidPath => "Invalid path",
133+
Error::InvalidUtf8 => "Invalid UTF-8 string",
134+
Error::UnsupportedOperation => "Unsupported Operation",
135+
Error::Sys(ref errno) => errno.desc(),
136136
}
137137
}
138138
}
139139

140140
impl fmt::Display for Error {
141141
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
142-
match self {
143-
&Error::InvalidPath => write!(f, "Invalid path"),
144-
&Error::InvalidUtf8 => write!(f, "Invalid UTF-8 string"),
145-
&Error::UnsupportedOperation => write!(f, "Unsupported Operation"),
146-
&Error::Sys(errno) => write!(f, "{:?}: {}", errno, errno.desc()),
142+
match *self {
143+
Error::InvalidPath => write!(f, "Invalid path"),
144+
Error::InvalidUtf8 => write!(f, "Invalid UTF-8 string"),
145+
Error::UnsupportedOperation => write!(f, "Unsupported Operation"),
146+
Error::Sys(errno) => write!(f, "{:?}: {}", errno, errno.desc()),
147147
}
148148
}
149149
}

src/mqueue.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ impl MqAttr {
6666

6767
/// Open a message queue
6868
///
69-
/// See also [mq_open(2)](http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_open.html)
69+
/// See also [`mq_open(2)`](http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_open.html)
7070
pub fn mq_open(name: &CString,
7171
oflag: MQ_OFlag,
7272
mode: Mode,
@@ -86,23 +86,23 @@ pub fn mq_open(name: &CString,
8686

8787
/// Remove a message queue
8888
///
89-
/// See also [mq_unlink(2)](http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_unlink.html)
89+
/// See also [`mq_unlink(2)`](http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_unlink.html)
9090
pub fn mq_unlink(name: &CString) -> Result<()> {
9191
let res = unsafe { libc::mq_unlink(name.as_ptr()) };
9292
Errno::result(res).map(drop)
9393
}
9494

9595
/// Close a message queue
9696
///
97-
/// See also [mq_close(2)](http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_close.html)
97+
/// See also [`mq_close(2)`](http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_close.html)
9898
pub fn mq_close(mqdes: mqd_t) -> Result<()> {
9999
let res = unsafe { libc::mq_close(mqdes) };
100100
Errno::result(res).map(drop)
101101
}
102102

103103
/// Receive a message from a message queue
104104
///
105-
/// See also [mq_receive(2)](http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_receive.html)
105+
/// See also [`mq_receive(2)`](http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_receive.html)
106106
pub fn mq_receive(mqdes: mqd_t, message: &mut [u8], msg_prio: &mut u32) -> Result<usize> {
107107
let len = message.len() as size_t;
108108
let res = unsafe {
@@ -116,7 +116,7 @@ pub fn mq_receive(mqdes: mqd_t, message: &mut [u8], msg_prio: &mut u32) -> Resul
116116

117117
/// Send a message to a message queue
118118
///
119-
/// See also [mq_send(2)](http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_send.html)
119+
/// See also [`mq_send(2)`](http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_send.html)
120120
pub fn mq_send(mqdes: mqd_t, message: &[u8], msq_prio: u32) -> Result<()> {
121121
let res = unsafe {
122122
libc::mq_send(mqdes,
@@ -129,7 +129,7 @@ pub fn mq_send(mqdes: mqd_t, message: &[u8], msq_prio: u32) -> Result<()> {
129129

130130
/// Get message queue attributes
131131
///
132-
/// See also [mq_getattr(2)](http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_getattr.html)
132+
/// See also [`mq_getattr(2)`](http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_getattr.html)
133133
pub fn mq_getattr(mqd: mqd_t) -> Result<MqAttr> {
134134
let mut attr = unsafe { mem::uninitialized::<libc::mq_attr>() };
135135
let res = unsafe { libc::mq_getattr(mqd, &mut attr) };

src/pty.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,21 +62,21 @@ impl Drop for PtyMaster {
6262
}
6363

6464
/// Grant access to a slave pseudoterminal (see
65-
/// [grantpt(3)](http://pubs.opengroup.org/onlinepubs/9699919799/functions/grantpt.html))
65+
/// [`grantpt(3)`](http://pubs.opengroup.org/onlinepubs/9699919799/functions/grantpt.html))
6666
///
6767
/// `grantpt()` changes the mode and owner of the slave pseudoterminal device corresponding to the
6868
/// master pseudoterminal referred to by `fd`. This is a necessary step towards opening the slave.
6969
#[inline]
7070
pub fn grantpt(fd: &PtyMaster) -> Result<()> {
7171
if unsafe { libc::grantpt(fd.as_raw_fd()) } < 0 {
72-
return Err(Error::last().into());
72+
return Err(Error::last());
7373
}
7474

7575
Ok(())
7676
}
7777

7878
/// Open a pseudoterminal device (see
79-
/// [posix_openpt(3)](http://pubs.opengroup.org/onlinepubs/9699919799/functions/posix_openpt.html))
79+
/// [`posix_openpt(3)`](http://pubs.opengroup.org/onlinepubs/9699919799/functions/posix_openpt.html))
8080
///
8181
/// `posix_openpt()` returns a file descriptor to an existing unused pseuterminal master device.
8282
///
@@ -116,14 +116,14 @@ pub fn posix_openpt(flags: fcntl::OFlag) -> Result<PtyMaster> {
116116
};
117117

118118
if fd < 0 {
119-
return Err(Error::last().into());
119+
return Err(Error::last());
120120
}
121121

122122
Ok(PtyMaster(fd))
123123
}
124124

125125
/// Get the name of the slave pseudoterminal (see
126-
/// [ptsname(3)](http://man7.org/linux/man-pages/man3/ptsname.3.html))
126+
/// [`ptsname(3)`](http://man7.org/linux/man-pages/man3/ptsname.3.html))
127127
///
128128
/// `ptsname()` returns the name of the slave pseudoterminal device corresponding to the master
129129
/// referred to by `fd`.
@@ -142,15 +142,15 @@ pub fn posix_openpt(flags: fcntl::OFlag) -> Result<PtyMaster> {
142142
pub unsafe fn ptsname(fd: &PtyMaster) -> Result<String> {
143143
let name_ptr = libc::ptsname(fd.as_raw_fd());
144144
if name_ptr.is_null() {
145-
return Err(Error::last().into());
145+
return Err(Error::last());
146146
}
147147

148148
let name = CStr::from_ptr(name_ptr);
149149
Ok(name.to_string_lossy().into_owned())
150150
}
151151

152152
/// Get the name of the slave pseudoterminal (see
153-
/// [ptsname(3)](http://man7.org/linux/man-pages/man3/ptsname.3.html))
153+
/// [`ptsname(3)`](http://man7.org/linux/man-pages/man3/ptsname.3.html))
154154
///
155155
/// `ptsname_r()` returns the name of the slave pseudoterminal device corresponding to the master
156156
/// referred to by `fd`. This is the threadsafe version of `ptsname()`, but it is not part of the
@@ -164,7 +164,7 @@ pub fn ptsname_r(fd: &PtyMaster) -> Result<String> {
164164
let mut name_buf = vec![0u8; 64];
165165
let name_buf_ptr = name_buf.as_mut_ptr() as *mut libc::c_char;
166166
if unsafe { libc::ptsname_r(fd.as_raw_fd(), name_buf_ptr, name_buf.capacity()) } != 0 {
167-
return Err(Error::last().into());
167+
return Err(Error::last());
168168
}
169169

170170
// Find the first null-character terminating this string. This is guaranteed to succeed if the
@@ -177,15 +177,15 @@ pub fn ptsname_r(fd: &PtyMaster) -> Result<String> {
177177
}
178178

179179
/// Unlock a pseudoterminal master/slave pseudoterminal pair (see
180-
/// [unlockpt(3)](http://pubs.opengroup.org/onlinepubs/9699919799/functions/unlockpt.html))
180+
/// [`unlockpt(3)`](http://pubs.opengroup.org/onlinepubs/9699919799/functions/unlockpt.html))
181181
///
182182
/// `unlockpt()` unlocks the slave pseudoterminal device corresponding to the master pseudoterminal
183183
/// referred to by `fd`. This must be called before trying to open the slave side of a
184184
/// pseuoterminal.
185185
#[inline]
186186
pub fn unlockpt(fd: &PtyMaster) -> Result<()> {
187187
if unsafe { libc::unlockpt(fd.as_raw_fd()) } < 0 {
188-
return Err(Error::last().into());
188+
return Err(Error::last());
189189
}
190190

191191
Ok(())
@@ -194,7 +194,7 @@ pub fn unlockpt(fd: &PtyMaster) -> Result<()> {
194194

195195
/// Create a new pseudoterminal, returning the slave and master file descriptors
196196
/// in `OpenptyResult`
197-
/// (see [openpty](http://man7.org/linux/man-pages/man3/openpty.3.html)).
197+
/// (see [`openpty`](http://man7.org/linux/man-pages/man3/openpty.3.html)).
198198
///
199199
/// If `winsize` is not `None`, the window size of the slave will be set to
200200
/// the values in `winsize`. If `termios` is not `None`, the pseudoterminal's

src/sys/aio.rs

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,12 @@ impl<'a> AioCb<'a> {
111111
a.aio_nbytes = 0;
112112
a.aio_buf = null_mut();
113113

114-
let aiocb = AioCb { aiocb: a, mutable: false, in_progress: false,
115-
keeper: Keeper::none};
116-
aiocb
114+
AioCb {
115+
aiocb: a,
116+
mutable: false,
117+
in_progress: false,
118+
keeper: Keeper::none
119+
}
117120
}
118121

119122
/// Constructs a new `AioCb`.
@@ -136,9 +139,12 @@ impl<'a> AioCb<'a> {
136139
a.aio_buf = buf.as_ptr() as *mut c_void;
137140
a.aio_lio_opcode = opcode as libc::c_int;
138141

139-
let aiocb = AioCb { aiocb: a, mutable: true, in_progress: false,
140-
keeper: Keeper::phantom(PhantomData)};
141-
aiocb
142+
AioCb {
143+
aiocb: a,
144+
mutable: true,
145+
in_progress: false,
146+
keeper: Keeper::phantom(PhantomData)
147+
}
142148
}
143149

144150
/// Constructs a new `AioCb`.
@@ -164,9 +170,12 @@ impl<'a> AioCb<'a> {
164170
a.aio_buf = buf.as_ptr() as *mut c_void;
165171
a.aio_lio_opcode = opcode as libc::c_int;
166172

167-
let aiocb = AioCb{ aiocb: a, mutable: true, in_progress: false,
168-
keeper: Keeper::boxed(buf)};
169-
aiocb
173+
AioCb {
174+
aiocb: a,
175+
mutable: true,
176+
in_progress: false,
177+
keeper: Keeper::boxed(buf)
178+
}
170179
}
171180

172181
/// Like `from_mut_slice`, but works on constant slices rather than
@@ -195,9 +204,12 @@ impl<'a> AioCb<'a> {
195204
assert!(opcode != LioOpcode::LIO_READ, "Can't read into an immutable buffer");
196205
a.aio_lio_opcode = opcode as libc::c_int;
197206

198-
let aiocb = AioCb { aiocb: a, mutable: false, in_progress: false,
199-
keeper: Keeper::none};
200-
aiocb
207+
AioCb {
208+
aiocb: a,
209+
mutable: false,
210+
in_progress: false,
211+
keeper: Keeper::none
212+
}
201213
}
202214

203215
fn common_init(fd: RawFd, prio: libc::c_int,

src/sys/event.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,13 +312,13 @@ pub fn ev_set(ev: &mut KEvent,
312312
fn test_struct_kevent() {
313313
let udata : intptr_t = 12345;
314314

315-
let expected = libc::kevent{ident: 0xdeadbeef,
315+
let expected = libc::kevent{ident: 0xdead_beef,
316316
filter: libc::EVFILT_READ,
317317
flags: libc::EV_ONESHOT | libc::EV_ADD,
318318
fflags: libc::NOTE_CHILD | libc::NOTE_EXIT,
319319
data: 0x1337,
320320
udata: udata as type_of_udata};
321-
let actual = KEvent::new(0xdeadbeef,
321+
let actual = KEvent::new(0xdead_beef,
322322
EventFilter::EVFILT_READ,
323323
EventFlag::EV_ONESHOT | EventFlag::EV_ADD,
324324
FilterFlag::NOTE_CHILD | FilterFlag::NOTE_EXIT,

src/sys/ioctl/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ macro_rules! convert_ioctl_res {
255255
);
256256
}
257257

258-
/// Generates ioctl functions. See [::sys::ioctl](sys/ioctl/index.html).
258+
/// Generates ioctl functions. See [`::sys::ioctl`](sys/ioctl/index.html).
259259
#[macro_export]
260260
macro_rules! ioctl {
261261
($(#[$attr:meta])* bad none $name:ident with $nr:expr) => (

src/sys/ioctl/platform/bsd.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ pub type ioctl_num_type = ::libc::c_ulong;
55
mod consts {
66
use ::sys::ioctl::platform::ioctl_num_type;
77
#[doc(hidden)]
8-
pub const VOID: ioctl_num_type = 0x20000000;
8+
pub const VOID: ioctl_num_type = 0x2000_0000;
99
#[doc(hidden)]
10-
pub const OUT: ioctl_num_type = 0x40000000;
10+
pub const OUT: ioctl_num_type = 0x4000_0000;
1111
#[doc(hidden)]
12-
pub const IN: ioctl_num_type = 0x80000000;
12+
pub const IN: ioctl_num_type = 0x8000_0000;
1313
#[doc(hidden)]
1414
pub const INOUT: ioctl_num_type = (IN|OUT);
1515
#[doc(hidden)]

src/sys/pthread.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ use libc::{self, pthread_t};
33
pub type Pthread = pthread_t;
44

55
/// Obtain ID of the calling thread (see
6-
/// [pthread_self(3)](http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_self.html)
6+
/// [`pthread_self(3)`](http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_self.html)
77
///
8-
/// The thread ID returned by pthread_self() is not the same thing as
9-
/// the kernel thread ID returned by a call to gettid(2).
8+
/// The thread ID returned by `pthread_self()` is not the same thing as
9+
/// the kernel thread ID returned by a call to `gettid(2)`.
1010
#[inline]
1111
pub fn pthread_self() -> Pthread {
1212
unsafe { libc::pthread_self() }

src/sys/ptrace.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ fn ptrace_peek(request: Request, pid: Pid, addr: *mut c_void, data: *mut c_void)
151151
}
152152

153153
/// Function for ptrace requests that return values from the data field.
154-
/// Some ptrace get requests populate structs or larger elements than c_long
154+
/// Some ptrace get requests populate structs or larger elements than `c_long`
155155
/// and therefore use the data field to return values. This function handles these
156156
/// requests.
157157
fn ptrace_get_data<T>(request: Request, pid: Pid) -> Result<T> {

0 commit comments

Comments
 (0)