Upgrade rust/crates/serde to 1.0.123

Test: make
Change-Id: Icf792951389636d98b4d7bb4cf806c58be295873
diff --git a/src/de/from_primitive.rs b/src/de/from_primitive.rs
deleted file mode 100644
index 544f3f1..0000000
--- a/src/de/from_primitive.rs
+++ /dev/null
@@ -1,260 +0,0 @@
-use lib::*;
-
-macro_rules! int_to_int {
-    ($dst:ident, $n:ident) => {
-        if $dst::min_value() as i64 <= $n as i64 && $n as i64 <= $dst::max_value() as i64 {
-            Some($n as $dst)
-        } else {
-            None
-        }
-    };
-}
-
-macro_rules! int_to_uint {
-    ($dst:ident, $n:ident) => {
-        if 0 <= $n && $n as u64 <= $dst::max_value() as u64 {
-            Some($n as $dst)
-        } else {
-            None
-        }
-    };
-}
-
-macro_rules! uint_to {
-    ($dst:ident, $n:ident) => {
-        if $n as u64 <= $dst::max_value() as u64 {
-            Some($n as $dst)
-        } else {
-            None
-        }
-    };
-}
-
-pub trait FromPrimitive: Sized {
-    fn from_i8(n: i8) -> Option<Self>;
-    fn from_i16(n: i16) -> Option<Self>;
-    fn from_i32(n: i32) -> Option<Self>;
-    fn from_i64(n: i64) -> Option<Self>;
-    fn from_u8(n: u8) -> Option<Self>;
-    fn from_u16(n: u16) -> Option<Self>;
-    fn from_u32(n: u32) -> Option<Self>;
-    fn from_u64(n: u64) -> Option<Self>;
-}
-
-macro_rules! impl_from_primitive_for_int {
-    ($t:ident) => {
-        impl FromPrimitive for $t {
-            #[inline]
-            fn from_i8(n: i8) -> Option<Self> {
-                int_to_int!($t, n)
-            }
-            #[inline]
-            fn from_i16(n: i16) -> Option<Self> {
-                int_to_int!($t, n)
-            }
-            #[inline]
-            fn from_i32(n: i32) -> Option<Self> {
-                int_to_int!($t, n)
-            }
-            #[inline]
-            fn from_i64(n: i64) -> Option<Self> {
-                int_to_int!($t, n)
-            }
-            #[inline]
-            fn from_u8(n: u8) -> Option<Self> {
-                uint_to!($t, n)
-            }
-            #[inline]
-            fn from_u16(n: u16) -> Option<Self> {
-                uint_to!($t, n)
-            }
-            #[inline]
-            fn from_u32(n: u32) -> Option<Self> {
-                uint_to!($t, n)
-            }
-            #[inline]
-            fn from_u64(n: u64) -> Option<Self> {
-                uint_to!($t, n)
-            }
-        }
-    };
-}
-
-macro_rules! impl_from_primitive_for_uint {
-    ($t:ident) => {
-        impl FromPrimitive for $t {
-            #[inline]
-            fn from_i8(n: i8) -> Option<Self> {
-                int_to_uint!($t, n)
-            }
-            #[inline]
-            fn from_i16(n: i16) -> Option<Self> {
-                int_to_uint!($t, n)
-            }
-            #[inline]
-            fn from_i32(n: i32) -> Option<Self> {
-                int_to_uint!($t, n)
-            }
-            #[inline]
-            fn from_i64(n: i64) -> Option<Self> {
-                int_to_uint!($t, n)
-            }
-            #[inline]
-            fn from_u8(n: u8) -> Option<Self> {
-                uint_to!($t, n)
-            }
-            #[inline]
-            fn from_u16(n: u16) -> Option<Self> {
-                uint_to!($t, n)
-            }
-            #[inline]
-            fn from_u32(n: u32) -> Option<Self> {
-                uint_to!($t, n)
-            }
-            #[inline]
-            fn from_u64(n: u64) -> Option<Self> {
-                uint_to!($t, n)
-            }
-        }
-    };
-}
-
-macro_rules! impl_from_primitive_for_float {
-    ($t:ident) => {
-        impl FromPrimitive for $t {
-            #[inline]
-            fn from_i8(n: i8) -> Option<Self> {
-                Some(n as Self)
-            }
-            #[inline]
-            fn from_i16(n: i16) -> Option<Self> {
-                Some(n as Self)
-            }
-            #[inline]
-            fn from_i32(n: i32) -> Option<Self> {
-                Some(n as Self)
-            }
-            #[inline]
-            fn from_i64(n: i64) -> Option<Self> {
-                Some(n as Self)
-            }
-            #[inline]
-            fn from_u8(n: u8) -> Option<Self> {
-                Some(n as Self)
-            }
-            #[inline]
-            fn from_u16(n: u16) -> Option<Self> {
-                Some(n as Self)
-            }
-            #[inline]
-            fn from_u32(n: u32) -> Option<Self> {
-                Some(n as Self)
-            }
-            #[inline]
-            fn from_u64(n: u64) -> Option<Self> {
-                Some(n as Self)
-            }
-        }
-    };
-}
-
-impl_from_primitive_for_int!(isize);
-impl_from_primitive_for_int!(i8);
-impl_from_primitive_for_int!(i16);
-impl_from_primitive_for_int!(i32);
-impl_from_primitive_for_int!(i64);
-impl_from_primitive_for_uint!(usize);
-impl_from_primitive_for_uint!(u8);
-impl_from_primitive_for_uint!(u16);
-impl_from_primitive_for_uint!(u32);
-impl_from_primitive_for_uint!(u64);
-impl_from_primitive_for_float!(f32);
-impl_from_primitive_for_float!(f64);
-
-serde_if_integer128! {
-    impl FromPrimitive for i128 {
-        #[inline]
-        fn from_i8(n: i8) -> Option<Self> {
-            Some(n as i128)
-        }
-        #[inline]
-        fn from_i16(n: i16) -> Option<Self> {
-            Some(n as i128)
-        }
-        #[inline]
-        fn from_i32(n: i32) -> Option<Self> {
-            Some(n as i128)
-        }
-        #[inline]
-        fn from_i64(n: i64) -> Option<Self> {
-            Some(n as i128)
-        }
-        #[inline]
-        fn from_u8(n: u8) -> Option<Self> {
-            Some(n as i128)
-        }
-        #[inline]
-        fn from_u16(n: u16) -> Option<Self> {
-            Some(n as i128)
-        }
-        #[inline]
-        fn from_u32(n: u32) -> Option<Self> {
-            Some(n as i128)
-        }
-        #[inline]
-        fn from_u64(n: u64) -> Option<Self> {
-            Some(n as i128)
-        }
-    }
-
-    impl FromPrimitive for u128 {
-        #[inline]
-        fn from_i8(n: i8) -> Option<Self> {
-            if n >= 0 {
-                Some(n as u128)
-            } else {
-                None
-            }
-        }
-        #[inline]
-        fn from_i16(n: i16) -> Option<Self> {
-            if n >= 0 {
-                Some(n as u128)
-            } else {
-                None
-            }
-        }
-        #[inline]
-        fn from_i32(n: i32) -> Option<Self> {
-            if n >= 0 {
-                Some(n as u128)
-            } else {
-                None
-            }
-        }
-        #[inline]
-        fn from_i64(n: i64) -> Option<Self> {
-            if n >= 0 {
-                Some(n as u128)
-            } else {
-                None
-            }
-        }
-        #[inline]
-        fn from_u8(n: u8) -> Option<Self> {
-            Some(n as u128)
-        }
-        #[inline]
-        fn from_u16(n: u16) -> Option<Self> {
-            Some(n as u128)
-        }
-        #[inline]
-        fn from_u32(n: u32) -> Option<Self> {
-            Some(n as u128)
-        }
-        #[inline]
-        fn from_u64(n: u64) -> Option<Self> {
-            Some(n as u128)
-        }
-    }
-}
diff --git a/src/de/ignored_any.rs b/src/de/ignored_any.rs
index 68a644e..1d50f5e 100644
--- a/src/de/ignored_any.rs
+++ b/src/de/ignored_any.rs
@@ -130,12 +130,28 @@
         Ok(IgnoredAny)
     }
 
