Use drop instead of the toilet closure |_| ()
This commit is contained in:
@@ -93,12 +93,12 @@ pub fn ftruncate64(fd: c_int, size: u64) -> io::Result<()> {
|
||||
|
||||
unsafe {
|
||||
match ftruncate64.get() {
|
||||
Some(f) => cvt_r(|| f(fd, size as i64)).map(|_| ()),
|
||||
Some(f) => cvt_r(|| f(fd, size as i64)).map(drop),
|
||||
None => {
|
||||
if size > i32::max_value() as u64 {
|
||||
Err(io::Error::new(io::ErrorKind::InvalidInput, "cannot truncate >2GB"))
|
||||
} else {
|
||||
cvt_r(|| ftruncate(fd, size as i32)).map(|_| ())
|
||||
cvt_r(|| ftruncate(fd, size as i32)).map(drop)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -107,7 +107,7 @@ pub fn ftruncate64(fd: c_int, size: u64) -> io::Result<()> {
|
||||
|
||||
#[cfg(target_pointer_width = "64")]
|
||||
pub fn ftruncate64(fd: c_int, size: u64) -> io::Result<()> {
|
||||
unsafe { cvt_r(|| ftruncate(fd, size as i64)).map(|_| ()) }
|
||||
unsafe { cvt_r(|| ftruncate(fd, size as i64)).map(drop) }
|
||||
}
|
||||
|
||||
#[cfg(target_pointer_width = "32")]
|
||||
|
||||
@@ -814,7 +814,7 @@ impl File {
|
||||
use crate::convert::TryInto;
|
||||
let size: off64_t =
|
||||
size.try_into().map_err(|e| io::Error::new(io::ErrorKind::InvalidInput, e))?;
|
||||
cvt_r(|| unsafe { ftruncate64(self.0.raw(), size) }).map(|_| ())
|
||||
cvt_r(|| unsafe { ftruncate64(self.0.raw(), size) }).map(drop)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -324,7 +324,7 @@ impl Socket {
|
||||
|
||||
pub fn set_nonblocking(&self, nonblocking: bool) -> io::Result<()> {
|
||||
let mut nonblocking = nonblocking as libc::c_int;
|
||||
cvt(unsafe { libc::ioctl(*self.as_inner(), libc::FIONBIO, &mut nonblocking) }).map(|_| ())
|
||||
cvt(unsafe { libc::ioctl(*self.as_inner(), libc::FIONBIO, &mut nonblocking) }).map(drop)
|
||||
}
|
||||
|
||||
pub fn take_error(&self) -> io::Result<Option<io::Error>> {
|
||||
|
||||
@@ -529,7 +529,7 @@ pub fn setenv(k: &OsStr, v: &OsStr) -> io::Result<()> {
|
||||
|
||||
unsafe {
|
||||
let _guard = env_lock();
|
||||
cvt(libc::setenv(k.as_ptr(), v.as_ptr(), 1)).map(|_| ())
|
||||
cvt(libc::setenv(k.as_ptr(), v.as_ptr(), 1)).map(drop)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -538,7 +538,7 @@ pub fn unsetenv(n: &OsStr) -> io::Result<()> {
|
||||
|
||||
unsafe {
|
||||
let _guard = env_lock();
|
||||
cvt(libc::unsetenv(nbuf.as_ptr())).map(|_| ())
|
||||
cvt(libc::unsetenv(nbuf.as_ptr())).map(drop)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -99,11 +99,11 @@ pub fn read2(p1: AnonPipe, v1: &mut Vec<u8>, p2: AnonPipe, v2: &mut Vec<u8>) ->
|
||||
|
||||
if fds[0].revents != 0 && read(&p1, v1)? {
|
||||
p2.set_nonblocking(false)?;
|
||||
return p2.read_to_end(v2).map(|_| ());
|
||||
return p2.read_to_end(v2).map(drop);
|
||||
}
|
||||
if fds[1].revents != 0 && read(&p2, v2)? {
|
||||
p1.set_nonblocking(false)?;
|
||||
return p1.read_to_end(v1).map(|_| ());
|
||||
return p1.read_to_end(v1).map(drop);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -425,7 +425,7 @@ impl Process {
|
||||
"invalid argument: can't kill an exited process",
|
||||
))
|
||||
} else {
|
||||
cvt(unsafe { libc::kill(self.pid, libc::SIGKILL) }).map(|_| ())
|
||||
cvt(unsafe { libc::kill(self.pid, libc::SIGKILL) }).map(drop)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -340,7 +340,7 @@ impl File {
|
||||
}
|
||||
|
||||
pub fn truncate(&self, size: u64) -> io::Result<()> {
|
||||
return cvt_r(|| unsafe { ftruncate(self.0.raw(), size as off_t) }).map(|_| ());
|
||||
return cvt_r(|| unsafe { ftruncate(self.0.raw(), size as off_t) }).map(drop);
|
||||
}
|
||||
|
||||
pub fn read(&self, buf: &mut [u8]) -> io::Result<usize> {
|
||||
|
||||
@@ -261,7 +261,7 @@ impl Socket {
|
||||
|
||||
pub fn set_nonblocking(&self, nonblocking: bool) -> io::Result<()> {
|
||||
let mut nonblocking = nonblocking as libc::c_int;
|
||||
cvt(unsafe { libc::ioctl(*self.as_inner(), libc::FIONBIO, &mut nonblocking) }).map(|_| ())
|
||||
cvt(unsafe { libc::ioctl(*self.as_inner(), libc::FIONBIO, &mut nonblocking) }).map(drop)
|
||||
}
|
||||
|
||||
pub fn take_error(&self) -> io::Result<Option<io::Error>> {
|
||||
|
||||
@@ -279,7 +279,7 @@ pub fn setenv(k: &OsStr, v: &OsStr) -> io::Result<()> {
|
||||
|
||||
unsafe {
|
||||
let _guard = env_lock();
|
||||
cvt(libc::setenv(k.as_ptr(), v.as_ptr(), 1)).map(|_| ())
|
||||
cvt(libc::setenv(k.as_ptr(), v.as_ptr(), 1)).map(drop)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -288,7 +288,7 @@ pub fn unsetenv(n: &OsStr) -> io::Result<()> {
|
||||
|
||||
unsafe {
|
||||
let _guard = env_lock();
|
||||
cvt(libc::unsetenv(nbuf.as_ptr())).map(|_| ())
|
||||
cvt(libc::unsetenv(nbuf.as_ptr())).map(drop)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -66,11 +66,11 @@ pub fn read2(p1: AnonPipe, v1: &mut Vec<u8>, p2: AnonPipe, v2: &mut Vec<u8>) ->
|
||||
|
||||
if fds[0].revents != 0 && read(&p1, v1)? {
|
||||
p2.set_nonblocking_pipe(false)?;
|
||||
return p2.read_to_end(v2).map(|_| ());
|
||||
return p2.read_to_end(v2).map(drop);
|
||||
}
|
||||
if fds[1].revents != 0 && read(&p2, v2)? {
|
||||
p1.set_nonblocking_pipe(false)?;
|
||||
return p1.read_to_end(v1).map(|_| ());
|
||||
return p1.read_to_end(v1).map(drop);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -138,7 +138,7 @@ impl Process {
|
||||
"invalid argument: can't kill an exited process",
|
||||
))
|
||||
} else {
|
||||
cvt(unsafe { libc::kill(self.pid, libc::SIGKILL) }).map(|_| ())
|
||||
cvt(unsafe { libc::kill(self.pid, libc::SIGKILL) }).map(drop)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -151,7 +151,7 @@ pub fn setenv(k: &OsStr, v: &OsStr) -> io::Result<()> {
|
||||
|
||||
unsafe {
|
||||
let _guard = env_lock();
|
||||
cvt(libc::setenv(k.as_ptr(), v.as_ptr(), 1)).map(|_| ())
|
||||
cvt(libc::setenv(k.as_ptr(), v.as_ptr(), 1)).map(drop)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -160,7 +160,7 @@ pub fn unsetenv(n: &OsStr) -> io::Result<()> {
|
||||
|
||||
unsafe {
|
||||
let _guard = env_lock();
|
||||
cvt(libc::unsetenv(nbuf.as_ptr())).map(|_| ())
|
||||
cvt(libc::unsetenv(nbuf.as_ptr())).map(drop)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -923,6 +923,6 @@ fn symlink_junction_inner(target: &Path, junction: &Path) -> io::Result<()> {
|
||||
&mut ret,
|
||||
ptr::null_mut(),
|
||||
))
|
||||
.map(|_| ())
|
||||
.map(drop)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -156,7 +156,7 @@ impl RawHandle {
|
||||
}
|
||||
|
||||
pub fn cancel_io(&self) -> io::Result<()> {
|
||||
unsafe { cvt(c::CancelIo(self.raw())).map(|_| ()) }
|
||||
unsafe { cvt(c::CancelIo(self.raw())).map(drop) }
|
||||
}
|
||||
|
||||
pub fn write(&self, buf: &[u8]) -> io::Result<usize> {
|
||||
|
||||
@@ -355,7 +355,7 @@ impl Socket {
|
||||
#[cfg(not(target_vendor = "uwp"))]
|
||||
fn set_no_inherit(&self) -> io::Result<()> {
|
||||
sys::cvt(unsafe { c::SetHandleInformation(self.0 as c::HANDLE, c::HANDLE_FLAG_INHERIT, 0) })
|
||||
.map(|_| ())
|
||||
.map(drop)
|
||||
}
|
||||
|
||||
#[cfg(target_vendor = "uwp")]
|
||||
|
||||
@@ -247,7 +247,7 @@ pub fn chdir(p: &path::Path) -> io::Result<()> {
|
||||
let mut p = p.encode_wide().collect::<Vec<_>>();
|
||||
p.push(0);
|
||||
|
||||
cvt(unsafe { c::SetCurrentDirectoryW(p.as_ptr()) }).map(|_| ())
|
||||
cvt(unsafe { c::SetCurrentDirectoryW(p.as_ptr()) }).map(drop)
|
||||
}
|
||||
|
||||
pub fn getenv(k: &OsStr) -> io::Result<Option<OsString>> {
|
||||
@@ -272,12 +272,12 @@ pub fn setenv(k: &OsStr, v: &OsStr) -> io::Result<()> {
|
||||
let k = to_u16s(k)?;
|
||||
let v = to_u16s(v)?;
|
||||
|
||||
cvt(unsafe { c::SetEnvironmentVariableW(k.as_ptr(), v.as_ptr()) }).map(|_| ())
|
||||
cvt(unsafe { c::SetEnvironmentVariableW(k.as_ptr(), v.as_ptr()) }).map(drop)
|
||||
}
|
||||
|
||||
pub fn unsetenv(n: &OsStr) -> io::Result<()> {
|
||||
let v = to_u16s(n)?;
|
||||
cvt(unsafe { c::SetEnvironmentVariableW(v.as_ptr(), ptr::null()) }).map(|_| ())
|
||||
cvt(unsafe { c::SetEnvironmentVariableW(v.as_ptr(), ptr::null()) }).map(drop)
|
||||
}
|
||||
|
||||
pub fn temp_dir() -> PathBuf {
|
||||
|
||||
Reference in New Issue
Block a user