From c01e9e7e7729c12ca8c7098049347bf11547a50a Mon Sep 17 00:00:00 2001 From: Karan Jain Date: Thu, 22 Jan 2026 15:59:39 -0800 Subject: [PATCH 1/2] clippy: add missing_const_for_fn lint to make a bunch of methods const --- Cargo.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index a8b581a..794dcc7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,3 +21,6 @@ bincode = ["dep:bincode"] [dev-dependencies] serde_json = "1" + +[lints.clippy] +missing_const_for_fn = "warn" From efc62b350274e82d9b19a2bf65df41447d11c3a5 Mon Sep 17 00:00:00 2001 From: Karan Jain Date: Thu, 22 Jan 2026 16:00:14 -0800 Subject: [PATCH 2/2] cargo clippy --fix --- src/lib.rs | 8 ++++---- src/nonzero.rs | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 07465bb..3b3ba25 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -278,7 +278,7 @@ impl NonEmpty { /// *head *= 42; /// assert_eq!(non_empty.first(), &42); /// ``` - pub fn first_mut(&mut self) -> &mut T { + pub const fn first_mut(&mut self) -> &mut T { &mut self.head } @@ -339,17 +339,17 @@ impl NonEmpty { } /// Get the length of the list. - pub fn len(&self) -> usize { + pub const fn len(&self) -> usize { self.tail.len() + 1 } /// Gets the length of the list as a NonZeroUsize. - pub fn len_nonzero(&self) -> NonZeroUsize { + pub const fn len_nonzero(&self) -> NonZeroUsize { unsafe { NonZeroUsize::new_unchecked(self.tail.len().saturating_add(1)) } } /// Get the capacity of the list. - pub fn capacity(&self) -> NonZeroUsize { + pub const fn capacity(&self) -> NonZeroUsize { NonZeroUsize::MIN.saturating_add(self.tail.capacity()) } diff --git a/src/nonzero.rs b/src/nonzero.rs index 243eb4c..4315e31 100644 --- a/src/nonzero.rs +++ b/src/nonzero.rs @@ -14,12 +14,12 @@ pub struct NonEmpty(super::NonEmpty); impl NonEmpty { /// Get the length of the list. - pub fn len(&self) -> NonZeroUsize { + pub const fn len(&self) -> NonZeroUsize { unsafe { NonZeroUsize::new_unchecked(self.0.tail.len() + 1) } } /// Get the capacity of the list. - pub fn capacity(&self) -> NonZeroUsize { + pub const fn capacity(&self) -> NonZeroUsize { unsafe { NonZeroUsize::new_unchecked(self.0.tail.capacity() + 1) } }