+    serde_if_integer128! {
+        #[inline]
+        fn visit_i128<E>(self, x: i128) -> Result<Self::Value, E> {
+            let _ = x;
+            Ok(IgnoredAny)
+        }
+    }
+
     #[inline]
     fn visit_u64<E>(self, x: u64) -> Result<Self::Value, E> {
         let _ = x;
         Ok(IgnoredAny)
     }
 
+    serde_if_integer128! {
+        #[inline]
+        fn visit_u128<E>(self, x: u128) -> Result<Self::Value, E> {
+            let _ = x;
+            Ok(IgnoredAny)
+        }
+    }
+
     #[inline]
     fn visit_f64<E>(self, x: f64) -> Result<Self::Value, E> {
         let _ = x;
diff --git a/src/de/impls.rs b/src/de/impls.rs
index 4d100d6..409f6cb 100644
--- a/src/de/impls.rs
+++ b/src/de/impls.rs
@@ -7,11 +7,10 @@
 #[cfg(any(core_duration, feature = "std", feature = "alloc"))]
 use de::MapAccess;
 
-use __private::de::InPlaceSeed;
-use de::from_primitive::FromPrimitive;
+use seed::InPlaceSeed;
 
 #[cfg(any(feature = "std", feature = "alloc"))]
-use __private::de::size_hint;
+use __private::size_hint;
 
 ////////////////////////////////////////////////////////////////////////////////
 
@@ -81,38 +80,8 @@
 
 ////////////////////////////////////////////////////////////////////////////////
 
-macro_rules! visit_integer_method {
-    ($src_ty:ident, $method:ident, $from_method:ident, $group:ident, $group_ty:ident) => {
-        #[inline]
-        fn $method<E>(self, v: $src_ty) -> Result<Self::Value, E>
-        where
-            E: Error,
-        {
-            match FromPrimitive::$from_method(v) {
-                Some(v) => Ok(v),
-                None => Err(Error::invalid_value(
-                    Unexpected::$group(v as $group_ty),
-                    &self,
-                )),
-            }
-        }
-    };
-}
-
-macro_rules! visit_float_method {
-    ($src_ty:ident, $method:ident) => {
-        #[inline]
-        fn $method<E>(self, v: $src_ty) -> Result<Self::Value, E>
-        where
-            E: Error,
-        {
-            Ok(v as Self::Value)
-        }
-    };
-}
-
 macro_rules! impl_deserialize_num {
-    ($ty:ident, $method:ident, $($visit:ident),*) => {
+    ($ty:ident, $deserialize:ident $($methods:tt)*) => {
         impl<'de> Deserialize<'de> for $ty {
             #[inline]
             fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
@@ -128,131 +97,221 @@
                         formatter.write_str(stringify!($ty))
                     }
 
-                    $(
-                        impl_deserialize_num!($visit $ty);
-                    )*
+                    $($methods)*
                 }
 
-                deserializer.$method(PrimitiveVisitor)
+                deserializer.$deserialize(PrimitiveVisitor)
             }
         }
     };
-
-    (integer $ty:ident) => {
-        visit_integer_method!(i8, visit_i8, from_i8, Signed, i64);
-        visit_integer_method!(i16, visit_i16, from_i16, Signed, i64);
-        visit_integer_method!(i32, visit_i32, from_i32, Signed, i64);
-        visit_integer_method!(i64, visit_i64, from_i64, Signed, i64);
-
-        visit_integer_method!(u8, visit_u8, from_u8, Unsigned, u64);
-        visit_integer_method!(u16, visit_u16, from_u16, Unsigned, u64);
-        visit_integer_method!(u32, visit_u32, from_u32, Unsigned, u64);
-        visit_integer_method!(u64, visit_u64, from_u64, Unsigned, u64);
-    };
-
-    (float $ty:ident) => {
-        visit_float_method!(f32, visit_f32);
-        visit_float_method!(f64, visit_f64);
-    };
 }
 
