diff --git a/library/std/src/io/error/repr_bitpacked.rs b/library/std/src/io/error/repr_bitpacked.rs index 292bf4826fd23..b05eaa2958ec0 100644 --- a/library/std/src/io/error/repr_bitpacked.rs +++ b/library/std/src/io/error/repr_bitpacked.rs @@ -145,7 +145,7 @@ impl Repr { let p = Box::into_raw(b).cast::(); // Should only be possible if an allocator handed out a pointer with // wrong alignment. - debug_assert_eq!(p.addr() & TAG_MASK, 0); + assert_eq!(p.addr() & TAG_MASK, 0); // Note: We know `TAG_CUSTOM <= size_of::()` (static_assert at // end of file), and both the start and end of the expression must be // valid without address space wraparound due to `Box`'s semantics. @@ -167,7 +167,7 @@ impl Repr { let res = Self(unsafe { NonNull::new_unchecked(tagged) }, PhantomData); // quickly smoke-check we encoded the right thing (This generally will // only run in libstd's tests, unless the user uses -Zbuild-std) - debug_assert!(matches!(res.data(), ErrorData::Custom(_)), "repr(custom) encoding failed"); + assert!(matches!(res.data(), ErrorData::Custom(_)), "repr(custom) encoding failed"); res } @@ -178,7 +178,7 @@ impl Repr { let res = Self(unsafe { NonNull::new_unchecked(ptr::invalid_mut(utagged)) }, PhantomData); // quickly smoke-check we encoded the right thing (This generally will // only run in libstd's tests, unless the user uses -Zbuild-std) - debug_assert!( + assert!( matches!(res.data(), ErrorData::Os(c) if c == code), "repr(os) encoding failed for {code}" ); @@ -192,7 +192,7 @@ impl Repr { let res = Self(unsafe { NonNull::new_unchecked(ptr::invalid_mut(utagged)) }, PhantomData); // quickly smoke-check we encoded the right thing (This generally will // only run in libstd's tests, unless the user uses -Zbuild-std) - debug_assert!( + assert!( matches!(res.data(), ErrorData::Simple(k) if k == kind), "repr(simple) encoding failed {:?}", kind, @@ -256,7 +256,7 @@ where TAG_SIMPLE => { let kind_bits = (bits >> 32) as u32; let kind = kind_from_prim(kind_bits).unwrap_or_else(|| { - debug_assert!(false, "Invalid io::error::Repr bits: `Repr({:#018x})`", bits); + assert!(false, "Invalid io::error::Repr bits: `Repr({:#018x})`", bits); // This means the `ptr` passed in was not valid, which violates // the unsafe contract of `decode_repr`. // diff --git a/library/std/src/os/windows/io/socket.rs b/library/std/src/os/windows/io/socket.rs index 72cb3406dcada..8840fab3d91a7 100644 --- a/library/std/src/os/windows/io/socket.rs +++ b/library/std/src/os/windows/io/socket.rs @@ -193,7 +193,7 @@ impl IntoRawSocket for OwnedSocket { impl FromRawSocket for OwnedSocket { #[inline] unsafe fn from_raw_socket(socket: RawSocket) -> Self { - debug_assert_ne!(socket, c::INVALID_SOCKET as RawSocket); + assert_ne!(socket, c::INVALID_SOCKET as RawSocket); Self { socket } } } diff --git a/library/std/src/sync/mpsc/oneshot.rs b/library/std/src/sync/mpsc/oneshot.rs index 0e259b8aecb9a..05b23c00604a9 100644 --- a/library/std/src/sync/mpsc/oneshot.rs +++ b/library/std/src/sync/mpsc/oneshot.rs @@ -138,7 +138,7 @@ impl Packet { } } else { wait_token.wait(); - debug_assert!(self.state.load(Ordering::SeqCst) != EMPTY); + assert!(self.state.load(Ordering::SeqCst) != EMPTY, "packet state not empity"); } } else { // drop the signal token, since we never blocked diff --git a/library/std/src/sync/once_lock.rs b/library/std/src/sync/once_lock.rs index 813516040cdb6..9da51e48d737e 100644 --- a/library/std/src/sync/once_lock.rs +++ b/library/std/src/sync/once_lock.rs @@ -217,7 +217,7 @@ impl OnceLock { } self.initialize(f)?; - debug_assert!(self.is_initialized()); + assert!(self.is_initialized(), "bad initialization"); // SAFETY: The inner value has been initialized Ok(unsafe { self.get_unchecked() }) @@ -369,7 +369,7 @@ impl OnceLock { /// /// The value must be initialized unsafe fn get_unchecked(&self) -> &T { - debug_assert!(self.is_initialized()); + assert!(self.is_initialized(), "value not initialized"); (&*self.value.get()).assume_init_ref() } @@ -377,7 +377,7 @@ impl OnceLock { /// /// The value must be initialized unsafe fn get_unchecked_mut(&mut self) -> &mut T { - debug_assert!(self.is_initialized()); + assert!(self.is_initialized(), "value not initialized"); (&mut *self.value.get()).assume_init_mut() } } diff --git a/library/std/src/sys/itron/condvar.rs b/library/std/src/sys/itron/condvar.rs index 008cd8fb1e392..d465838fe96f6 100644 --- a/library/std/src/sys/itron/condvar.rs +++ b/library/std/src/sys/itron/condvar.rs @@ -157,7 +157,7 @@ mod waiter_queue { // Zeroness of `Waiter::task` indicates whether the `Waiter` is // linked to a queue or not. This invariant is important for // the correctness. - debug_assert_ne!(task, 0); + assert_ne!(task, 0); Self { task, priority, prev: None, next: None } } @@ -182,8 +182,8 @@ mod waiter_queue { unsafe { let waiter = waiter_ptr.as_mut(); - debug_assert!(waiter.prev.is_none()); - debug_assert!(waiter.next.is_none()); + assert!(waiter.prev.is_none()); + assert!(waiter.next.is_none()); if let Some(head) = &mut self.head { // Find the insertion position and insert `waiter` diff --git a/library/std/src/sys/itron/spin.rs b/library/std/src/sys/itron/spin.rs index 44d409444bca4..08deb5e7a9bec 100644 --- a/library/std/src/sys/itron/spin.rs +++ b/library/std/src/sys/itron/spin.rs @@ -34,7 +34,7 @@ impl SpinMutex { let _guard; if unsafe { abi::sns_dsp() } == 0 { let er = unsafe { abi::dis_dsp() }; - debug_assert!(er >= 0); + assert!(er >= 0, "unexpected error during abi::dis_dsp(): {:?}", ret); // Wait until the current processor acquires a lock. while self.locked.swap(true, Ordering::Acquire) {} @@ -95,11 +95,11 @@ impl SpinIdOnceCell { /// Assign the content without checking if it's already initialized or /// being initialized. pub unsafe fn set_unchecked(&self, (id, extra): (abi::ID, T)) { - debug_assert!(self.get().is_none()); + assert!(self.get().is_none()); // Assumption: A positive `abi::ID` fits in `usize`. - debug_assert!(id >= 0); - debug_assert!(usize::try_from(id).is_ok()); + assert!(id >= 0, "negative `abi::ID` received: {:?}", id); + assert!(usize::try_from(id).is_ok(), "fails to conver `abi::ID` to `usize`: {:?}", id); let id = id as usize; unsafe { *self.extra.get() = MaybeUninit::new(extra) }; @@ -124,7 +124,7 @@ impl SpinIdOnceCell { self.initialize(f)?; - debug_assert!(self.get().is_some()); + assert!(self.get().is_some()); // Safety: The inner value has been initialized Ok(unsafe { self.get_unchecked() }) @@ -139,8 +139,11 @@ impl SpinIdOnceCell { let (initialized_id, initialized_extra) = f()?; // Assumption: A positive `abi::ID` fits in `usize`. - debug_assert!(initialized_id >= 0); - debug_assert!(usize::try_from(initialized_id).is_ok()); + assert!(initialized_id >= 0, "negative `abi::ID`"); + assert!( + usize::try_from(initialized_id).is_ok(), + "fails to conver `abi::ID` to `usize`: {:?}" + ); let initialized_id = initialized_id as usize; // Store the initialized contents. Use the release ordering to diff --git a/library/std/src/sys/itron/thread.rs b/library/std/src/sys/itron/thread.rs index d28f57f33be20..e8bbc6aaaded1 100644 --- a/library/std/src/sys/itron/thread.rs +++ b/library/std/src/sys/itron/thread.rs @@ -202,9 +202,21 @@ impl Thread { // Get the current task ID. Panicking here would cause a resource leak, // so just abort on failure. let current_task = task::current_task_id_aborting(); - debug_assert!(usize::try_from(current_task).is_ok()); - debug_assert_ne!(current_task as usize, LIFECYCLE_INIT); - debug_assert_ne!(current_task as usize, LIFECYCLE_DETACHED); + assert!( + usize::try_from(current_task).is_ok(), + "fails to convert `current_task_id` to `usize`: {:?}", + current_task + ); + assert_ne!( + current_task as usize, LIFECYCLE_INIT, + "`current_task` is not in a valid state: {:?}", + current_task + ); + assert_ne!( + current_task as usize, LIFECYCLE_DETACHED, + "`current_task` is not in a valid state: {:?}", + current_task + ); let current_task = current_task as usize; diff --git a/library/std/src/sys/unix/locks/futex_rwlock.rs b/library/std/src/sys/unix/locks/futex_rwlock.rs index b3bbbf743f84c..e75959fbf6db8 100644 --- a/library/std/src/sys/unix/locks/futex_rwlock.rs +++ b/library/std/src/sys/unix/locks/futex_rwlock.rs @@ -95,7 +95,11 @@ impl RwLock { // It's impossible for a reader to be waiting on a read-locked RwLock, // except if there is also a writer waiting. - debug_assert!(!has_readers_waiting(state) || has_writers_waiting(state)); + assert!( + !has_readers_waiting(state) || has_writers_waiting(state), + "invalid read state: {:?}", + state + ); // Wake up a writer if we were the last reader and there's a writer waiting. if is_unlocked(state) && has_writers_waiting(state) { @@ -161,7 +165,7 @@ impl RwLock { pub unsafe fn write_unlock(&self) { let state = self.state.fetch_sub(WRITE_LOCKED, Release) - WRITE_LOCKED; - debug_assert!(is_unlocked(state)); + assert!(is_unlocked(state), "trying to write while the state is invalid: {:?}", state); if has_writers_waiting(state) || has_readers_waiting(state) { self.wake_writer_or_readers(state); diff --git a/library/std/src/sys/unix/locks/pthread_rwlock.rs b/library/std/src/sys/unix/locks/pthread_rwlock.rs index a4f06a6a032be..429f85db64b0e 100644 --- a/library/std/src/sys/unix/locks/pthread_rwlock.rs +++ b/library/std/src/sys/unix/locks/pthread_rwlock.rs @@ -143,7 +143,7 @@ impl RwLock { } #[inline] pub unsafe fn write_unlock(&self) { - debug_assert_eq!(self.num_readers.load(Ordering::Relaxed), 0); + assert_eq!(self.num_readers.load(Ordering::Relaxed), 0); assert!(*self.write_locked.get(), "trying to unlock a thread already unlocked"); *self.write_locked.get() = false; self.raw_unlock(); diff --git a/library/std/src/sys/unix/process/process_common.rs b/library/std/src/sys/unix/process/process_common.rs index bca1b65a7fc05..e281dc651b9fc 100644 --- a/library/std/src/sys/unix/process/process_common.rs +++ b/library/std/src/sys/unix/process/process_common.rs @@ -177,7 +177,7 @@ impl Command { pub fn set_arg_0(&mut self, arg: &OsStr) { // Set a new arg0 let arg = os2c(arg, &mut self.saw_nul); - debug_assert!(self.argv.0.len() > 1); + assert!(self.argv.0.len() > 1, "invalid number of argument: {:?}", self.argv.0); self.argv.0[0] = arg.as_ptr(); self.args[0] = arg; } diff --git a/library/std/src/sys/unix/thread_parker.rs b/library/std/src/sys/unix/thread_parker.rs index 9f4d4f7e736e8..9394aa6b343eb 100644 --- a/library/std/src/sys/unix/thread_parker.rs +++ b/library/std/src/sys/unix/thread_parker.rs @@ -24,22 +24,22 @@ const NOTIFIED: usize = 2; unsafe fn lock(lock: *mut libc::pthread_mutex_t) { let r = libc::pthread_mutex_lock(lock); - debug_assert_eq!(r, 0); + assert_eq!(r, 0, "unexpected error during pthread_mutex_lock: {:?}", r); } unsafe fn unlock(lock: *mut libc::pthread_mutex_t) { let r = libc::pthread_mutex_unlock(lock); - debug_assert_eq!(r, 0); + assert_eq!(r, 0, "unexpected error during pthread_mutex_ulock: {:?}", r); } unsafe fn notify_one(cond: *mut libc::pthread_cond_t) { let r = libc::pthread_cond_signal(cond); - debug_assert_eq!(r, 0); + assert_eq!(r, 0, "unexpected error during pthread_cond_signal: {:?}", r); } unsafe fn wait(cond: *mut libc::pthread_cond_t, lock: *mut libc::pthread_mutex_t) { let r = libc::pthread_cond_wait(cond, lock); - debug_assert_eq!(r, 0); + assert_eq!(r, 0, "unexpected error during pthread_cond_wait: {:?}", r); } const TIMESPEC_MAX: libc::timespec = @@ -83,7 +83,11 @@ unsafe fn wait_timeout( let timeout = now.checked_add_duration(&dur).and_then(|t| t.to_timespec()).unwrap_or(TIMESPEC_MAX); let r = libc::pthread_cond_timedwait(cond, lock, &timeout); - debug_assert!(r == libc::ETIMEDOUT || r == 0); + assert!( + r == libc::ETIMEDOUT || r == 0, + "unexpected error during pthread_cond_timedwait: {:?}", + ret + ); } pub struct Parker { diff --git a/library/std/src/sys/wasi/thread.rs b/library/std/src/sys/wasi/thread.rs index e7a6ab4be826f..06dcd792c843f 100644 --- a/library/std/src/sys/wasi/thread.rs +++ b/library/std/src/sys/wasi/thread.rs @@ -19,7 +19,7 @@ impl Thread { pub fn yield_now() { let ret = unsafe { wasi::sched_yield() }; - debug_assert_eq!(ret, Ok(())); + assert_eq!(ret, Ok(()), "unexpected error wasi::sched_yield: {:?}", ret); } pub fn set_name(_name: &CStr) { diff --git a/library/std/src/sys/wasm/alloc.rs b/library/std/src/sys/wasm/alloc.rs index 6dceb1689a8b7..16141386a753c 100644 --- a/library/std/src/sys/wasm/alloc.rs +++ b/library/std/src/sys/wasm/alloc.rs @@ -79,7 +79,7 @@ mod lock { // 1, // expected value // -1, // timeout // ); - // debug_assert!(r == 0 || r == 1); + // assert!(r == 0 || r == 1); // } // // Unfortunately though in doing so we would cause issues for the @@ -144,7 +144,7 @@ mod lock { impl Drop for DropLock { fn drop(&mut self) { let r = LOCKED.swap(0, SeqCst); - debug_assert_eq!(r, 1); + assert_eq!(r, 1, "unexpected error during swap: {:?}", r); // Note that due to the above logic we don't actually need to wake // anyone up, but if we did it'd likely look something like this: diff --git a/library/std/src/sys/wasm/atomics/thread.rs b/library/std/src/sys/wasm/atomics/thread.rs index 714b704922794..f1cfcdd47a926 100644 --- a/library/std/src/sys/wasm/atomics/thread.rs +++ b/library/std/src/sys/wasm/atomics/thread.rs @@ -32,7 +32,7 @@ impl Thread { let amt = cmp::min(i64::MAX as u128, nanos); let mut x = 0; let val = unsafe { wasm32::memory_atomic_wait32(&mut x, 0, amt as i64) }; - debug_assert_eq!(val, 2); + assert_eq!(val, 2, "unexpected value during wasm32::memory_atomic_wait32: {:?}", val); nanos -= amt; } }