Skip to content

Commit 569788e

Browse files
committed
Auto merge of rust-lang#99624 - vincenzopalazzo:macros/unix_error, r=Amanieu
promote debug_assert to assert when possible and useful This PR fixed a very old issue rust-lang#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 rust-lang#94705 cc: `@tavianator` cc: `@cuviper`
2 parents cc65e1a + d91dff3 commit 569788e

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

library/std/src/sys/unix/fs.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,11 @@ impl Iterator for ReadDir {
687687
impl Drop for Dir {
688688
fn drop(&mut self) {
689689
let r = unsafe { libc::closedir(self.0) };
690-
debug_assert_eq!(r, 0);
690+
assert!(
691+
r == 0 || crate::io::Error::last_os_error().kind() == crate::io::ErrorKind::Interrupted,
692+
"unexpected error during closedir: {:?}",
693+
crate::io::Error::last_os_error()
694+
);
691695
}
692696
}
693697

library/std/src/sys/unix/locks/pthread_condvar.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ impl Condvar {
172172
let mut sys_now = libc::timeval { tv_sec: 0, tv_usec: 0 };
173173
let stable_now = Instant::now();
174174
let r = libc::gettimeofday(&mut sys_now, ptr::null_mut());
175-
debug_assert_eq!(r, 0);
175+
assert_eq!(r, 0, "unexpected error: {:?}", crate::io::Error::last_os_error());
176176

177177
let nsec = dur.subsec_nanos() as libc::c_long + (sys_now.tv_usec * 1000) as libc::c_long;
178178
let extra = (nsec / 1_000_000_000) as libc::time_t;

0 commit comments

Comments
 (0)