-impl_deserialize_num!(i8, deserialize_i8, integer);
-impl_deserialize_num!(i16, deserialize_i16, integer);
-impl_deserialize_num!(i32, deserialize_i32, integer);
-impl_deserialize_num!(i64, deserialize_i64, integer);
-impl_deserialize_num!(isize, deserialize_i64, integer);
-
-impl_deserialize_num!(u8, deserialize_u8, integer);
-impl_deserialize_num!(u16, deserialize_u16, integer);
-impl_deserialize_num!(u32, deserialize_u32, integer);
-impl_deserialize_num!(u64, deserialize_u64, integer);
-impl_deserialize_num!(usize, deserialize_u64, integer);
-
-impl_deserialize_num!(f32, deserialize_f32, integer, float);
-impl_deserialize_num!(f64, deserialize_f64, integer, float);
-
-serde_if_integer128! {
-    impl<'de> Deserialize<'de> for i128 {
+macro_rules! num_self {
+    ($ty:ident : $visit:ident) => {
         #[inline]
-        fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
+        fn $visit<E>(self, v: $ty) -> Result<Self::Value, E>
         where
-            D: Deserializer<'de>,
+            E: Error,
         {
-            struct PrimitiveVisitor;
+            Ok(v)
+        }
+    };
+}
 
-            impl<'de> Visitor<'de> for PrimitiveVisitor {
-                type Value = i128;
+macro_rules! num_as_self {
+    ($($ty:ident : $visit:ident)*) => {
+        $(
+            #[inline]
+            fn $visit<E>(self, v: $ty) -> Result<Self::Value, E>
+            where
+                E: Error,
+            {
+                Ok(v as Self::Value)
+            }
+        )*
+    };
+}
 
-                fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
-                    formatter.write_str("i128")
-                }
-
-                impl_deserialize_num!(integer i128);
-
-                #[inline]
-                fn visit_i128<E>(self, v: i128) -> Result<Self::Value, E>
-                where
-                    E: Error,
-                {
-                    Ok(v)
-                }
-
-                #[inline]
-                fn visit_u128<E>(self, v: u128) -> Result<Self::Value, E>
-                where
-                    E: Error,
-                {
-                    if v <= i128::max_value() as u128 {
-                        Ok(v as i128)
-                    } else {
-                        Err(Error::invalid_value(Unexpected::Other("u128"), &self))
-                    }
+macro_rules! int_to_int {
+    ($($ty:ident : $visit:ident)*) => {
+        $(
+            #[inline]
+            fn $visit<E>(self, v: $ty) -> Result<Self::Value, E>
+            where
+                E: Error,
+            {
+                if Self::Value::min_value() as i64 <= v as i64 && v as i64 <= Self::Value::max_value() as i64 {
+                    Ok(v as Self::Value)
+                } else {
+                    Err(Error::invalid_value(Unexpected::Signed(v as i64), &self))
                 }
             }
+        )*
+    };
+}
 
-            deserializer.deserialize_i128(PrimitiveVisitor)
+macro_rules! int_to_uint {
+    ($($ty:ident : $visit:ident)*) => {
+        $(
+            #[inline]
+            fn $visit<E>(self, v: $ty) -> Result<Self::Value, E>
+            where
+                E: Error,
+            {
+                if 0 <= v && v as u64 <= Self::Value::max_value() as u64 {
+                    Ok(v as Self::Value)
+                } else {
+                    Err(Error::invalid_value(Unexpected::Signed(v as i64), &self))
+                }
+            }
+        )*
+    };
+}
+
+macro_rules! uint_to_self {
+    ($($ty:ident : $visit:ident)*) => {
+        $(
+            #[inline]
+            fn $visit<E>(self, v: $ty) -> Result<Self::Value, E>
+            where
+                E: Error,
+            {
+                if v as u64 <= Self::Value::max_value() as u64 {
+                    Ok(v as Self::Value)
+                } else {
+                    Err(Error::invalid_value(Unexpected::Unsigned(v as u64), &self))
+                }
+            }
+        )*
+    };
+}
+
+impl_deserialize_num! {
+    i8, deserialize_i8
+    num_self!(i8:visit_i8);
+    int_to_int!(i16:visit_i16 i32:visit_i32 i64:visit_i64);
+    uint_to_self!(u8:visit_u8 u16:visit_u16 u32:visit_u32 u64:visit_u64);
+}
+
+impl_deserialize_num! {
+    i16, deserialize_i16
+    num_self!(i16:visit_i16);
+    num_as_self!(i8:visit_i8);
+    int_to_int!(i32:visit_i32 i64:visit_i64);
+    uint_to_self!(u8:visit_u8 u16:visit_u16 u32:visit_u32 u64:visit_u64);
+}
+
+impl_deserialize_num! {
+    i32, deserialize_i32
+    num_self!(i32:visit_i32);
+    num_as_self!(i8:visit_i8 i16:visit_i16);
+    int_to_int!(i64:visit_i64);
+    uint_to_self!(u8:visit_u8 u16:visit_u16 u32:visit_u32 u64:visit_u64);
+}
+
+impl_deserialize_num! {
+    i64, deserialize_i64
+    num_self!(i64:visit_i64);
+    num_as_self!(i8:visit_i8 i16:visit_i16 i32:visit_i32);
+    uint_to_self!(u8:visit_u8 u16:visit_u16 u32:visit_u32 u64:visit_u64);
+}
+
+impl_deserialize_num! {
+    isize, deserialize_i64
+    num_as_self!(i8:visit_i8 i16:visit_i16);
+    int_to_int!(i32:visit_i32 i64:visit_i64);
+    uint_to_self!(u8:visit_u8 u16:visit_u16 u32:visit_u32 u64:visit_u64);
+}
+
+impl_deserialize_num! {
+    u8, deserialize_u8
+    num_self!(u8:visit_u8);
+    int_to_uint!(i8:visit_i8 i16:visit_i16 i32:visit_i32 i64:visit_i64);
+    uint_to_self!(u16:visit_u16 u32:visit_u32 u64:visit_u64);
+}
+
+impl_deserialize_num! {
+    u16, deserialize_u16
+    num_self!(u16:visit_u16);
+    num_as_self!(u8:visit_u8);
+    int_to_uint!(i8:visit_i8 i16:visit_i16 i32:visit_i32 i64:visit_i64);
+    uint_to_self!(u32:visit_u32 u64:visit_u64);
+}
+
+impl_deserialize_num! {
+    u32, deserialize_u32
+    num_self!(u32:visit_u32);
+    num_as_self!(u8:visit_u8 u16:visit_u16);
+    int_to_uint!(i8:visit_i8 i16:visit_i16 i32:visit_i32 i64:visit_i64);
+    uint_to_self!(u64:visit_u64);
+}
+
+impl_deserialize_num! {
+    u64, deserialize_u64
+    num_self!(u64:visit_u64);
+    num_as_self!(u8:visit_u8 u16:visit_u16 u32:visit_u32);
+    int_to_uint!(i8:visit_i8 i16:visit_i16 i32:visit_i32 i64:visit_i64);
+}
+
+impl_deserialize_num! {
+    usize, deserialize_u64
+    num_as_self!(u8:visit_u8 u16:visit_u16);
+    int_to_uint!(i8:visit_i8 i16:visit_i16 i32:visit_i32 i64:visit_i64);
+    uint_to_self!(u32:visit_u32 u64:visit_u64);
+}
+
+impl_deserialize_num! {
+    f32, deserialize_f32
+    num_self!(f32:visit_f32);
+    num_as_self!(f64:visit_f64);
+    num_as_self!(i8:visit_i8 i16:visit_i16 i32:visit_i32 i64:visit_i64);
+    num_as_self!(u8:visit_u8 u16:visit_u16 u32:visit_u32 u64:visit_u64);
+}
+
+impl_deserialize_num! {
+    f64, deserialize_f64
+    num_self!(f64:visit_f64);
+    num_as_self!(f32:visit_f32);
+    num_as_self!(i8:visit_i8 i16:visit_i16 i32:visit_i32 i64:visit_i64);
+    num_as_self!(u8:visit_u8 u16:visit_u16 u32:visit_u32 u64:visit_u64);
+}
+
+serde_if_integer128! {
+    impl_deserialize_num! {
+        i128, deserialize_i128
+        num_self!(i128:visit_i128);
+        num_as_self!(i8:visit_i8 i16:visit_i16 i32:visit_i32 i64:visit_i64);
+        num_as_self!(u8:visit_u8 u16:visit_u16 u32:visit_u32 u64:visit_u64);
+
+        #[inline]
+        fn visit_u128<E>(self, v: u128) -> Result<Self::Value, E>
+        where
+            E: Error,
+        {
+            if v <= i128::max_value() as u128 {
+                Ok(v as i128)
+            } else {
+                Err(Error::invalid_value(Unexpected::Other("u128"), &self))
+            }
         }
     }
 
-    impl<'de> Deserialize<'de> for u128 {
+    impl_deserialize_num! {
+        u128, deserialize_u128
+        num_self!(u128:visit_u128);
+        num_as_self!(u8:visit_u8 u16:visit_u16 u32:visit_u32 u64:visit_u64);
+        int_to_uint!(i8:visit_i8 i16:visit_i16 i32:visit_i32 i64:visit_i64);
+
         #[inline]
-        fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
+        fn visit_i128<E>(self, v: i128) -> Result<Self::Value, E>
         where
-            D: Deserializer<'de>,
+            E: Error,
         {
-            struct PrimitiveVisitor;
-
-            impl<'de> Visitor<'de> for PrimitiveVisitor {
-                type Value = u128;
-
-                fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
-                    formatter.write_str("u128")
-                }
-
-                impl_deserialize_num!(integer u128);
-
-                #[inline]
-                fn visit_i128<E>(self, v: i128) -> Result<Self::Value, E>
-                where
-                    E: Error,
-                {
-                    if v >= 0 {
-                        Ok(v as u128)
-                    } else {
-                        Err(Error::invalid_value(Unexpected::Other("i128"), &self))
-                    }
-                }
-
-                #[inline]
-                fn visit_u128<E>(self, v: u128) -> Result<Self::Value, E>
-                where
-                    E: Error,
-                {
-                    Ok(v)
-                }
+            if 0 <= v {
+                Ok(v as u128)
+            } else {
+                Err(Error::invalid_value(Unexpected::Other("i128"), &self))
             }
-
-            deserializer.deserialize_u128(PrimitiveVisitor)
         }
     }
 }
@@ -1260,24 +1319,7 @@
                 D: Deserializer<'de>,
             {
                 if deserializer.is_human_readable() {
-                    struct IpAddrVisitor;
-
-                    impl<'de> Visitor<'de> for IpAddrVisitor {
-                        type Value = $ty;
-
-                        fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
-                            formatter.write_str($expecting)
-                        }
-
-                        fn visit_str<E>(self, s: &str) -> Result<Self::Value, E>
-                        where
-                            E: Error,
-                        {
-                            s.parse().map_err(Error::custom)
-                        }
-                    }
-
-                    deserializer.deserialize_str(IpAddrVisitor)
+                    deserializer.deserialize_str(FromStrVisitor::new($expecting))
                 } else {
                     <[u8; $size]>::deserialize(deserializer).map(<$ty>::from)
                 }
@@ -1405,24 +1447,7 @@
         D: Deserializer<'de>,
     {
         if deserializer.is_human_readable() {
-            struct IpAddrVisitor;
-
-            impl<'de> Visitor<'de> for IpAddrVisitor {
-                type Value = net::IpAddr;
-
-                fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
-                    formatter.write_str("IP address")
-                }
-
-                fn visit_str<E>(self, s: &str) -> Result<Self::Value, E>
-                where
-                    E: Error,
-                {
-                    s.parse().map_err(Error::custom)
-                }
-            }
-
-            deserializer.deserialize_str(IpAddrVisitor)
+            deserializer.deserialize_str(FromStrVisitor::new("IP address"))
         } else {
             use lib::net::IpAddr;
             deserialize_enum! {
@@ -1449,24 +1474,7 @@
                 D: Deserializer<'de>,
             {
                 if deserializer.is_human_readable() {
-                    struct SocketAddrVisitor;
-
-                    impl<'de> Visitor<'de> for SocketAddrVisitor {
-                        type Value = $ty;
-
-                        fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
-                            formatter.write_str($expecting)
-                        }
-
-                        fn visit_str<E>(self, s: &str) -> Result<Self::Value, E>
-                        where
-                            E: Error,
-                        {
-                            s.parse().map_err(Error::custom)
-                        }
-                    }
-
-                    deserializer.deserialize_str(SocketAddrVisitor)
+                    deserializer.deserialize_str(FromStrVisitor::new($expecting))
                 } else {
                     <(_, u16)>::deserialize(deserializer).map(|(ip, port)| $new(ip, port))
                 }
@@ -1482,24 +1490,7 @@
         D: Deserializer<'de>,
     {
         if deserializer.is_human_readable() {
-            struct SocketAddrVisitor;
-
-            impl<'de> Visitor<'de> for SocketAddrVisitor {
-                type Value = net::SocketAddr;
-
-                fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
-                    formatter.write_str("socket address")
-                }
-
-                fn visit_str<E>(self, s: &str) -> Result<Self::Value, E>
-                where
-                    E: Error,
-                {
-                    s.parse().map_err(Error::custom)
-                }
-            }
-
-            deserializer.deserialize_str(SocketAddrVisitor)
+            deserializer.deserialize_str(FromStrVisitor::new("socket address"))
         } else {
             use lib::net::SocketAddr;
             deserialize_enum! {
@@ -1917,6 +1908,17 @@
             }
         }
 
+        fn check_overflow<E>(secs: u64, nanos: u32) -> Result<(), E>
+        where
+            E: Error,
+        {
+            static NANOS_PER_SEC: u32 = 1_000_000_000;
+            match secs.checked_add((nanos / NANOS_PER_SEC) as u64) {
+                Some(_) => Ok(()),
+                None => Err(E::custom("overflow deserializing Duration")),
+            }
+        }
+
         struct DurationVisitor;
 
         impl<'de> Visitor<'de> for DurationVisitor {
@@ -1942,6 +1944,7 @@
                         return Err(Error::invalid_length(1, &self));
                     }
                 };
+                try!(check_overflow(secs, nanos));
                 Ok(Duration::new(secs, nanos))
             }
 
@@ -1975,6 +1978,7 @@
                     Some(nanos) => nanos,
                     None => return Err(<A::Error as Error>::missing_field("nanos")),
                 };
+                try!(check_overflow(secs, nanos));
                 Ok(Duration::new(secs, nanos))
             }
         }
@@ -2603,3 +2607,39 @@
 atomic_impl! {
     AtomicI64 AtomicU64
 }
+
+#[cfg(feature = "std")]
+struct FromStrVisitor<T> {
+    expecting: &'static str,
+    ty: PhantomData<T>,
+}
+
+#[cfg(feature = "std")]
+impl<T> FromStrVisitor<T> {
+    fn new(expecting: &'static str) -> Self {
+        FromStrVisitor {
+            expecting: expecting,
+            ty: PhantomData,
+        }
+    }
+}
+
+#[cfg(feature = "std")]
+impl<'de, T> Visitor<'de> for FromStrVisitor<T>
+where
+    T: str::FromStr,
+    T::Err: fmt::Display,
+{
+    type Value = T;
+
+    fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
+        formatter.write_str(self.expecting)
+    }
+
+    fn visit_str<E>(self, s: &str) -> Result<Self::Value, E>
+    where
+        E: Error,
+    {
+        s.parse().map_err(Error::custom)
+    }
+}
diff --git a/src/de/mod.rs b/src/de/mod.rs
index 6d39473..1ed7b4f 100644
--- a/src/de/mod.rs
+++ b/src/de/mod.rs
@@ -118,7 +118,6 @@
 
 pub mod value;
 
