Skip to content

Commit 45ffee6

Browse files
committed
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 rust-lang/rust#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/rust#94705 cc: `@tavianator` cc: `@cuviper`
2 parents 7411d45 + 8e21758 commit 45ffee6

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

std/src/sys/unix/fs.rs

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

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

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