From b0b7c252d79f57e47af5f677b9e551f42657c509 Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Sat, 26 Apr 2014 18:25:20 -0700 Subject: Add debug_assert and debug_assert_eq macros I also switched some `assert!` calls over to `debug_assert!`. Closes #12049. RFC: 0015-assert --- src/libstd/sync/arc.rs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'src/libstd/sync') diff --git a/src/libstd/sync/arc.rs b/src/libstd/sync/arc.rs index 7ac7700d8d3..8d6d1c222cf 100644 --- a/src/libstd/sync/arc.rs +++ b/src/libstd/sync/arc.rs @@ -86,8 +86,7 @@ impl UnsafeArc { #[inline] pub fn get(&self) -> *mut T { unsafe { - // FIXME(#12049): this needs some sort of debug assertion - if cfg!(test) { assert!((*self.data).count.load(Relaxed) > 0); } + debug_assert!((*self.data).count.load(Relaxed) > 0); return (*self.data).data.get(); } } @@ -97,8 +96,7 @@ impl UnsafeArc { #[inline] pub fn get_immut(&self) -> *T { unsafe { - // FIXME(#12049): this needs some sort of debug assertion - if cfg!(test) { assert!((*self.data).count.load(Relaxed) > 0); } + debug_assert!((*self.data).count.load(Relaxed) > 0); return (*self.data).data.get() as *T; } } @@ -125,8 +123,7 @@ impl Clone for UnsafeArc { // synchronization. // [1]: (www.boost.org/doc/libs/1_55_0/doc/html/atomic/usage_examples.html) let old_count = (*self.data).count.fetch_add(1, Relaxed); - // FIXME(#12049): this needs some sort of debug assertion - if cfg!(test) { assert!(old_count >= 1); } + debug_assert!(old_count >= 1); return UnsafeArc { data: self.data }; } } @@ -144,8 +141,7 @@ impl Drop for UnsafeArc{ // Because `fetch_sub` is already atomic, we do not need to synchronize with other // threads unless we are going to delete the object. let old_count = (*self.data).count.fetch_sub(1, Release); - // FIXME(#12049): this needs some sort of debug assertion - if cfg!(test) { assert!(old_count >= 1); } + debug_assert!(old_count >= 1); if old_count == 1 { // This fence is needed to prevent reordering of use of the data and deletion of // the data. Because it is marked `Release`, the decreasing of the reference count -- cgit 1.4.1-3-g733a5