-mod from_primitive;
 mod ignored_any;
 mod impls;
 mod utf8;
@@ -393,7 +392,7 @@
 }
 
 impl<'a> fmt::Display for Unexpected<'a> {
-    fn fmt(&self, formatter: &mut fmt::Formatter) -> Result<(), fmt::Error> {
+    fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
         use self::Unexpected::*;
         match *self {
             Bool(b) => write!(formatter, "boolean `{}`", b),
diff --git a/src/de/seed.rs b/src/de/seed.rs
new file mode 100644
index 0000000..13b7ea4
--- /dev/null
+++ b/src/de/seed.rs
@@ -0,0 +1,19 @@
+use de::{Deserialize, DeserializeSeed, Deserializer};
+
+/// A DeserializeSeed helper for implementing deserialize_in_place Visitors.
+///
+/// Wraps a mutable reference and calls deserialize_in_place on it.
+pub struct InPlaceSeed<'a, T: 'a>(pub &'a mut T);
+
+impl<'a, 'de, T> DeserializeSeed<'de> for InPlaceSeed<'a, T>
+where
+    T: Deserialize<'de>,
+{
+    type Value = ();
+    fn deserialize<D>(self, deserializer: D) -> Result<Self::Value, D::Error>
+    where
+        D: Deserializer<'de>,
+    {
+        T::deserialize_in_place(deserializer, self.0)
+    }
+}
diff --git a/src/de/value.rs b/src/de/value.rs
index 96f2a90..1b154c3 100644
--- a/src/de/value.rs
+++ b/src/de/value.rs
@@ -24,8 +24,8 @@
 use lib::*;
 
 use self::private::{First, Second};
-use __private::de::size_hint;
-use de::{self, Expected, IntoDeserializer, SeqAccess};
+use __private::size_hint;
+use de::{self, Deserializer, Expected, IntoDeserializer, SeqAccess, Visitor};
 use ser;
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -48,7 +48,7 @@
 
 /// A minimal representation of all possible errors that can occur using the
 /// `IntoDeserializer` trait.
-#[derive(Clone, Debug, PartialEq)]
+#[derive(Clone, PartialEq)]
 pub struct Error {
     err: ErrorImpl,
 }
@@ -93,16 +93,25 @@
 
 impl Display for Error {
     #[cfg(any(feature = "std", feature = "alloc"))]
-    fn fmt(&self, formatter: &mut fmt::Formatter) -> Result<(), fmt::Error> {
+    fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
         formatter.write_str(&self.err)
     }
 
     #[cfg(not(any(feature = "std", feature = "alloc")))]
-    fn fmt(&self, formatter: &mut fmt::Formatter) -> Result<(), fmt::Error> {
+    fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
         formatter.write_str("Serde deserialization error")
     }
 }
 
+impl Debug for Error {
+    fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
+        let mut debug = formatter.debug_tuple("Error");
+        #[cfg(any(feature = "std", feature = "alloc"))]
+        debug.field(&self.err);
+        debug.finish()
+    }
+}
+
 #[cfg(feature = "std")]
 impl error::Error for Error {
     fn description(&self) -> &str {
@@ -126,7 +135,6 @@
 }
 
 /// A deserializer holding a `()`.
-#[derive(Debug)]
 pub struct UnitDeserializer<E> {
     marker: PhantomData<E>,
 }
@@ -160,6 +168,12 @@
     }
 }
 
+impl<E> Debug for UnitDeserializer<E> {
+    fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
+        formatter.debug_struct("UnitDeserializer").finish()
+    }
+}
+
 ////////////////////////////////////////////////////////////////////////////////
 
 /// A deserializer that cannot be instantiated.
@@ -208,7 +222,6 @@
     ($ty:ty, $doc:tt, $name:ident, $method:ident $($cast:tt)*) => {
         #[doc = "A deserializer holding"]
         #[doc = $doc]
-        #[derive(Debug)]
         pub struct $name<E> {
             value: $ty,
             marker: PhantomData<E>
@@ -249,6 +262,15 @@
                 visitor.$method(self.value $($cast)*)
             }
         }
+
+        impl<E> Debug for $name<E> {
+            fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
+                formatter
+                    .debug_struct(stringify!($name))
+                    .field("value", &self.value)
+                    .finish()
+            }
+        }
     }
 }
 
