Skip to content

Commit 061d200

Browse files
authored
Rollup merge of #67807 - lzutao:toilet-closure, r=Centril
Use drop instead of the toilet closure `|_| ()`
2 parents 4ba28c8 + dd8f072 commit 061d200

File tree

25 files changed

+35
-35
lines changed

25 files changed

+35
-35
lines changed

src/liballoc/tests/arc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ fn shared_from_iter_trustedlen_normal() {
142142

143143
// Try a ZST to make sure it is handled well.
144144
{
145-
let iter = (0..SHARED_ITER_MAX).map(|_| ());
145+
let iter = (0..SHARED_ITER_MAX).map(drop);
146146
let vec = iter.clone().collect::<Vec<_>>();
147147
let rc = iter.collect::<Rc<[_]>>();
148148
assert_eq!(&*vec, &*rc);

src/liballoc/tests/rc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ fn shared_from_iter_trustedlen_normal() {
138138

139139
// Try a ZST to make sure it is handled well.
140140
{
141-
let iter = (0..SHARED_ITER_MAX).map(|_| ());
141+
let iter = (0..SHARED_ITER_MAX).map(drop);
142142
let vec = iter.clone().collect::<Vec<_>>();
143143
let rc = iter.collect::<Rc<[_]>>();
144144
assert_eq!(&*vec, &*rc);

src/librustc_parse/parser/diagnostics.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -848,7 +848,7 @@ impl<'a> Parser<'a> {
848848
let appl = Applicability::MachineApplicable;
849849
if self.token.span == DUMMY_SP || self.prev_span == DUMMY_SP {
850850
// Likely inside a macro, can't provide meaninful suggestions.
851-
return self.expect(&token::Semi).map(|_| ());
851+
return self.expect(&token::Semi).map(drop);
852852
} else if !sm.is_multiline(self.prev_span.until(self.token.span)) {
853853
// The current token is in the same line as the prior token, not recoverable.
854854
} else if self.look_ahead(1, |t| {
@@ -887,7 +887,7 @@ impl<'a> Parser<'a> {
887887
.emit();
888888
return Ok(());
889889
}
890-
self.expect(&token::Semi).map(|_| ()) // Error unconditionally
890+
self.expect(&token::Semi).map(drop) // Error unconditionally
891891
}
892892

893893
pub(super) fn parse_semi_or_incorrect_foreign_fn_body(

src/libstd/io/buffered.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ impl<R: Seek> BufReader<R> {
232232
}
233233
}
234234
}
235-
self.seek(SeekFrom::Current(offset)).map(|_| ())
235+
self.seek(SeekFrom::Current(offset)).map(drop)
236236
}
237237
}
238238

src/libstd/sys/unix/android.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,12 @@ pub fn ftruncate64(fd: c_int, size: u64) -> io::Result<()> {
9393

9494
unsafe {
9595
match ftruncate64.get() {
96-
Some(f) => cvt_r(|| f(fd, size as i64)).map(|_| ()),
96+
Some(f) => cvt_r(|| f(fd, size as i64)).map(drop),
9797
None => {
9898
if size > i32::max_value() as u64 {
9999
Err(io::Error::new(io::ErrorKind::InvalidInput, "cannot truncate >2GB"))
100100
} else {
101-
cvt_r(|| ftruncate(fd, size as i32)).map(|_| ())
101+
cvt_r(|| ftruncate(fd, size as i32)).map(drop)
102102
}
103103
}
104104
}
@@ -107,7 +107,7 @@ pub fn ftruncate64(fd: c_int, size: u64) -> io::Result<()> {
107107

108108
#[cfg(target_pointer_width = "64")]
109109
pub fn ftruncate64(fd: c_int, size: u64) -> io::Result<()> {
110-
unsafe { cvt_r(|| ftruncate(fd, size as i64)).map(|_| ()) }
110+
unsafe { cvt_r(|| ftruncate(fd, size as i64)).map(drop) }
111111
}
112112

113113
#[cfg(target_pointer_width = "32")]

src/libstd/sys/unix/fs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -814,7 +814,7 @@ impl File {
814814
use crate::convert::TryInto;
815815
let size: off64_t =
816816
size.try_into().map_err(|e| io::Error::new(io::ErrorKind::InvalidInput, e))?;
817-
cvt_r(|| unsafe { ftruncate64(self.0.raw(), size) }).map(|_| ())
817+
cvt_r(|| unsafe { ftruncate64(self.0.raw(), size) }).map(drop)
818818
}
819819
}
820820

src/libstd/sys/unix/net.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ impl Socket {
324324

325325
pub fn set_nonblocking(&self, nonblocking: bool) -> io::Result<()> {
326326
let mut nonblocking = nonblocking as libc::c_int;
327-
cvt(unsafe { libc::ioctl(*self.as_inner(), libc::FIONBIO, &mut nonblocking) }).map(|_| ())
327+
cvt(unsafe { libc::ioctl(*self.as_inner(), libc::FIONBIO, &mut nonblocking) }).map(drop)
328328
}
329329

330330
pub fn take_error(&self) -> io::Result<Option<io::Error>> {

src/libstd/sys/unix/os.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ pub fn setenv(k: &OsStr, v: &OsStr) -> io::Result<()> {
529529

530530
unsafe {
531531
let _guard = env_lock();
532-
cvt(libc::setenv(k.as_ptr(), v.as_ptr(), 1)).map(|_| ())
532+
cvt(libc::setenv(k.as_ptr(), v.as_ptr(), 1)).map(drop)
533533
}
534534
}
535535

@@ -538,7 +538,7 @@ pub fn unsetenv(n: &OsStr) -> io::Result<()> {
538538

539539
unsafe {
540540
let _guard = env_lock();
541-
cvt(libc::unsetenv(nbuf.as_ptr())).map(|_| ())
541+
cvt(libc::unsetenv(nbuf.as_ptr())).map(drop)
542542
}
543543
}
544544

src/libstd/sys/unix/pipe.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,11 @@ pub fn read2(p1: AnonPipe, v1: &mut Vec<u8>, p2: AnonPipe, v2: &mut Vec<u8>) ->
9999

100100
if fds[0].revents != 0 && read(&p1, v1)? {
101101
p2.set_nonblocking(false)?;
102-
return p2.read_to_end(v2).map(|_| ());
102+
return p2.read_to_end(v2).map(drop);
103103
}
104104
if fds[1].revents != 0 && read(&p2, v2)? {
105105
p1.set_nonblocking(false)?;
106-
return p1.read_to_end(v1).map(|_| ());
106+
return p1.read_to_end(v1).map(drop);
107107
}
108108
}
109109

src/libstd/sys/unix/process/process_unix.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ impl Process {
425425
"invalid argument: can't kill an exited process",
426426
))
427427
} else {
428-
cvt(unsafe { libc::kill(self.pid, libc::SIGKILL) }).map(|_| ())
428+
cvt(unsafe { libc::kill(self.pid, libc::SIGKILL) }).map(drop)
429429
}
430430
}
431431

src/libstd/sys/vxworks/fs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ impl File {
340340
}
341341

342342
pub fn truncate(&self, size: u64) -> io::Result<()> {
343-
return cvt_r(|| unsafe { ftruncate(self.0.raw(), size as off_t) }).map(|_| ());
343+
return cvt_r(|| unsafe { ftruncate(self.0.raw(), size as off_t) }).map(drop);
344344
}
345345

346346
pub fn read(&self, buf: &mut [u8]) -> io::Result<usize> {

src/libstd/sys/vxworks/net.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ impl Socket {
261261

262262
pub fn set_nonblocking(&self, nonblocking: bool) -> io::Result<()> {
263263
let mut nonblocking = nonblocking as libc::c_int;
264-
cvt(unsafe { libc::ioctl(*self.as_inner(), libc::FIONBIO, &mut nonblocking) }).map(|_| ())
264+
cvt(unsafe { libc::ioctl(*self.as_inner(), libc::FIONBIO, &mut nonblocking) }).map(drop)
265265
}
266266

267267
pub fn take_error(&self) -> io::Result<Option<io::Error>> {

src/libstd/sys/vxworks/os.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ pub fn setenv(k: &OsStr, v: &OsStr) -> io::Result<()> {
279279

280280
unsafe {
281281
let _guard = env_lock();
282-
cvt(libc::setenv(k.as_ptr(), v.as_ptr(), 1)).map(|_| ())
282+
cvt(libc::setenv(k.as_ptr(), v.as_ptr(), 1)).map(drop)
283283
}
284284
}
285285

@@ -288,7 +288,7 @@ pub fn unsetenv(n: &OsStr) -> io::Result<()> {
288288

289289
unsafe {
290290
let _guard = env_lock();
291-
cvt(libc::unsetenv(nbuf.as_ptr())).map(|_| ())
291+
cvt(libc::unsetenv(nbuf.as_ptr())).map(drop)
292292
}
293293
}
294294

src/libstd/sys/vxworks/pipe.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,11 @@ pub fn read2(p1: AnonPipe, v1: &mut Vec<u8>, p2: AnonPipe, v2: &mut Vec<u8>) ->
6666

6767
if fds[0].revents != 0 && read(&p1, v1)? {
6868
p2.set_nonblocking_pipe(false)?;
69-
return p2.read_to_end(v2).map(|_| ());
69+
return p2.read_to_end(v2).map(drop);
7070
}
7171
if fds[1].revents != 0 && read(&p2, v2)? {
7272
p1.set_nonblocking_pipe(false)?;
73-
return p1.read_to_end(v1).map(|_| ());
73+
return p1.read_to_end(v1).map(drop);
7474
}
7575
}
7676

src/libstd/sys/vxworks/process/process_vxworks.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ impl Process {
138138
"invalid argument: can't kill an exited process",
139139
))
140140
} else {
141-
cvt(unsafe { libc::kill(self.pid, libc::SIGKILL) }).map(|_| ())
141+
cvt(unsafe { libc::kill(self.pid, libc::SIGKILL) }).map(drop)
142142
}
143143
}
144144

src/libstd/sys/wasi/os.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ pub fn setenv(k: &OsStr, v: &OsStr) -> io::Result<()> {
151151

152152
unsafe {
153153
let _guard = env_lock();
154-
cvt(libc::setenv(k.as_ptr(), v.as_ptr(), 1)).map(|_| ())
154+
cvt(libc::setenv(k.as_ptr(), v.as_ptr(), 1)).map(drop)
155155
}
156156
}
157157

@@ -160,7 +160,7 @@ pub fn unsetenv(n: &OsStr) -> io::Result<()> {
160160

161161
unsafe {
162162
let _guard = env_lock();
163-
cvt(libc::unsetenv(nbuf.as_ptr())).map(|_| ())
163+
cvt(libc::unsetenv(nbuf.as_ptr())).map(drop)
164164
}
165165
}
166166

src/libstd/sys/windows/fs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -923,6 +923,6 @@ fn symlink_junction_inner(target: &Path, junction: &Path) -> io::Result<()> {
923923
&mut ret,
924924
ptr::null_mut(),
925925
))
926-
.map(|_| ())
926+
.map(drop)
927927
}
928928
}

