From 18446d780f19ef2497f9102181512af3e6b71957 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Mon, 24 Mar 2025 14:57:07 -0500 Subject: [PATCH] Remove `sealed` module --- src/deque.rs | 5 ++-- src/histbuf.rs | 5 ++-- src/indexmap.rs | 14 ++++++---- src/lib.rs | 2 -- src/mpmc.rs | 14 ++++------ src/sealed.rs | 59 --------------------------------------- src/sorted_linked_list.rs | 5 ++-- src/spsc.rs | 5 ++-- src/vec/mod.rs | 7 ++--- 9 files changed, 28 insertions(+), 88 deletions(-) delete mode 100644 src/sealed.rs diff --git a/src/deque.rs b/src/deque.rs index fcc0331c..8a8e720e 100644 --- a/src/deque.rs +++ b/src/deque.rs @@ -152,8 +152,9 @@ impl Deque { /// static mut X: Deque = Deque::new(); /// ``` pub const fn new() -> Self { - // Const assert N > 0 - crate::sealed::greater_than_0::(); + const { + assert!(N > 0); + } Self { phantom: PhantomData, diff --git a/src/histbuf.rs b/src/histbuf.rs index 3ce9aa55..752c0f00 100644 --- a/src/histbuf.rs +++ b/src/histbuf.rs @@ -208,8 +208,9 @@ impl HistoryBuffer { /// ``` #[inline] pub const fn new() -> Self { - // Const assert - crate::sealed::greater_than_0::(); + const { + assert!(N > 0); + } Self { phantom: PhantomData, diff --git a/src/indexmap.rs b/src/indexmap.rs index ca36f192..54abf8e6 100644 --- a/src/indexmap.rs +++ b/src/indexmap.rs @@ -729,9 +729,10 @@ pub struct IndexMap { impl IndexMap, N> { /// Creates an empty `IndexMap`. pub const fn new() -> Self { - // Const assert - crate::sealed::greater_than_1::(); - crate::sealed::power_of_two::(); + const { + assert!(N > 1); + assert!(N.is_power_of_two()); + } Self { build_hasher: BuildHasherDefault::new(), @@ -1236,9 +1237,10 @@ where S: Default, { fn default() -> Self { - // Const assert - crate::sealed::greater_than_1::(); - crate::sealed::power_of_two::(); + const { + assert!(N > 1); + assert!(N.is_power_of_two()); + } Self { build_hasher: <_>::default(), diff --git a/src/lib.rs b/src/lib.rs index 523598c9..9a4b42f2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -221,8 +221,6 @@ pub mod spsc; #[cfg(feature = "ufmt")] mod ufmt; -mod sealed; - /// Implementation details for macros. /// Do not use. Used for macros only. Not covered by semver guarantees. #[doc(hidden)] diff --git a/src/mpmc.rs b/src/mpmc.rs index 7c90d1f5..9ef54a25 100644 --- a/src/mpmc.rs +++ b/src/mpmc.rs @@ -151,17 +151,13 @@ pub type MpMcQueue = MpMcQueueInner>; pub type MpMcQueueView = MpMcQueueInner; impl MpMcQueue { - const ASSERT: [(); 1] = [()]; - /// Creates an empty queue pub const fn new() -> Self { - // Const assert - crate::sealed::greater_than_1::(); - crate::sealed::power_of_two::(); - - // Const assert on size. - #[allow(clippy::no_effect)] - Self::ASSERT[(N >= (UintSize::MAX as usize)) as usize]; + const { + assert!(N > 1); + assert!(N.is_power_of_two()); + assert!(N < UintSize::MAX as usize); + } let mut cell_count = 0; diff --git a/src/sealed.rs b/src/sealed.rs deleted file mode 100644 index ca0b8ec1..00000000 --- a/src/sealed.rs +++ /dev/null @@ -1,59 +0,0 @@ -#[allow(dead_code, path_statements, clippy::no_effect)] -pub const fn smaller_than() { - Assert::::LESS; -} - -#[allow(dead_code, path_statements, clippy::no_effect)] -pub const fn greater_than_eq() { - Assert::::GREATER_EQ; -} - -#[allow(dead_code, path_statements, clippy::no_effect)] -pub const fn greater_than_eq_0() { - Assert::::GREATER_EQ; -} - -#[allow(dead_code, path_statements, clippy::no_effect)] -pub const fn greater_than_0() { - Assert::::GREATER; -} - -#[allow(dead_code, path_statements, clippy::no_effect)] -pub const fn greater_than_1() { - Assert::::GREATER; -} - -#[allow(dead_code, path_statements, clippy::no_effect)] -pub const fn power_of_two() { - Assert::::GREATER; - Assert::::POWER_OF_TWO; -} - -#[allow(dead_code)] -/// Const assert hack -pub struct Assert; - -#[allow(dead_code)] -impl Assert { - /// Const assert hack - pub const GREATER_EQ: usize = L - R; - - /// Const assert hack - pub const LESS_EQ: usize = R - L; - - /// Const assert hack - #[allow(clippy::erasing_op)] - pub const NOT_EQ: isize = 0 / (R as isize - L as isize); - - /// Const assert hack - pub const EQ: usize = (R - L) + (L - R); - - /// Const assert hack - pub const GREATER: usize = L - R - 1; - - /// Const assert hack - pub const LESS: usize = R - L - 1; - - /// Const assert hack - pub const POWER_OF_TWO: usize = 0 - (L & (L - 1)); -} diff --git a/src/sorted_linked_list.rs b/src/sorted_linked_list.rs index f70e1bbf..2c12ee82 100644 --- a/src/sorted_linked_list.rs +++ b/src/sorted_linked_list.rs @@ -237,8 +237,9 @@ macro_rules! impl_index_and_const_new { /// Create a new linked list. pub const fn $new_name() -> Self { - // Const assert N < MAX - crate::sealed::smaller_than::(); + const { + assert!(N < $max_val); + } let mut list = SortedLinkedList { list: OwnedSortedLinkedListStorage { diff --git a/src/spsc.rs b/src/spsc.rs index 7f156813..10a0e26e 100644 --- a/src/spsc.rs +++ b/src/spsc.rs @@ -143,8 +143,9 @@ pub type QueueView = QueueInner; impl Queue { /// Creates an empty queue with a fixed capacity of `N - 1` pub const fn new() -> Self { - // Const assert N > 1 - crate::sealed::greater_than_1::(); + const { + assert!(N > 1); + } Queue { head: AtomicUsize::new(0), diff --git a/src/vec/mod.rs b/src/vec/mod.rs index 89fae0ac..28334805 100644 --- a/src/vec/mod.rs +++ b/src/vec/mod.rs @@ -211,10 +211,9 @@ impl Vec { /// If the length of the provided array is greater than the capacity of the /// vector a compile-time error will be produced. pub fn from_array(src: [T; M]) -> Self { - // Const assert M >= 0 - crate::sealed::greater_than_eq_0::(); - // Const assert N >= M - crate::sealed::greater_than_eq::(); + const { + assert!(N >= M); + } // We've got to copy `src`, but we're functionally moving it. Don't run // any Drop code for T.