@@ -272,7 +294,6 @@
 }
 
 /// A deserializer holding a `u32`.
-#[derive(Debug)]
 pub struct U32Deserializer<E> {
     value: u32,
     marker: PhantomData<E>,
@@ -343,10 +364,18 @@
     }
 }
 
+impl<E> Debug for U32Deserializer<E> {
+    fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
+        formatter
+            .debug_struct("U32Deserializer")
+            .field("value", &self.value)
+            .finish()
+    }
+}
+
 ////////////////////////////////////////////////////////////////////////////////
 
 /// A deserializer holding a `&str`.
-#[derive(Debug)]
 pub struct StrDeserializer<'a, E> {
     value: &'a str,
     marker: PhantomData<E>,
@@ -417,11 +446,19 @@
     }
 }
 
+impl<'a, E> Debug for StrDeserializer<'a, E> {
+    fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
+        formatter
+            .debug_struct("StrDeserializer")
+            .field("value", &self.value)
+            .finish()
+    }
+}
+
 ////////////////////////////////////////////////////////////////////////////////
 
 /// A deserializer holding a `&str` with a lifetime tied to another
 /// deserializer.
-#[derive(Debug)]
 pub struct BorrowedStrDeserializer<'de, E> {
     value: &'de str,
     marker: PhantomData<E>,
@@ -488,11 +525,19 @@
     }
 }
 
+impl<'de, E> Debug for BorrowedStrDeserializer<'de, E> {
+    fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
+        formatter
+            .debug_struct("BorrowedStrDeserializer")
+            .field("value", &self.value)
+            .finish()
+    }
+}
+
 ////////////////////////////////////////////////////////////////////////////////
 
 /// A deserializer holding a `String`.
 #[cfg(any(feature = "std", feature = "alloc"))]
-#[derive(Debug)]
 pub struct StringDeserializer<E> {
     value: String,
     marker: PhantomData<E>,
@@ -574,11 +619,20 @@
     }
 }
 
+#[cfg(any(feature = "std", feature = "alloc"))]
+impl<E> Debug for StringDeserializer<E> {
+    fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
+        formatter
+            .debug_struct("StringDeserializer")
+            .field("value", &self.value)
+            .finish()
+    }
+}
+
 ////////////////////////////////////////////////////////////////////////////////
 
 /// A deserializer holding a `Cow<str>`.
 #[cfg(any(feature = "std", feature = "alloc"))]
-#[derive(Debug)]
 pub struct CowStrDeserializer<'a, E> {
     value: Cow<'a, str>,
     marker: PhantomData<E>,
@@ -663,29 +717,48 @@
     }
 }
 
+#[cfg(any(feature = "std", feature = "alloc"))]
+impl<'a, E> Debug for CowStrDeserializer<'a, E> {
+    fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
+        formatter
+            .debug_struct("CowStrDeserializer")
+            .field("value", &self.value)
+            .finish()
+    }
+}
+
 ////////////////////////////////////////////////////////////////////////////////
 
-/// A deserializer holding a `&[u8]` with a lifetime tied to another
-/// deserializer.
-#[derive(Debug)]
-pub struct BorrowedBytesDeserializer<'de, E> {
-    value: &'de [u8],
+/// A deserializer holding a `&[u8]`. Always calls [`Visitor::visit_bytes`].
+pub struct BytesDeserializer<'a, E> {
+    value: &'a [u8],
     marker: PhantomData<E>,
 }
 
