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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

0 commit comments

Comments
 (0)