src/libstd/sys/windows/handle.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ impl RawHandle {
156156
}
157157

158158
pub fn cancel_io(&self) -> io::Result<()> {
159-
unsafe { cvt(c::CancelIo(self.raw())).map(|_| ()) }
159+
unsafe { cvt(c::CancelIo(self.raw())).map(drop) }
160160
}
161161

162162
pub fn write(&self, buf: &[u8]) -> io::Result<usize> {

src/libstd/sys/windows/net.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ impl Socket {
355355
#[cfg(not(target_vendor = "uwp"))]
356356
fn set_no_inherit(&self) -> io::Result<()> {
357357
sys::cvt(unsafe { c::SetHandleInformation(self.0 as c::HANDLE, c::HANDLE_FLAG_INHERIT, 0) })
358-
.map(|_| ())
358+
.map(drop)
359359
}
360360

361361
#[cfg(target_vendor = "uwp")]

src/libstd/sys/windows/os.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ pub fn chdir(p: &path::Path) -> io::Result<()> {
247247
let mut p = p.encode_wide().collect::<Vec<_>>();
248248
p.push(0);
249249

250-
cvt(unsafe { c::SetCurrentDirectoryW(p.as_ptr()) }).map(|_| ())
250+
cvt(unsafe { c::SetCurrentDirectoryW(p.as_ptr()) }).map(drop)
251251
}
252252

253253
pub fn getenv(k: &OsStr) -> io::Result<Option<OsString>> {
@@ -272,12 +272,12 @@ pub fn setenv(k: &OsStr, v: &OsStr) -> io::Result<()> {
272272
let k = to_u16s(k)?;
273273
let v = to_u16s(v)?;
274274

275-
cvt(unsafe { c::SetEnvironmentVariableW(k.as_ptr(), v.as_ptr()) }).map(|_| ())
275+
cvt(unsafe { c::SetEnvironmentVariableW(k.as_ptr(), v.as_ptr()) }).map(drop)
276276
}
277277

278278
pub fn unsetenv(n: &OsStr) -> io::Result<()> {
279279
let v = to_u16s(n)?;
280-
cvt(unsafe { c::SetEnvironmentVariableW(v.as_ptr(), ptr::null()) }).map(|_| ())
280+
cvt(unsafe { c::SetEnvironmentVariableW(v.as_ptr(), ptr::null()) }).map(drop)
281281
}
282282

283283
pub fn temp_dir() -> PathBuf {

src/libstd/sys_common/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ macro_rules! rtunwrap {
3636
match $e {
3737
$ok(v) => v,
3838
ref err => {
39-
let err = err.as_ref().map(|_| ()); // map Ok/Some which might not be Debug
39+
let err = err.as_ref().map(drop); // map Ok/Some which might not be Debug
4040
rtabort!(concat!("unwrap failed: ", stringify!($e), " = {:?}"), err)
4141
}
4242
}

src/libstd/sys_common/net.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,7 @@ impl UdpSocket {
659659

660660
pub fn connect(&self, addr: io::Result<&SocketAddr>) -> io::Result<()> {
661661
let (addrp, len) = addr?.into_inner();
662-
cvt_r(|| unsafe { c::connect(*self.inner.as_inner(), addrp, len) }).map(|_| ())
662+
cvt_r(|| unsafe { c::connect(*self.inner.as_inner(), addrp, len) }).map(drop)
663663
}
664664
}
665665

src/test/ui/async-await/issues/issue-64433.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ impl B {
2323
async fn can_error(some_string: &str) -> Result<(), String> {
2424
let a = A { inner: vec![some_string, "foo"] };
2525
let mut b = B {};
26-
Ok(b.something_with_a(a).await.map(|_| ())?)
26+
Ok(b.something_with_a(a).await.map(drop)?)
2727
}
2828

2929
fn main() {

src/test/ui/nll/issue-50343.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
#![deny(unused_mut)]
44

55
fn main() {
6-
vec![42].iter().map(|_| ()).count();
6+
vec![42].iter().map(drop).count();
77
vec![(42, 22)].iter().map(|(_x, _y)| ()).count();
88
}

src/test/ui/paths-containing-nul.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ fn assert_invalid_input<T>(on: &str, result: io::Result<T>) {
1717
"{} returned a strange {:?} on a path with NUL", on, e.kind()),
1818
}
1919
}
20-
inner(on, result.map(|_| ()))
20+
inner(on, result.map(drop))
2121
}
2222

2323
fn main() {

0 commit comments

Comments
 (0)