-impl_copy_clone!(BorrowedBytesDeserializer<'de>);
-
-impl<'de, E> BorrowedBytesDeserializer<'de, E> {
-    /// Create a new borrowed deserializer from the given byte slice.
-    pub fn new(value: &'de [u8]) -> BorrowedBytesDeserializer<'de, E> {
-        BorrowedBytesDeserializer {
+impl<'a, E> BytesDeserializer<'a, E> {
+    /// Create a new deserializer from the given bytes.
+    pub fn new(value: &'a [u8]) -> Self {
+        BytesDeserializer {
             value: value,
             marker: PhantomData,
         }
     }
 }
 
-impl<'de, E> de::Deserializer<'de> for BorrowedBytesDeserializer<'de, E>
+impl_copy_clone!(BytesDeserializer<'a>);
+
+impl<'de, 'a, E> IntoDeserializer<'de, E> for &'a [u8]
+where
+    E: de::Error,
+{
+    type Deserializer = BytesDeserializer<'a, E>;
+
+    fn into_deserializer(self) -> BytesDeserializer<'a, E> {
+        BytesDeserializer::new(self)
+    }
+}
+
+impl<'de, 'a, E> Deserializer<'de> for BytesDeserializer<'a, E>
 where
     E: de::Error,
 {
@@ -693,7 +766,55 @@
 
     fn deserialize_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>
     where
-        V: de::Visitor<'de>,
+        V: Visitor<'de>,
+    {
+        visitor.visit_bytes(self.value)
+    }
+
+    forward_to_deserialize_any! {
+        bool i8 i16 i32 i64 i128 u8 u16 u32 u64 u128 f32 f64 char str string
+        bytes byte_buf option unit unit_struct newtype_struct seq tuple
+        tuple_struct map struct enum identifier ignored_any
+    }
+}
+
+impl<'a, E> Debug for BytesDeserializer<'a, E> {
+    fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
+        formatter
+            .debug_struct("BytesDeserializer")
+            .field("value", &self.value)
+            .finish()
+    }
+}
+
+/// A deserializer holding a `&[u8]` with a lifetime tied to another
+/// deserializer. Always calls [`Visitor::visit_borrowed_bytes`].
+pub struct BorrowedBytesDeserializer<'de, E> {
+    value: &'de [u8],
+    marker: PhantomData<E>,
+}
+
+impl<'de, E> BorrowedBytesDeserializer<'de, E> {
+    /// Create a new borrowed deserializer from the given borrowed bytes.
+    pub fn new(value: &'de [u8]) -> Self {
+        BorrowedBytesDeserializer {
+            value: value,
+            marker: PhantomData,
+        }
+    }
+}
+
+impl_copy_clone!(BorrowedBytesDeserializer<'de>);
+
+impl<'de, E> Deserializer<'de> for BorrowedBytesDeserializer<'de, E>
+where
+    E: de::Error,
+{
+    type Error = E;
+
+    fn deserialize_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>
+    where
+        V: Visitor<'de>,
     {
         visitor.visit_borrowed_bytes(self.value)
     }
@@ -701,14 +822,23 @@
     forward_to_deserialize_any! {
         bool i8 i16 i32 i64 i128 u8 u16 u32 u64 u128 f32 f64 char str string
         bytes byte_buf option unit unit_struct newtype_struct seq tuple
-        tuple_struct map struct identifier ignored_any enum
+        tuple_struct map struct enum identifier ignored_any
+    }
+}
+
+impl<'de, E> Debug for BorrowedBytesDeserializer<'de, E> {
+    fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
+        formatter
+            .debug_struct("BorrowedBytesDeserializer")
+            .field("value", &self.value)
+            .finish()
     }
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 
 /// A deserializer that iterates over a sequence.
-#[derive(Clone, Debug)]
+#[derive(Clone)]
 pub struct SeqDeserializer<I, E> {
     iter: iter::Fuse<I>,
     count: usize,
@@ -813,6 +943,19 @@
     }
 }
 
+impl<I, E> Debug for SeqDeserializer<I, E>
+where
+    I: Debug,
+{
+    fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
+        formatter
+            .debug_struct("SeqDeserializer")
+            .field("iter", &self.iter)
+            .field("count", &self.count)
+            .finish()
+    }
+}
+
 ////////////////////////////////////////////////////////////////////////////////
 
 #[cfg(any(feature = "std", feature = "alloc"))]
@@ -1108,7 +1251,6 @@
     }
 }
 
-// Cannot #[derive(Debug)] because of the bound `Second<I::Item>: Debug`.
 impl<'de, I, E> Debug for MapDeserializer<'de, I, E>
 where
     I: Iterator + Debug,
@@ -1121,8 +1263,6 @@
             .field("iter", &self.iter)
             .field("value", &self.value)
             .field("count", &self.count)
-            .field("lifetime", &self.lifetime)
-            .field("error", &self.error)
             .finish()
     }
 }
@@ -1331,7 +1471,6 @@
 
     use de::{self, DeserializeSeed, Deserializer, MapAccess, Unexpected, VariantAccess, Visitor};
 
-    #[derive(Clone, Debug)]
     pub struct UnitOnly<E> {
         marker: PhantomData<E>,
     }
@@ -1390,7 +1529,6 @@
         }
     }
 
-    #[derive(Clone, Debug)]
     pub struct MapAsEnum<A> {
         map: A,
     }
diff --git a/src/integer128.rs b/src/integer128.rs
index 3028c0a..0ee05bd 100644
--- a/src/integer128.rs
+++ b/src/integer128.rs
@@ -10,7 +10,7 @@
 /// bother with this macro and may assume support for 128-bit integers.
 ///
 /// ```edition2018
-/// # use serde::__private::ser::Error;
+/// # use serde::__private::doc::Error;
 /// #
 /// # struct MySerializer;
 /// #
diff --git a/src/lib.rs b/src/lib.rs
index 325c1af..7de2ff6 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -84,7 +84,7 @@
 ////////////////////////////////////////////////////////////////////////////////
 
 // Serde types in rustdoc of other crates get linked to here.
-#![doc(html_root_url = "https://docs.rs/serde/1.0.119")]
+#![doc(html_root_url = "https://docs.rs/serde/1.0.123")]
 // Support using Serde without the standard library!
 #![cfg_attr(not(feature = "std"), no_std)]
 // Unstable functionality only if the user asks for it. For tracking and
@@ -276,6 +276,9 @@
 #[allow(unused_imports)]
 use self::__private as private;
 
+#[path = "de/seed.rs"]
+mod seed;
+
 #[cfg(not(feature = "std"))]
 mod std_error;
 
diff --git a/src/private/de.rs b/src/private/de.rs
index bcb964a..0c2f3b8 100644
--- a/src/private/de.rs
+++ b/src/private/de.rs
@@ -1,9 +1,10 @@
 use lib::*;
 
-use de::{Deserialize, DeserializeSeed, Deserializer, Error, IntoDeserializer, Visitor};
+use de::value::{BorrowedBytesDeserializer, BytesDeserializer};
+use de::{Deserialize, Deserializer, Error, IntoDeserializer, Visitor};
 
 #[cfg(any(feature = "std", feature = "alloc"))]
