diff options
| author | bors <bors@rust-lang.org> | 2022-08-12 09:49:55 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-08-12 09:49:55 +0000 |
| commit | 569788e47ee3595c9c6f0e332844d982b3e991c2 (patch) | |
| tree | 8e88e20df9face042294c44f868e177152681f6d | |
| parent | cc65e1a548abee1d664113abd117b79055532ffa (diff) | |
| parent | d91dff3c1b1dfa1e6a1b890057019259b97d6ea4 (diff) | |
| download | rust-569788e47ee3595c9c6f0e332844d982b3e991c2.tar.gz rust-569788e47ee3595c9c6f0e332844d982b3e991c2.zip | |
Auto merge of #99624 - vincenzopalazzo:macros/unix_error, r=Amanieu
promote debug_assert to assert when possible and useful This PR fixed a very old issue https://github.com/rust-lang/rust/issues/94705 to clarify and improve the POSIX error checking, and some of the checks are skipped because can have no benefit, but I'm sure that this can open some interesting discussion. Fixes https://github.com/rust-lang/rust/issues/94705 cc: `@tavianator` cc: `@cuviper`
| -rw-r--r-- | library/std/src/sys/unix/fs.rs | 6 | ||||
| -rw-r--r-- | library/std/src/sys/unix/locks/pthread_condvar.rs | 2 |
2 files changed, 6 insertions, 2 deletions
diff --git a/library/std/src/sys/unix/fs.rs b/library/std/src/sys/unix/fs.rs index b5cc8038ca4..1f2f9d97bdd 100644 --- a/library/std/src/sys/unix/fs.rs +++ b/library/std/src/sys/unix/fs.rs @@ -687,7 +687,11 @@ impl Iterator for ReadDir { impl Drop for Dir { fn drop(&mut self) { let r = unsafe { libc::closedir(self.0) }; - debug_assert_eq!(r, 0); + assert!( + r == 0 || crate::io::Error::last_os_error().kind() == crate::io::ErrorKind::Interrupted, + "unexpected error during closedir: {:?}", + crate::io::Error::last_os_error() + ); } } diff --git a/library/std/src/sys/unix/locks/pthread_condvar.rs b/library/std/src/sys/unix/locks/pthread_condvar.rs index abf27e7db78..4741c0c6736 100644 --- a/library/std/src/sys/unix/locks/pthread_condvar.rs +++ b/library/std/src/sys/unix/locks/pthread_condvar.rs @@ -172,7 +172,7 @@ impl Condvar { let mut sys_now = libc::timeval { tv_sec: 0, tv_usec: 0 }; let stable_now = Instant::now(); let r = libc::gettimeofday(&mut sys_now, ptr::null_mut()); - debug_assert_eq!(r, 0); + assert_eq!(r, 0, "unexpected error: {:?}", crate::io::Error::last_os_error()); let nsec = dur.subsec_nanos() as libc::c_long + (sys_now.tv_usec * 1000) as libc::c_long; let extra = (nsec / 1_000_000_000) as libc::time_t; |
