Remove unused types and macros from internals::serde
What changed, and why it matters
This commit simply deletes unused code—an internal trait and a macro for serde serialization helpers. There is no bug fix, behavior change, or security patch here. It is a routine cleanup that removes dead code.
No security action needed. Treat as normal code-cleanup/refactoring.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit removes IntoDeError trait and its Infallible/ParseIntError implementations, plus the serde_struct_human_string_impl macro from internals/src/serde.rs. The commit message explicitly states these are entirely unused, neither privately within internals nor publicly by other crates. No functional or security-relevant change is introduced.
Changed components
internals/src/serde.rsInspect captured patch +0 / −231
diff --git a/internals/src/serde.rs b/internals/src/serde.rs
index b6619b6c..1db364ad 100644
--- a/internals/src/serde.rs
+++ b/internals/src/serde.rs
@@ -3,67 +3,6 @@
#[doc(hidden)]
pub use serde::{de, ser, Deserialize, Deserializer, Serialize, Serializer};
-/// Converts given error type to a type implementing [`de::Error`].
-///
-/// This is used in [`Deserialize`] implementations to convert specialized errors into serde
-/// errors.
-pub trait IntoDeError: Sized {
- /// Converts to deserializer error possibly outputting vague message.
- ///
- /// This method is allowed to return a vague error message if the error type doesn't contain
- /// enough information to explain the error precisely.
- fn into_de_error<E: de::Error>(self, expected: Option<&dyn de::Expected>) -> E;
-
- /// Converts to deserializer error without outputting vague message.
- ///
- /// If the error type doesn't contain enough information to explain the error precisely this
- /// should return `Err(self)` allowing the caller to use its information instead.
- ///
- /// # Errors
- ///
- /// Returns `Err(self)` if the error cannot be converted to a deserializer error.
- fn try_into_de_error<E>(self, expected: Option<&dyn de::Expected>) -> Result<E, Self>
- where
- E: de::Error,
- {
- Ok(self.into_de_error(expected))
- }
-}
-
-mod impls {
- use super::{de, IntoDeError};
-
- impl IntoDeError for core::convert::Infallible {
- fn into_de_error<E: de::Error>(self, _expected: Option<&dyn de::Expected>) -> E {
- match self {}
- }
- }
-
- impl IntoDeError for core::num::ParseIntError {
- fn into_de_error<E: de::Error>(self, expected: Option<&dyn de::Expected>) -> E {
- self.try_into_de_error(expected).unwrap_or_else(|_| {
- let expected = expected.unwrap_or(&"an integer");
-
- E::custom(format_args!("invalid string, expected {}", expected))
- })
- }
-
- fn try_into_de_error<E>(self, expected: Option<&dyn de::Expected>) -> Result<E, Self>
- where
- E: de::Error,
- {
- use core::num::IntErrorKind::Empty;
-
- let expected = expected.unwrap_or(&"an integer");
-
- match self.kind() {
- Empty => Ok(E::invalid_value(de::Unexpected::Str(""), expected)),
- _ => Err(self),
- }
- }
- }
-}
-
/// Implements `serde::Serialize` by way of `Display`.
///
/// `$name` is required to implement `core::fmt::Display`.
@@ -126,173 +65,3 @@ macro_rules! serde_string_impl {
$crate::serde_string_serialize_impl!($name, $expecting);
};
}
-
-/// A combination macro where the human-readable serialization is done like
-/// `serde_string_impl` and the non-human-readable impl is done as a struct.
-#[macro_export]
-macro_rules! serde_struct_human_string_impl {
- ($name:ident, $expecting:literal, $($fe:ident),*) => (
- impl<'de> $crate::serde::Deserialize<'de> for $name {
- fn deserialize<D>(deserializer: D) -> core::result::Result<$name, D::Error>
- where
- D: $crate::serde::de::Deserializer<'de>,
- {
- if deserializer.is_human_readable() {
- use core::fmt::Formatter;
-
- 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($expecting)
- }
-
- fn visit_str<E>(self, v: &str) -> core::result::Result<Self::Value, E>
- where
- E: $crate::serde::de::Error,
- {
- v.parse::<$name>().map_err(E::custom)
- }
-
- }
-
- deserializer.deserialize_str(Visitor)
- } else {
- use core::fmt::Formatter;
- use $crate::serde::de::IgnoredAny;
-
- #[allow(non_camel_case_types)]
- enum Enum { Unknown__Field, $($fe),* }
-
- struct EnumVisitor;
- impl<'de> $crate::serde::de::Visitor<'de> for EnumVisitor {
- type Value = Enum;
-
- fn expecting(&self, f: &mut Formatter) -> core::fmt::Result {
- f.write_str("a field name")
- }
-
- fn visit_str<E>(self, v: &str) -> core::result::Result<Self::Value, E>
- where
- E: $crate::serde::de::Error,
- {
- match v {
- $(
- stringify!($fe) => Ok(Enum::$fe)
- ),*,
- _ => Ok(Enum::Unknown__Field)
- }
- }
- }
-
- impl<'de> $crate::serde::Deserialize<'de> for Enum {
- fn deserialize<D>(deserializer: D) -> core::result::Result<Self, D::Error>
- where
- D: $crate::serde::de::Deserializer<'de>,
- {
- deserializer.deserialize_str(EnumVisitor)
- }
- }
-
- 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("a struct")
- }
-
- fn visit_seq<V>(self, mut seq: V) -> core::result::Result<Self::Value, V::Error>
- where
- V: $crate::serde::de::SeqAccess<'de>,
- {
- use $crate::serde::de::Error;
-
- let length = 0;
- $(
- let $fe = seq.next_element()?.ok_or_else(|| {
- Error::invalid_length(length, &self)
- })?;
- #[allow(unused_variables)]
- let length = length + 1;
- )*
-
- let ret = $name {
- $($fe),*
- };
-
- Ok(ret)
- }
-
- fn visit_map<A>(self, mut map: A) -> core::result::Result<Self::Value, A::Error>
- where
- A: $crate::serde::de::MapAccess<'de>,
- {
- use $crate::serde::de::Error;
-
- $(let mut $fe = None;)*
-
- loop {
- match map.next_key::<Enum>()? {
- Some(Enum::Unknown__Field) => {
- map.next_value::<IgnoredAny>()?;
- }
- $(
- Some(Enum::$fe) => {
- $fe = Some(map.next_value()?);
- }
- )*
- None => { break; }
- }
- }
-
- $(
- let $fe = match $fe {
- Some(x) => x,
- None => return Err(A::Error::missing_field(stringify!($fe))),
- };
- )*
-
- let ret = $name {
- $($fe),*
- };
-
- Ok(ret)
- }
- }
- // end type defs
-
- static FIELDS: &'static [&'static str] = &[$(stringify!($fe)),*];
-
- deserializer.deserialize_struct(stringify!($name), FIELDS, Visitor)
- }
- }
- }
-
- impl $crate::serde::Serialize for $name {
- fn serialize<S>(&self, serializer: S) -> core::result::Result<S::Ok, S::Error>
- where
- S: $crate::serde::Serializer,
- {
- if serializer.is_human_readable() {
- serializer.collect_str(&self)
- } else {
- use $crate::serde::ser::SerializeStruct;
-
- // Only used to get the struct length.
- static FIELDS: &'static [&'static str] = &[$(stringify!($fe)),*];
-
- let mut st = serializer.serialize_struct(stringify!($name), FIELDS.len())?;
-
- $(
- st.serialize_field(stringify!($fe), &self.$fe)?;
- )*
-
- st.end()
- }
- }
- }
- )
-}
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.