-use de::{MapAccess, Unexpected};
+use de::{DeserializeSeed, MapAccess, Unexpected};
 
 #[cfg(any(feature = "std", feature = "alloc"))]
 pub use self::content::{
@@ -12,6 +13,8 @@
     TagOrContentField, TagOrContentFieldVisitor, TaggedContentVisitor, UntaggedUnitVisitor,
 };
 
+pub use seed::InPlaceSeed;
+
 /// If the missing field is of type `Option<T>` then treat is as `None`,
 /// otherwise it is an error.
 pub fn missing_field<'de, V, E>(field: &'static str) -> Result<V, E>
@@ -188,29 +191,6 @@
         .map(From::from)
 }
 
-pub mod size_hint {
-    use lib::*;
-
-    pub fn from_bounds<I>(iter: &I) -> Option<usize>
-    where
-        I: Iterator,
-    {
-        helper(iter.size_hint())
-    }
-
-    #[inline]
-    pub fn cautious(hint: Option<usize>) -> usize {
-        cmp::min(hint.unwrap_or(0), 4096)
-    }
-
-    fn helper(bounds: (usize, Option<usize>)) -> Option<usize> {
-        match bounds {
-            (lower, Some(upper)) if lower == upper => Some(upper),
-            _ => None,
-        }
-    }
-}
-
 #[cfg(any(feature = "std", feature = "alloc"))]
 mod content {
     // This module is private and nothing here should be used outside of
@@ -225,7 +205,7 @@
 
     use lib::*;
 
-    use super::size_hint;
+    use __private::size_hint;
     use de::{
         self, Deserialize, DeserializeSeed, Deserializer, EnumAccess, Expected, IgnoredAny,
         MapAccess, SeqAccess, Unexpected, Visitor,
@@ -824,15 +804,17 @@
     /// Not public API.
     pub struct TaggedContentVisitor<'de, T> {
         tag_name: &'static str,
+        expecting: &'static str,
         value: PhantomData<TaggedContent<'de, T>>,
     }
 
     impl<'de, T> TaggedContentVisitor<'de, T> {
         /// Visitor for the content of an internally tagged enum with the given
         /// tag name.
-        pub fn new(name: &'static str) -> Self {
+        pub fn new(name: &'static str, expecting: &'static str) -> Self {
             TaggedContentVisitor {
                 tag_name: name,
+                expecting: expecting,
                 value: PhantomData,
             }
         }
@@ -861,7 +843,7 @@
         type Value = TaggedContent<'de, T>;
 
         fn expecting(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
-            fmt.write_str("internally tagged enum")
+            fmt.write_str(self.expecting)
         }
 
         fn visit_seq<S>(self, mut seq: S) -> Result<Self::Value, S::Error>
@@ -1040,6 +1022,25 @@
                 _ => Err(self.invalid_type(&visitor)),
             }
         }
+
+        fn deserialize_float<V>(self, visitor: V) -> Result<V::Value, E>
+        where
+            V: Visitor<'de>,
+        {
+            match self.content {
+                Content::F32(v) => visitor.visit_f32(v),
+                Content::F64(v) => visitor.visit_f64(v),
+                Content::U8(v) => visitor.visit_u8(v),
+                Content::U16(v) => visitor.visit_u16(v),
+                Content::U32(v) => visitor.visit_u32(v),
+                Content::U64(v) => visitor.visit_u64(v),
+                Content::I8(v) => visitor.visit_i8(v),
+                Content::I16(v) => visitor.visit_i16(v),
+                Content::I32(v) => visitor.visit_i32(v),
+                Content::I64(v) => visitor.visit_i64(v),
+                _ => Err(self.invalid_type(&visitor)),
+            }
+        }
     }
 
     fn visit_content_seq<'de, V, E>(content: Vec<Content<'de>>, visitor: V) -> Result<V::Value, E>
@@ -1179,25 +1180,14 @@
         where
             V: Visitor<'de>,
         {
-            match self.content {
-                Content::F32(v) => visitor.visit_f32(v),
-                Content::F64(v) => visitor.visit_f64(v),
-                Content::U64(v) => visitor.visit_u64(v),
-                Content::I64(v) => visitor.visit_i64(v),
-                _ => Err(self.invalid_type(&visitor)),
-            }
+            self.deserialize_float(visitor)
         }
 
         fn deserialize_f64<V>(self, visitor: V) -> Result<V::Value, Self::Error>
         where
             V: Visitor<'de>,
         {
-            match self.content {
-                Content::F64(v) => visitor.visit_f64(v),
-                Content::U64(v) => visitor.visit_u64(v),
-                Content::I64(v) => visitor.visit_i64(v),
-                _ => Err(self.invalid_type(&visitor)),
-            }
+            self.deserialize_float(visitor)
         }
 
         fn deserialize_char<V>(self, visitor: V) -> Result<V::Value, Self::Error>
@@ -2542,11 +2532,13 @@
     fn from(self) -> Self::Deserializer;
 }
 
-impl<'de, E> IdentifierDeserializer<'de, E> for u32
+pub struct Borrowed<'de, T: 'de + ?Sized>(pub &'de T);
+
+impl<'de, E> IdentifierDeserializer<'de, E> for u64
 where
     E: Error,
 {
-    type Deserializer = <u32 as IntoDeserializer<'de, E>>::Deserializer;
+    type Deserializer = <u64 as IntoDeserializer<'de, E>>::Deserializer;
 
     fn from(self) -> Self::Deserializer {
         self.into_deserializer()
@@ -2558,20 +2550,6 @@
     marker: PhantomData<E>,
 }
 
-impl<'a, E> IdentifierDeserializer<'a, E> for &'a str
-where
-    E: Error,
-{
-    type Deserializer = StrDeserializer<'a, E>;
-
-    fn from(self) -> Self::Deserializer {
-        StrDeserializer {
-            value: self,
-            marker: PhantomData,
-        }
-    }
-}
-
 impl<'de, 'a, E> Deserializer<'de> for StrDeserializer<'a, E>
 where
     E: Error,
@@ -2592,26 +2570,12 @@
     }
 }
 
-pub struct BytesDeserializer<'a, E> {
-    value: &'a [u8],
+pub struct BorrowedStrDeserializer<'de, E> {
+    value: &'de str,
     marker: PhantomData<E>,
 }
 
-impl<'a, E> IdentifierDeserializer<'a, E> for &'a [u8]
-where
-    E: Error,
-{
-    type Deserializer = BytesDeserializer<'a, E>;
-
-    fn from(self) -> Self::Deserializer {
-        BytesDeserializer {
-            value: self,
-            marker: PhantomData,
-        }
-    }
-}
-
-impl<'de, 'a, E> Deserializer<'de> for BytesDeserializer<'a, E>
+impl<'de, E> Deserializer<'de> for BorrowedStrDeserializer<'de, E>
 where
     E: Error,
 {
@@ -2621,7 +2585,7 @@
     where
         V: Visitor<'de>,
     {
-        visitor.visit_bytes(self.value)
+        visitor.visit_borrowed_str(self.value)
     }
 
     forward_to_deserialize_any! {
@@ -2631,21 +2595,53 @@
     }
 }
 
