What changed, and why it matters
This commit simply deletes two internal helper code modules that were not being used anywhere in the project. It is a cleanup change with no security relevance.
No security action needed. Treat as routine code cleanup.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit removes internals/src/const_tools.rs and internals/src/parse.rs and their exports from internals/src/lib.rs. The commit message and diff show these modules were completely unused: their macros and types were referenced only within themselves. This is a straightforward dead-code removal with no functional or security changes to the library’s public API or behavior.
Changed components
internals/src/const_tools.rsinternals/src/parse.rsinternals/src/lib.rsInspect captured patch +0 / −199
diff --git a/internals/src/const_tools.rs b/internals/src/const_tools.rs
deleted file mode 100644
index 70e2b885..00000000
--- a/internals/src/const_tools.rs
+++ /dev/null
@@ -1,90 +0,0 @@
-//! Contains tools (workarounds) to make implementing `const fn`s easier.
-
-/// Copies first `$len` bytes from `$slice` and returns them as an array.
-///
-/// Returns `None` if `$len > $slice.len()`. `$len` must be (obviously) statically known.
-/// Calling from non-const context doesn't affect performance.
-#[macro_export]
-macro_rules! copy_byte_array_from_slice {
- ($slice:expr, $len:expr) => {
- if $len > $slice.len() {
- None
- } else {
- let mut array = [0u8; $len];
- // Note: produces same assemble as copy_from_slice
- let mut i = 0;
- while i < $len {
- array[i] = $slice[i];
- i += 1;
- }
- Some(array)
- }
- };
-}
-pub use copy_byte_array_from_slice;
-
-/// Concatenates two byte slices or byte arrays (or combination) to a single array.
-///
-/// # Panics
-///
-/// This macro panics if `$len` is not equal to the sum of `$a.len()` and `$b.len()`.
-#[macro_export]
-macro_rules! concat_bytes_to_arr {
- ($a:expr, $b:expr, $len:expr) => {{
- // avoid repeated eval
- let a = $a;
- let b = $b;
-
- #[allow(unconditional_panic)]
- let _ = [(); 1][($len != a.len() + b.len()) as usize];
-
- let mut output = [0u8; $len];
- let mut i = 0;
- while i < a.len() {
- output[i] = a[i];
- i += 1;
- }
- while i < a.len() + b.len() {
- output[i] = b[i - a.len()];
- i += 1;
- }
- output
- }};
-}
-pub use concat_bytes_to_arr;
-
-#[macro_export]
-/// Enables const fn in specified Rust version
-macro_rules! cond_const {
- ($($(#[$attr:meta])* $vis:vis const(in $version:tt) fn $name:ident$(<$($gen:tt)*>)?($($args:tt)*) $(-> $ret:ty)? $body:block)+ ) => {
- $(
- $crate::rust_version::rust_version! {
- if >= $version {
- $(#[$attr])*
- #[doc = concat!("\nNote: the function is only `const` in Rust ", stringify!($version), ".")]
- $vis const fn $name$(<$($gen)*>)?($($args)*) $(-> $ret)? $body
- } else {
- $(#[$attr])*
- #[doc = concat!("\nNote: the function is `const` in Rust ", stringify!($version), ".")]
- $vis fn $name$(<$($gen)*>)?($($args)*) $(-> $ret)? $body
- }
- }
- )+
- };
- ($($(#[$attr:meta])* $vis:vis const(in $version:tt) unsafe fn $name:ident$(<$($gen:tt)*>)?($($args:tt)*) $(-> $ret:ty)? $body:block)+ ) => {
- $(
- $crate::rust_version::rust_version! {
- if >= $version {
- $(#[$attr])*
- #[doc = concat!("\nNote: the function is only `const` in Rust ", stringify!($version), ".")]
- $vis const unsafe fn $name$(<$($gen)*>)?($($args)*) $(-> $ret)? $body
- } else {
- $(#[$attr])*
- #[doc = concat!("\nNote: the function is `const` in Rust ", stringify!($version), ".")]
- $vis unsafe fn $name$(<$($gen)*>)?($($args)*) $(-> $ret)? $body
- }
- }
- )+
- };
-}
-pub use cond_const;
diff --git a/internals/src/lib.rs b/internals/src/lib.rs
index e0fcc659..4335b242 100644
--- a/internals/src/lib.rs
+++ b/internals/src/lib.rs
@@ -38,10 +38,8 @@ pub mod _export {
pub mod array;
pub mod array_vec;
-pub mod const_tools;
pub mod error;
pub mod macros;
-mod parse;
pub mod script;
pub mod slice;
#[cfg(feature = "serde")]
diff --git a/internals/src/parse.rs b/internals/src/parse.rs
deleted file mode 100644
index 363006e9..00000000
--- a/internals/src/parse.rs
+++ /dev/null
@@ -1,107 +0,0 @@
-//! Support for parsing strings.
-
-// Impls a single TryFrom conversion
-#[doc(hidden)]
-#[macro_export]
-macro_rules! impl_try_from_stringly {
- ($from:ty, $to:ty, $error:ty, $func:expr) => {
- $(#[$attr])?
- impl core::convert::TryFrom<$from> for $to {
- type Error = $error;
-
- fn try_from(s: $from) -> core::result::Result<Self, Self::Error> {
- $func(AsRef::<str>::as_ref(s)).map_err(|source| <$error>::new(s, source))
- }
- }
-
- }
-}
-
-/// Implements conversions from various string types.
-///
-/// This macro implements `FromStr` as well as `TryFrom<{stringly}` where `{stringly}` is one of
-/// these types:
-///
-/// * `&str`
-/// * `String`
-/// * `Box<str>`
-/// * `Cow<'_, str>`
-///
-/// The last three are only available with `alloc` feature turned on.
-#[macro_export]
-macro_rules! impl_parse {
- ($type:ty, $descr:expr, $func:expr, $vis:vis $error:ident, $error_source:ty $(, $error_derive:path)*) => {
- $crate::parse_error_type!($vis $error, $error_source, $descr $(, $error_derive)*);
-
- impl core::str::FromStr for $type {
- type Err = $error;
-
- fn from_str(s: &str) -> core::result::Result<Self, Self::Err> {
- $func(s).map_err(|source| <$error>::new(s, source))
- }
- }
-
- impl_try_from_stringly!(&str);
-
- #[cfg(feature = "alloc")]
- impl_try_from_stringly!(alloc::string::String, $type, $error, $func);
- #[cfg(feature = "alloc")]
- impl_try_from_stringly!(alloc::borrow::Cow<'_, str>, $type, $error, $func);
- #[cfg(feature = "alloc")]
- impl_try_from_stringly!(alloc::boxed::Box<str>, $type, $error, $func);
- }
-}
-
-/// Implements conversions from various string types as well as `serde` (de)serialization.
-///
-/// This calls `impl_parse` macro and implements serde deserialization by expecting and parsing a
-/// string and serialization by outputting a string.
-#[macro_export]
-macro_rules! impl_parse_and_serde {
- ($type:ty, $descr:expr, $func:expr, $error:ident, $error_source:ty $(, $error_derive:path)*) => {
- impl_parse!($type, $descr, $func, $error, $error_source $(, $error_derive)*);
-
- // We don't use `serde_string_impl` because we want to avoid allocating input.
- #[cfg(feature = "serde")]
- impl<'de> $crate::serde::Deserialize<'de> for $type {
- fn deserialize<D>(deserializer: D) -> core::result::Result<$name, D::Error>
- where
- D: $crate::serde::de::Deserializer<'de>,
- {
- use core::fmt::{self, Formatter};
- use core::str::FromStr;
-
- struct Visitor;
- impl<'de> $crate::serde::de::Visitor<'de> for Visitor {
- type Value = $name;
-
- fn expecting(&self, f: &mut Formatter) -> core::fmt::Result {
- f.write_str($descr)
- }
-
- fn visit_str<E>(self, s: &str) -> core::result::Result<Self::Value, E>
- where
- E: $crate::serde::de::Error,
- {
- s.parse().map_err(|error| {
- $crate::serde::IntoDeError::try_into_de_error(error)
- .unwrap_or_else(|_| E::invalid_value(Unexpected::Str(s), &self))
- })
- }
- }
-
- deserializer.deserialize_str(Visitor)
- }
- }
-
- #[cfg(feature = "serde")]
- impl $crate::serde::Serialize for $name {
- fn serialize<S>(&self, serializer: S) -> core::result::Result<S::Ok, S::Error>
- where
- S: $crate::serde::Serializer,
- {
- serializer.collect_str(&self)
- }
- }
- }
-}
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.