-/// A DeserializeSeed helper for implementing deserialize_in_place Visitors.
-///
-/// Wraps a mutable reference and calls deserialize_in_place on it.
-pub struct InPlaceSeed<'a, T: 'a>(pub &'a mut T);
-
-impl<'a, 'de, T> DeserializeSeed<'de> for InPlaceSeed<'a, T>
+impl<'a, E> IdentifierDeserializer<'a, E> for &'a str
 where
-    T: Deserialize<'de>,
+    E: Error,
 {
-    type Value = ();
-    fn deserialize<D>(self, deserializer: D) -> Result<Self::Value, D::Error>
-    where
-        D: Deserializer<'de>,
-    {
-        T::deserialize_in_place(deserializer, self.0)
+    type Deserializer = StrDeserializer<'a, E>;
+
+    fn from(self) -> Self::Deserializer {
+        StrDeserializer {
+            value: self,
+            marker: PhantomData,
+        }
+    }
+}
+
+impl<'de, E> IdentifierDeserializer<'de, E> for Borrowed<'de, str>
+where
+    E: Error,
+{
+    type Deserializer = BorrowedStrDeserializer<'de, E>;
+
+    fn from(self) -> Self::Deserializer {
+        BorrowedStrDeserializer {
+            value: self.0,
+            marker: PhantomData,
+        }
+    }
+}
+
+impl<'a, E> IdentifierDeserializer<'a, E> for &'a [u8]
+where
+    E: Error,
+{
+    type Deserializer = BytesDeserializer<'a, E>;
+
+    fn from(self) -> Self::Deserializer {
+        BytesDeserializer::new(self)
+    }
+}
+
+impl<'de, E> IdentifierDeserializer<'de, E> for Borrowed<'de, [u8]>
+where
+    E: Error,
+{
+    type Deserializer = BorrowedBytesDeserializer<'de, E>;
+
+    fn from(self) -> Self::Deserializer {
+        BorrowedBytesDeserializer::new(self.0)
     }
 }
 
diff --git a/src/private/macros.rs b/src/private/doc.rs
similarity index 89%
rename from src/private/macros.rs
rename to src/private/doc.rs
index 39d66f6..f597af8 100644
--- a/src/private/macros.rs
+++ b/src/private/doc.rs
@@ -1,3 +1,35 @@
+// Used only by Serde doc tests. Not public API.
+
+use lib::*;
+
+use ser;
+
+#[doc(hidden)]
+#[derive(Debug)]
+pub struct Error;
+
+impl ser::Error for Error {
+    fn custom<T>(_: T) -> Self
+    where
+        T: Display,
+    {
+        unimplemented!()
+    }
+}
+
+#[cfg(feature = "std")]
+impl error::Error for Error {
+    fn description(&self) -> &str {
+        unimplemented!()
+    }
+}
+
+impl Display for Error {
+    fn fmt(&self, _: &mut fmt::Formatter) -> fmt::Result {
+        unimplemented!()
+    }
+}
+
 #[doc(hidden)]
 #[macro_export]
 macro_rules! __private_serialize {
@@ -11,19 +43,6 @@
 }
 
 #[doc(hidden)]
-#[macro_export]
-macro_rules! __private_deserialize {
-    () => {
-        trait Deserialize<'de>: Sized {
-            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
-            where
-                D: $crate::Deserializer<'de>;
-        }
-    };
-}
-
-/// Used only by Serde doc tests. Not public API.
-#[doc(hidden)]
 #[macro_export(local_inner_macros)]
 macro_rules! __serialize_unimplemented {
     ($($func:ident)*) => {
diff --git a/src/private/mod.rs b/src/private/mod.rs
index 73355e4..24ea84b 100644
--- a/src/private/mod.rs
+++ b/src/private/mod.rs
@@ -1,8 +1,13 @@
-mod macros;
-
+#[cfg(serde_derive)]
 pub mod de;
+#[cfg(serde_derive)]
 pub mod ser;
 
+pub mod size_hint;
+
+// FIXME: #[cfg(doctest)] once https://github.com/rust-lang/rust/issues/67295 is fixed.
+pub mod doc;
+
 pub use lib::clone::Clone;
 pub use lib::convert::{From, Into};
 pub use lib::default::Default;
diff --git a/src/private/ser.rs b/src/private/ser.rs
index eb8cfc9..6ee9993 100644
--- a/src/private/ser.rs
+++ b/src/private/ser.rs
@@ -335,33 +335,6 @@
     }
 }
 
-/// Used only by Serde doc tests. Not public API.
-#[doc(hidden)]
-#[derive(Debug)]
-pub struct Error;
-
-impl ser::Error for Error {
-    fn custom<T>(_: T) -> Self
-    where
-        T: Display,
-    {
-        unimplemented!()
-    }
-}
-
-#[cfg(feature = "std")]
-impl error::Error for Error {
-    fn description(&self) -> &str {
-        unimplemented!()
-    }
-}
-
-impl Display for Error {
-    fn fmt(&self, _: &mut fmt::Formatter) -> fmt::Result {
-        unimplemented!()
-    }
-}
-
 #[cfg(any(feature = "std", feature = "alloc"))]
 mod content {
     use lib::*;
@@ -452,7 +425,6 @@
         }
     }
 
-    #[derive(Debug)]
     pub enum Content {
         Bool(bool),
 
diff --git a/src/private/size_hint.rs b/src/private/size_hint.rs
new file mode 100644
index 0000000..ca71e61
--- /dev/null
+++ b/src/private/size_hint.rs
@@ -0,0 +1,21 @@
+use lib::*;
+
+pub fn from_bounds<I>(iter: &I) -> Option<usize>
+where
+    I: Iterator,
+{
+    helper(iter.size_hint())
+}
+
+#[cfg(any(feature = "std", feature = "alloc"))]
+#[inline]
+pub fn cautious(hint: Option<usize>) -> usize {
+    cmp::min(hint.unwrap_or(0), 4096)
+}
+
+fn helper(bounds: (usize, Option<usize>)) -> Option<usize> {
+    match bounds {
+        (lower, Some(upper)) if lower == upper => Some(upper),
+        _ => None,
+    }
+}
diff --git a/src/ser/impossible.rs b/src/ser/impossible.rs
index 8a6501e..e8df9ca 100644
--- a/src/ser/impossible.rs
+++ b/src/ser/impossible.rs
@@ -17,7 +17,7 @@
 ///
 /// ```edition2018
 /// # use serde::ser::{Serializer, Impossible};
-/// # use serde::__private::ser::Error;
+/// # use serde::__private::doc::Error;
 /// #
 /// # struct MySerializer;
 /// #
diff --git a/src/ser/mod.rs b/src/ser/mod.rs
index 1e7ef8a..d686c5a 100644
--- a/src/ser/mod.rs
+++ b/src/ser/mod.rs
@@ -711,7 +711,7 @@
     ///
     /// ```edition2018
     /// # use serde::ser::{Serializer, SerializeSeq};
-    /// # use serde::__private::ser::Error;
+    /// # use serde::__private::doc::Error;
     /// #
     /// # struct MySerializer;
     /// #