From c23a457e72abe608715ac76f076f47dc42af07a5 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Thu, 30 May 2024 20:31:44 +0200 Subject: Merging upstream version 1.74.1+dfsg1. Signed-off-by: Daniel Baumann --- vendor/serde/src/de/format.rs | 4 +- vendor/serde/src/de/ignored_any.rs | 30 ++-- vendor/serde/src/de/impls.rs | 286 ++++++++++++++++--------------------- vendor/serde/src/de/mod.rs | 133 +++++++++-------- vendor/serde/src/de/seed.rs | 2 +- vendor/serde/src/de/size_hint.rs | 29 ++++ vendor/serde/src/de/utf8.rs | 46 ------ vendor/serde/src/de/value.rs | 40 +++--- 8 files changed, 249 insertions(+), 321 deletions(-) create mode 100644 vendor/serde/src/de/size_hint.rs delete mode 100644 vendor/serde/src/de/utf8.rs (limited to 'vendor/serde/src/de') diff --git a/vendor/serde/src/de/format.rs b/vendor/serde/src/de/format.rs index f14580b8d..9053cc070 100644 --- a/vendor/serde/src/de/format.rs +++ b/vendor/serde/src/de/format.rs @@ -1,5 +1,5 @@ -use lib::fmt::{self, Write}; -use lib::str; +use crate::lib::fmt::{self, Write}; +use crate::lib::str; pub(super) struct Buf<'a> { bytes: &'a mut [u8], diff --git a/vendor/serde/src/de/ignored_any.rs b/vendor/serde/src/de/ignored_any.rs index 01555a29f..2360a1742 100644 --- a/vendor/serde/src/de/ignored_any.rs +++ b/vendor/serde/src/de/ignored_any.rs @@ -1,6 +1,6 @@ -use lib::*; +use crate::lib::*; -use de::{ +use crate::de::{ Deserialize, Deserializer, EnumAccess, Error, MapAccess, SeqAccess, VariantAccess, Visitor, }; @@ -129,12 +129,10 @@ impl<'de> Visitor<'de> for IgnoredAny { Ok(IgnoredAny) } - serde_if_integer128! { - #[inline] - fn visit_i128(self, x: i128) -> Result { - let _ = x; - Ok(IgnoredAny) - } + #[inline] + fn visit_i128(self, x: i128) -> Result { + let _ = x; + Ok(IgnoredAny) } #[inline] @@ -143,12 +141,10 @@ impl<'de> Visitor<'de> for IgnoredAny { Ok(IgnoredAny) } - serde_if_integer128! { - #[inline] - fn visit_u128(self, x: u128) -> Result { - let _ = x; - Ok(IgnoredAny) - } + #[inline] + fn visit_u128(self, x: u128) -> Result { + let _ = x; + Ok(IgnoredAny) } #[inline] @@ -197,7 +193,7 @@ impl<'de> Visitor<'de> for IgnoredAny { where A: SeqAccess<'de>, { - while let Some(IgnoredAny) = try!(seq.next_element()) { + while let Some(IgnoredAny) = tri!(seq.next_element()) { // Gobble } Ok(IgnoredAny) @@ -208,7 +204,7 @@ impl<'de> Visitor<'de> for IgnoredAny { where A: MapAccess<'de>, { - while let Some((IgnoredAny, IgnoredAny)) = try!(map.next_entry()) { + while let Some((IgnoredAny, IgnoredAny)) = tri!(map.next_entry()) { // Gobble } Ok(IgnoredAny) @@ -227,7 +223,7 @@ impl<'de> Visitor<'de> for IgnoredAny { where A: EnumAccess<'de>, { - try!(data.variant::()).1.newtype_variant() + tri!(data.variant::()).1.newtype_variant() } } diff --git a/vendor/serde/src/de/impls.rs b/vendor/serde/src/de/impls.rs index 12fbdfdb3..fbee1554b 100644 --- a/vendor/serde/src/de/impls.rs +++ b/vendor/serde/src/de/impls.rs @@ -1,16 +1,14 @@ -use lib::*; +use crate::lib::*; -use de::{ - Deserialize, Deserializer, EnumAccess, Error, SeqAccess, Unexpected, VariantAccess, Visitor, +use crate::de::{ + Deserialize, Deserializer, EnumAccess, Error, MapAccess, SeqAccess, Unexpected, VariantAccess, + Visitor, }; -#[cfg(any(feature = "std", feature = "alloc", not(no_core_duration)))] -use de::MapAccess; - -use seed::InPlaceSeed; +use crate::seed::InPlaceSeed; #[cfg(any(feature = "std", feature = "alloc"))] -use __private::size_hint; +use crate::de::size_hint; //////////////////////////////////////////////////////////////////////////////// @@ -84,7 +82,7 @@ macro_rules! impl_deserialize_num { ($primitive:ident, $nonzero:ident $(cfg($($cfg:tt)*))*, $deserialize:ident $($method:ident!($($val:ident : $visit:ident)*);)*) => { impl_deserialize_num!($primitive, $deserialize $($method!($($val : $visit)*);)*); - #[cfg(all(not(no_num_nonzero), $($($cfg)*)*))] + $(#[cfg($($cfg)*)])* impl<'de> Deserialize<'de> for num::$nonzero { fn deserialize(deserializer: D) -> Result where @@ -366,64 +364,62 @@ impl_deserialize_num! { num_as_self!(u8:visit_u8 u16:visit_u16 u32:visit_u32 u64:visit_u64); } -serde_if_integer128! { - macro_rules! num_128 { - ($ty:ident : $visit:ident) => { - fn $visit(self, v: $ty) -> Result - where - E: Error, +macro_rules! num_128 { + ($ty:ident : $visit:ident) => { + fn $visit(self, v: $ty) -> Result + where + E: Error, + { + if v as i128 >= Self::Value::min_value() as i128 + && v as u128 <= Self::Value::max_value() as u128 { - if v as i128 >= Self::Value::min_value() as i128 - && v as u128 <= Self::Value::max_value() as u128 - { - Ok(v as Self::Value) - } else { - Err(Error::invalid_value( - Unexpected::Other(stringify!($ty)), - &self, - )) - } + Ok(v as Self::Value) + } else { + Err(Error::invalid_value( + Unexpected::Other(stringify!($ty)), + &self, + )) } - }; + } + }; - (nonzero $primitive:ident $ty:ident : $visit:ident) => { - fn $visit(self, v: $ty) -> Result - where - E: Error, + (nonzero $primitive:ident $ty:ident : $visit:ident) => { + fn $visit(self, v: $ty) -> Result + where + E: Error, + { + if v as i128 >= $primitive::min_value() as i128 + && v as u128 <= $primitive::max_value() as u128 { - if v as i128 >= $primitive::min_value() as i128 - && v as u128 <= $primitive::max_value() as u128 - { - if let Some(nonzero) = Self::Value::new(v as $primitive) { - Ok(nonzero) - } else { - Err(Error::invalid_value(Unexpected::Unsigned(0), &self)) - } + if let Some(nonzero) = Self::Value::new(v as $primitive) { + Ok(nonzero) } else { - Err(Error::invalid_value( - Unexpected::Other(stringify!($ty)), - &self, - )) + Err(Error::invalid_value(Unexpected::Unsigned(0), &self)) } + } else { + Err(Error::invalid_value( + Unexpected::Other(stringify!($ty)), + &self, + )) } - }; - } + } + }; +} - impl_deserialize_num! { - i128, NonZeroI128 cfg(not(no_num_nonzero_signed)), 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); - num_128!(u128:visit_u128); - } +impl_deserialize_num! { + i128, NonZeroI128 cfg(not(no_num_nonzero_signed)), 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); + num_128!(u128:visit_u128); +} - impl_deserialize_num! { - u128, NonZeroU128, 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); - num_128!(i128:visit_i128); - } +impl_deserialize_num! { + u128, NonZeroU128, 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); + num_128!(i128:visit_i128); } //////////////////////////////////////////////////////////////////////////////// @@ -684,7 +680,7 @@ impl<'de> Visitor<'de> for CStringVisitor { let capacity = size_hint::cautious::(seq.size_hint()); let mut values = Vec::::with_capacity(capacity); - while let Some(value) = try!(seq.next_element()) { + while let Some(value) = tri!(seq.next_element()) { values.push(value); } @@ -747,13 +743,9 @@ macro_rules! forwarded_impl { } } -#[cfg(all( - any(feature = "std", all(not(no_core_cstr), feature = "alloc")), - not(no_de_boxed_c_str) -))] +#[cfg(any(feature = "std", all(not(no_core_cstr), feature = "alloc")))] forwarded_impl!((), Box, CString::into_boxed_c_str); -#[cfg(not(no_core_reverse))] forwarded_impl!((T), Reverse, Reverse); //////////////////////////////////////////////////////////////////////////////// @@ -901,7 +893,7 @@ macro_rules! seq_impl { { let mut values = $with_capacity; - while let Some(value) = try!($access.next_element()) { + while let Some(value) = tri!($access.next_element()) { $insert(&mut values, value); } @@ -939,7 +931,7 @@ macro_rules! seq_impl { $reserve(&mut self.0, size_hint::cautious::($access.size_hint())); // FIXME: try to overwrite old values here? (Vec, VecDeque, LinkedList) - while let Some(value) = try!($access.next_element()) { + while let Some(value) = tri!($access.next_element()) { $insert(&mut self.0, value); } @@ -1039,7 +1031,7 @@ where let capacity = size_hint::cautious::(seq.size_hint()); let mut values = Vec::::with_capacity(capacity); - while let Some(value) = try!(seq.next_element()) { + while let Some(value) = tri!(seq.next_element()) { values.push(value); } @@ -1081,7 +1073,7 @@ where for i in 0..self.0.len() { let next = { let next_place = InPlaceSeed(&mut self.0[i]); - try!(seq.next_element_seed(next_place)) + tri!(seq.next_element_seed(next_place)) }; if next.is_none() { self.0.truncate(i); @@ -1089,7 +1081,7 @@ where } } - while let Some(value) = try!(seq.next_element()) { + while let Some(value) = tri!(seq.next_element()) { self.0.push(value); } @@ -1161,7 +1153,7 @@ macro_rules! array_impls { A: SeqAccess<'de>, { Ok([$( - match try!(seq.next_element()) { + match tri!(seq.next_element()) { Some(val) => val, None => return Err(Error::invalid_length($n, &self)), } @@ -1186,7 +1178,7 @@ macro_rules! array_impls { { let mut fail_idx = None; for (idx, dest) in self.0[..].iter_mut().enumerate() { - if try!(seq.next_element_seed(InPlaceSeed(dest))).is_none() { + if tri!(seq.next_element_seed(InPlaceSeed(dest))).is_none() { fail_idx = Some(idx); break; } @@ -1284,7 +1276,7 @@ macro_rules! tuple_impls { A: SeqAccess<'de>, { $( - let $name = match try!(seq.next_element()) { + let $name = match tri!(seq.next_element()) { Some(value) => value, None => return Err(Error::invalid_length($n, &self)), }; @@ -1318,7 +1310,7 @@ macro_rules! tuple_impls { A: SeqAccess<'de>, { $( - if try!(seq.next_element_seed(InPlaceSeed(&mut (self.0).$n))).is_none() { + if tri!(seq.next_element_seed(InPlaceSeed(&mut (self.0).$n))).is_none() { return Err(Error::invalid_length($n, &self)); } )+ @@ -1395,7 +1387,7 @@ macro_rules! map_impl { { let mut values = $with_capacity; - while let Some((key, value)) = try!($access.next_entry()) { + while let Some((key, value)) = tri!($access.next_entry()) { values.insert(key, value); } @@ -1541,7 +1533,7 @@ macro_rules! deserialize_enum { where A: EnumAccess<'de>, { - match try!(data.variant()) { + match tri!(data.variant()) { $( ($name_kind :: $variant, v) => v.newtype_variant().map($name :: $variant), )* @@ -1561,7 +1553,7 @@ impl<'de> Deserialize<'de> for net::IpAddr { if deserializer.is_human_readable() { deserializer.deserialize_str(FromStrVisitor::new("IP address")) } else { - use lib::net::IpAddr; + use crate::lib::net::IpAddr; deserialize_enum! { IpAddr IpAddrKind (V4; b"V4"; 0, V6; b"V6"; 1) "`V4` or `V6`", @@ -1604,7 +1596,7 @@ impl<'de> Deserialize<'de> for net::SocketAddr { if deserializer.is_human_readable() { deserializer.deserialize_str(FromStrVisitor::new("socket address")) } else { - use lib::net::SocketAddr; + use crate::lib::net::SocketAddr; deserialize_enum! { SocketAddr SocketAddrKind (V4; b"V4"; 0, V6; b"V6"; 1) "`V4` or `V6`", @@ -1714,7 +1706,7 @@ impl<'de> Deserialize<'de> for PathBuf { } } -#[cfg(all(feature = "std", not(no_de_boxed_path)))] +#[cfg(feature = "std")] forwarded_impl!((), Box, PathBuf::into_boxed_path); //////////////////////////////////////////////////////////////////////////////// @@ -1748,7 +1740,7 @@ impl<'de> Visitor<'de> for OsStringVisitor { { use std::os::unix::ffi::OsStringExt; - match try!(data.variant()) { + match tri!(data.variant()) { (OsStringKind::Unix, v) => v.newtype_variant().map(OsString::from_vec), (OsStringKind::Windows, _) => Err(Error::custom( "cannot deserialize Windows OS string on Unix", @@ -1763,7 +1755,7 @@ impl<'de> Visitor<'de> for OsStringVisitor { { use std::os::windows::ffi::OsStringExt; - match try!(data.variant()) { + match tri!(data.variant()) { (OsStringKind::Windows, v) => v .newtype_variant::>() .map(|vec| OsString::from_wide(&vec)), @@ -1795,29 +1787,8 @@ forwarded_impl!((T), Box<[T]>, Vec::into_boxed_slice); #[cfg(any(feature = "std", feature = "alloc"))] forwarded_impl!((), Box, String::into_boxed_str); -#[cfg(all(no_de_rc_dst, feature = "rc", any(feature = "std", feature = "alloc")))] -forwarded_impl! { - /// This impl requires the [`"rc"`] Cargo feature of Serde. - /// - /// Deserializing a data structure containing `Arc` will not attempt to - /// deduplicate `Arc` references to the same data. Every deserialized `Arc` - /// will end up with a strong count of 1. - /// - /// [`"rc"`]: https://serde.rs/feature-flags.html#-features-rc - (T), Arc, Arc::new -} - -#[cfg(all(no_de_rc_dst, feature = "rc", any(feature = "std", feature = "alloc")))] -forwarded_impl! { - /// This impl requires the [`"rc"`] Cargo feature of Serde. - /// - /// Deserializing a data structure containing `Rc` will not attempt to - /// deduplicate `Rc` references to the same data. Every deserialized `Rc` - /// will end up with a strong count of 1. - /// - /// [`"rc"`]: https://serde.rs/feature-flags.html#-features-rc - (T), Rc, Rc::new -} +#[cfg(all(feature = "std", any(unix, windows)))] +forwarded_impl!((), Box, OsString::into_boxed_os_str); #[cfg(any(feature = "std", feature = "alloc"))] impl<'de, 'a, T: ?Sized> Deserialize<'de> for Cow<'a, T> @@ -1849,7 +1820,7 @@ where where D: Deserializer<'de>, { - try!(Option::::deserialize(deserializer)); + tri!(Option::::deserialize(deserializer)); Ok(RcWeak::new()) } } @@ -1867,18 +1838,14 @@ where where D: Deserializer<'de>, { - try!(Option::::deserialize(deserializer)); + tri!(Option::::deserialize(deserializer)); Ok(ArcWeak::new()) } } //////////////////////////////////////////////////////////////////////////////// -#[cfg(all( - not(no_de_rc_dst), - feature = "rc", - any(feature = "std", feature = "alloc") -))] +#[cfg(all(feature = "rc", any(feature = "std", feature = "alloc")))] macro_rules! box_forwarded_impl { ( $(#[doc = $doc:tt])* @@ -1899,11 +1866,7 @@ macro_rules! box_forwarded_impl { }; } -#[cfg(all( - not(no_de_rc_dst), - feature = "rc", - any(feature = "std", feature = "alloc") -))] +#[cfg(all(feature = "rc", any(feature = "std", feature = "alloc")))] box_forwarded_impl! { /// This impl requires the [`"rc"`] Cargo feature of Serde. /// @@ -1915,11 +1878,7 @@ box_forwarded_impl! { Rc } -#[cfg(all( - not(no_de_rc_dst), - feature = "rc", - any(feature = "std", feature = "alloc") -))] +#[cfg(all(feature = "rc", any(feature = "std", feature = "alloc")))] box_forwarded_impl! { /// This impl requires the [`"rc"`] Cargo feature of Serde. /// @@ -1963,7 +1922,6 @@ forwarded_impl!((T), RwLock, RwLock::new); // secs: u64, // nanos: u32, // } -#[cfg(any(feature = "std", not(no_core_duration)))] impl<'de> Deserialize<'de> for Duration { fn deserialize(deserializer: D) -> Result where @@ -2011,7 +1969,7 @@ impl<'de> Deserialize<'de> for Duration { b"secs" => Ok(Field::Secs), b"nanos" => Ok(Field::Nanos), _ => { - let value = ::__private::from_utf8_lossy(value); + let value = crate::__private::from_utf8_lossy(value); Err(Error::unknown_field(&*value, FIELDS)) } } @@ -2046,19 +2004,19 @@ impl<'de> Deserialize<'de> for Duration { where A: SeqAccess<'de>, { - let secs: u64 = match try!(seq.next_element()) { + let secs: u64 = match tri!(seq.next_element()) { Some(value) => value, None => { return Err(Error::invalid_length(0, &self)); } }; - let nanos: u32 = match try!(seq.next_element()) { + let nanos: u32 = match tri!(seq.next_element()) { Some(value) => value, None => { return Err(Error::invalid_length(1, &self)); } }; - try!(check_overflow(secs, nanos)); + tri!(check_overflow(secs, nanos)); Ok(Duration::new(secs, nanos)) } @@ -2068,19 +2026,19 @@ impl<'de> Deserialize<'de> for Duration { { let mut secs: Option = None; let mut nanos: Option = None; - while let Some(key) = try!(map.next_key()) { + while let Some(key) = tri!(map.next_key()) { match key { Field::Secs => { if secs.is_some() { return Err(::duplicate_field("secs")); } - secs = Some(try!(map.next_value())); + secs = Some(tri!(map.next_value())); } Field::Nanos => { if nanos.is_some() { return Err(::duplicate_field("nanos")); } - nanos = Some(try!(map.next_value())); + nanos = Some(tri!(map.next_value())); } } } @@ -2092,7 +2050,7 @@ impl<'de> Deserialize<'de> for Duration { Some(nanos) => nanos, None => return Err(::missing_field("nanos")), }; - try!(check_overflow(secs, nanos)); + tri!(check_overflow(secs, nanos)); Ok(Duration::new(secs, nanos)) } } @@ -2184,19 +2142,19 @@ impl<'de> Deserialize<'de> for SystemTime { where A: SeqAccess<'de>, { - let secs: u64 = match try!(seq.next_element()) { + let secs: u64 = match tri!(seq.next_element()) { Some(value) => value, None => { return Err(Error::invalid_length(0, &self)); } }; - let nanos: u32 = match try!(seq.next_element()) { + let nanos: u32 = match tri!(seq.next_element()) { Some(value) => value, None => { return Err(Error::invalid_length(1, &self)); } }; - try!(check_overflow(secs, nanos)); + tri!(check_overflow(secs, nanos)); Ok(Duration::new(secs, nanos)) } @@ -2206,7 +2164,7 @@ impl<'de> Deserialize<'de> for SystemTime { { let mut secs: Option = None; let mut nanos: Option = None; - while let Some(key) = try!(map.next_key()) { + while let Some(key) = tri!(map.next_key()) { match key { Field::Secs => { if secs.is_some() { @@ -2214,7 +2172,7 @@ impl<'de> Deserialize<'de> for SystemTime { "secs_since_epoch", )); } - secs = Some(try!(map.next_value())); + secs = Some(tri!(map.next_value())); } Field::Nanos => { if nanos.is_some() { @@ -2222,7 +2180,7 @@ impl<'de> Deserialize<'de> for SystemTime { "nanos_since_epoch", )); } - nanos = Some(try!(map.next_value())); + nanos = Some(tri!(map.next_value())); } } } @@ -2234,13 +2192,13 @@ impl<'de> Deserialize<'de> for SystemTime { Some(nanos) => nanos, None => return Err(::missing_field("nanos_since_epoch")), }; - try!(check_overflow(secs, nanos)); + tri!(check_overflow(secs, nanos)); Ok(Duration::new(secs, nanos)) } } const FIELDS: &[&str] = &["secs_since_epoch", "nanos_since_epoch"]; - let duration = try!(deserializer.deserialize_struct("SystemTime", FIELDS, DurationVisitor)); + let duration = tri!(deserializer.deserialize_struct("SystemTime", FIELDS, DurationVisitor)); #[cfg(not(no_systemtime_checked_add))] let ret = UNIX_EPOCH .checked_add(duration) @@ -2269,7 +2227,7 @@ where where D: Deserializer<'de>, { - let (start, end) = try!(deserializer.deserialize_struct( + let (start, end) = tri!(deserializer.deserialize_struct( "Range", range::FIELDS, range::RangeVisitor { @@ -2281,7 +2239,6 @@ where } } -#[cfg(not(no_range_inclusive))] impl<'de, Idx> Deserialize<'de> for RangeInclusive where Idx: Deserialize<'de>, @@ -2290,7 +2247,7 @@ where where D: Deserializer<'de>, { - let (start, end) = try!(deserializer.deserialize_struct( + let (start, end) = tri!(deserializer.deserialize_struct( "RangeInclusive", range::FIELDS, range::RangeVisitor { @@ -2303,9 +2260,9 @@ where } mod range { - use lib::*; + use crate::lib::*; - use de::{Deserialize, Deserializer, Error, MapAccess, SeqAccess, Visitor}; + use crate::de::{Deserialize, Deserializer, Error, MapAccess, SeqAccess, Visitor}; pub const FIELDS: &[&str] = &["start", "end"]; @@ -2351,7 +2308,7 @@ mod range { b"start" => Ok(Field::Start), b"end" => Ok(Field::End), _ => { - let value = ::__private::from_utf8_lossy(value); + let value = crate::__private::from_utf8_lossy(value); Err(Error::unknown_field(&*value, FIELDS)) } } @@ -2381,13 +2338,13 @@ mod range { where A: SeqAccess<'de>, { - let start: Idx = match try!(seq.next_element()) { + let start: Idx = match tri!(seq.next_element()) { Some(value) => value, None => { return Err(Error::invalid_length(0, &self)); } }; - let end: Idx = match try!(seq.next_element()) { + let end: Idx = match tri!(seq.next_element()) { Some(value) => value, None => { return Err(Error::invalid_length(1, &self)); @@ -2402,19 +2359,19 @@ mod range { { let mut start: Option = None; let mut end: Option = None; - while let Some(key) = try!(map.next_key()) { + while let Some(key) = tri!(map.next_key()) { match key { Field::Start => { if start.is_some() { return Err(::duplicate_field("start")); } - start = Some(try!(map.next_value())); + start = Some(tri!(map.next_value())); } Field::End => { if end.is_some() { return Err(::duplicate_field("end")); } - end = Some(try!(map.next_value())); + end = Some(tri!(map.next_value())); } } } @@ -2448,7 +2405,7 @@ where where D: Deserializer<'de>, { - let start = try!(deserializer.deserialize_struct( + let start = tri!(deserializer.deserialize_struct( "RangeFrom", range_from::FIELDS, range_from::RangeFromVisitor { @@ -2461,9 +2418,9 @@ where } mod range_from { - use lib::*; + use crate::lib::*; - use de::{Deserialize, Deserializer, Error, MapAccess, SeqAccess, Visitor}; + use crate::de::{Deserialize, Deserializer, Error, MapAccess, SeqAccess, Visitor}; pub const FIELDS: &[&str] = &["end"]; @@ -2506,7 +2463,7 @@ mod range_from { match value { b"end" => Ok(Field::End), _ => { - let value = ::__private::from_utf8_lossy(value); + let value = crate::__private::from_utf8_lossy(value); Err(Error::unknown_field(&*value, FIELDS)) } } @@ -2536,7 +2493,7 @@ mod range_from { where A: SeqAccess<'de>, { - let end: Idx = match try!(seq.next_element()) { + let end: Idx = match tri!(seq.next_element()) { Some(value) => value, None => { return Err(Error::invalid_length(0, &self)); @@ -2550,13 +2507,13 @@ mod range_from { A: MapAccess<'de>, { let mut end: Option = None; - while let Some(key) = try!(map.next_key()) { + while let Some(key) = tri!(map.next_key()) { match key { Field::End => { if end.is_some() { return Err(::duplicate_field("end")); } - end = Some(try!(map.next_value())); + end = Some(tri!(map.next_value())); } } } @@ -2586,7 +2543,7 @@ where where D: Deserializer<'de>, { - let end = try!(deserializer.deserialize_struct( + let end = tri!(deserializer.deserialize_struct( "RangeTo", range_to::FIELDS, range_to::RangeToVisitor { @@ -2599,9 +2556,9 @@ where } mod range_to { - use lib::*; + use crate::lib::*; - use de::{Deserialize, Deserializer, Error, MapAccess, SeqAccess, Visitor}; + use crate::de::{Deserialize, Deserializer, Error, MapAccess, SeqAccess, Visitor}; pub const FIELDS: &[&str] = &["start"]; @@ -2644,7 +2601,7 @@ mod range_to { match value { b"start" => Ok(Field::Start), _ => { - let value = ::__private::from_utf8_lossy(value); + let value = crate::__private::from_utf8_lossy(value); Err(Error::unknown_field(&*value, FIELDS)) } } @@ -2674,7 +2631,7 @@ mod range_to { where A: SeqAccess<'de>, { - let start: Idx = match try!(seq.next_element()) { + let start: Idx = match tri!(seq.next_element()) { Some(value) => value, None => { return Err(Error::invalid_length(0, &self)); @@ -2688,13 +2645,13 @@ mod range_to { A: MapAccess<'de>, { let mut start: Option = None; - while let Some(key) = try!(map.next_key()) { + while let Some(key) = tri!(map.next_key()) { match key { Field::Start => { if start.is_some() { return Err(::duplicate_field("start")); } - start = Some(try!(map.next_value())); + start = Some(tri!(map.next_value())); } } } @@ -2709,7 +2666,6 @@ mod range_to { //////////////////////////////////////////////////////////////////////////////// -#[cfg(any(not(no_ops_bound), all(feature = "std", not(no_collections_bound))))] impl<'de, T> Deserialize<'de> for Bound where T: Deserialize<'de>, @@ -2801,7 +2757,7 @@ where where A: EnumAccess<'de>, { - match try!(data.variant()) { + match tri!(data.variant()) { (Field::Unbounded, v) => v.unit_variant().map(|()| Bound::Unbounded), (Field::Included, v) => v.newtype_variant().map(Bound::Included), (Field::Excluded, v) => v.newtype_variant().map(Bound::Excluded), @@ -2910,7 +2866,7 @@ where where A: EnumAccess<'de>, { - match try!(data.variant()) { + match tri!(data.variant()) { (Field::Ok, v) => v.newtype_variant().map(Ok), (Field::Err, v) => v.newtype_variant().map(Err), } diff --git a/vendor/serde/src/de/mod.rs b/vendor/serde/src/de/mod.rs index a04ecf77d..afbc23af6 100644 --- a/vendor/serde/src/de/mod.rs +++ b/vendor/serde/src/de/mod.rs @@ -112,26 +112,28 @@ //! [derive section of the manual]: https://serde.rs/derive.html //! [data formats]: https://serde.rs/#data-formats -use lib::*; +use crate::lib::*; //////////////////////////////////////////////////////////////////////////////// pub mod value; -#[cfg(not(no_integer128))] mod format; mod ignored_any; mod impls; -mod utf8; +pub(crate) mod size_hint; pub use self::ignored_any::IgnoredAny; +#[cfg(not(any(feature = "std", feature = "unstable")))] +#[doc(no_inline)] +pub use crate::std_error::Error as StdError; +#[cfg(all(feature = "unstable", not(feature = "std")))] +#[doc(no_inline)] +pub use core::error::Error as StdError; #[cfg(feature = "std")] #[doc(no_inline)] pub use std::error::Error as StdError; -#[cfg(not(feature = "std"))] -#[doc(no_inline)] -pub use std_error::Error as StdError; //////////////////////////////////////////////////////////////////////////////// @@ -566,7 +568,7 @@ pub trait Deserialize<'de>: Sized { D: Deserializer<'de>, { // Default implementation just delegates to `deserialize` impl. - *place = try!(Deserialize::deserialize(deserializer)); + *place = tri!(Deserialize::deserialize(deserializer)); Ok(()) } } @@ -946,18 +948,15 @@ pub trait Deserializer<'de>: Sized { where V: Visitor<'de>; - serde_if_integer128! { - /// Hint that the `Deserialize` type is expecting an `i128` value. - /// - /// This method is available only on Rust compiler versions >=1.26. The - /// default behavior unconditionally returns an error. - fn deserialize_i128(self, visitor: V) -> Result - where - V: Visitor<'de> - { - let _ = visitor; - Err(Error::custom("i128 is not supported")) - } + /// Hint that the `Deserialize` type is expecting an `i128` value. + /// + /// The default behavior unconditionally returns an error. + fn deserialize_i128(self, visitor: V) -> Result + where + V: Visitor<'de>, + { + let _ = visitor; + Err(Error::custom("i128 is not supported")) } /// Hint that the `Deserialize` type is expecting a `u8` value. @@ -980,18 +979,15 @@ pub trait Deserializer<'de>: Sized { where V: Visitor<'de>; - serde_if_integer128! { - /// Hint that the `Deserialize` type is expecting an `u128` value. - /// - /// This method is available only on Rust compiler versions >=1.26. The - /// default behavior unconditionally returns an error. - fn deserialize_u128(self, visitor: V) -> Result - where - V: Visitor<'de> - { - let _ = visitor; - Err(Error::custom("u128 is not supported")) - } + /// Hint that the `Deserialize` type is expecting an `u128` value. + /// + /// The default behavior unconditionally returns an error. + fn deserialize_u128(self, visitor: V) -> Result + where + V: Visitor<'de>, + { + let _ = visitor; + Err(Error::custom("u128 is not supported")) } /// Hint that the `Deserialize` type is expecting a `f32` value. @@ -1226,11 +1222,11 @@ pub trait Deserializer<'de>: Sized { #[doc(hidden)] fn __deserialize_content( self, - _: ::actually_private::T, + _: crate::actually_private::T, visitor: V, - ) -> Result<::private::de::Content<'de>, Self::Error> + ) -> Result, Self::Error> where - V: Visitor<'de, Value = ::private::de::Content<'de>>, + V: Visitor<'de, Value = crate::__private::de::Content<'de>>, { self.deserialize_any(visitor) } @@ -1363,20 +1359,20 @@ pub trait Visitor<'de>: Sized { Err(Error::invalid_type(Unexpected::Signed(v), &self)) } - serde_if_integer128! { - /// The input contains a `i128`. - /// - /// This method is available only on Rust compiler versions >=1.26. The - /// default implementation fails with a type error. - fn visit_i128(self, v: i128) -> Result - where - E: Error, - { - let mut buf = [0u8; 58]; - let mut writer = format::Buf::new(&mut buf); - fmt::Write::write_fmt(&mut writer, format_args!("integer `{}` as i128", v)).unwrap(); - Err(Error::invalid_type(Unexpected::Other(writer.as_str()), &self)) - } + /// The input contains a `i128`. + /// + /// The default implementation fails with a type error. + fn visit_i128(self, v: i128) -> Result + where + E: Error, + { + let mut buf = [0u8; 58]; + let mut writer = format::Buf::new(&mut buf); + fmt::Write::write_fmt(&mut writer, format_args!("integer `{}` as i128", v)).unwrap(); + Err(Error::invalid_type( + Unexpected::Other(writer.as_str()), + &self, + )) } /// The input contains a `u8`. @@ -1425,20 +1421,20 @@ pub trait Visitor<'de>: Sized { Err(Error::invalid_type(Unexpected::Unsigned(v), &self)) } - serde_if_integer128! { - /// The input contains a `u128`. - /// - /// This method is available only on Rust compiler versions >=1.26. The - /// default implementation fails with a type error. - fn visit_u128(self, v: u128) -> Result - where - E: Error, - { - let mut buf = [0u8; 57]; - let mut writer = format::Buf::new(&mut buf); - fmt::Write::write_fmt(&mut writer, format_args!("integer `{}` as u128", v)).unwrap(); - Err(Error::invalid_type(Unexpected::Other(writer.as_str()), &self)) - } + /// The input contains a `u128`. + /// + /// The default implementation fails with a type error. + fn visit_u128(self, v: u128) -> Result + where + E: Error, + { + let mut buf = [0u8; 57]; + let mut writer = format::Buf::new(&mut buf); + fmt::Write::write_fmt(&mut writer, format_args!("integer `{}` as u128", v)).unwrap(); + Err(Error::invalid_type( + Unexpected::Other(writer.as_str()), + &self, + )) } /// The input contains an `f32`. @@ -1474,7 +1470,7 @@ pub trait Visitor<'de>: Sized { where E: Error, { - self.visit_str(utf8::encode(v).as_str()) + self.visit_str(v.encode_utf8(&mut [0u8; 4])) } /// The input contains a string. The lifetime of the string is ephemeral and @@ -1551,7 +1547,6 @@ pub trait Visitor<'de>: Sized { where E: Error, { - let _ = v; Err(Error::invalid_type(Unexpected::Bytes(v), &self)) } @@ -1831,9 +1826,9 @@ pub trait MapAccess<'de> { K: DeserializeSeed<'de>, V: DeserializeSeed<'de>, { - match try!(self.next_key_seed(kseed)) { + match tri!(self.next_key_seed(kseed)) { Some(key) => { - let value = try!(self.next_value_seed(vseed)); + let value = tri!(self.next_value_seed(vseed)); Ok(Some((key, value))) } None => Ok(None), @@ -2281,12 +2276,12 @@ impl Display for OneOf { 1 => write!(formatter, "`{}`", self.names[0]), 2 => write!(formatter, "`{}` or `{}`", self.names[0], self.names[1]), _ => { - try!(write!(formatter, "one of ")); + tri!(write!(formatter, "one of ")); for (i, alt) in self.names.iter().enumerate() { if i > 0 { - try!(write!(formatter, ", ")); + tri!(write!(formatter, ", ")); } - try!(write!(formatter, "`{}`", alt)); + tri!(write!(formatter, "`{}`", alt)); } Ok(()) } diff --git a/vendor/serde/src/de/seed.rs b/vendor/serde/src/de/seed.rs index 13b7ea461..52fb89d84 100644 --- a/vendor/serde/src/de/seed.rs +++ b/vendor/serde/src/de/seed.rs @@ -1,4 +1,4 @@ -use de::{Deserialize, DeserializeSeed, Deserializer}; +use crate::de::{Deserialize, DeserializeSeed, Deserializer}; /// A DeserializeSeed helper for implementing deserialize_in_place Visitors. /// diff --git a/vendor/serde/src/de/size_hint.rs b/vendor/serde/src/de/size_hint.rs new file mode 100644 index 000000000..4a4fe25dc --- /dev/null +++ b/vendor/serde/src/de/size_hint.rs @@ -0,0 +1,29 @@ +use crate::lib::*; + +pub fn from_bounds(iter: &I) -> Option +where + I: Iterator, +{ + helper(iter.size_hint()) +} + +#[cfg(any(feature = "std", feature = "alloc"))] +pub fn cautious(hint: Option) -> usize { + const MAX_PREALLOC_BYTES: usize = 1024 * 1024; + + if mem::size_of::() == 0 { + 0 + } else { + cmp::min( + hint.unwrap_or(0), + MAX_PREALLOC_BYTES / mem::size_of::(), + ) + } +} + +fn helper(bounds: (usize, Option)) -> Option { + match bounds { + (lower, Some(upper)) if lower == upper => Some(upper), + _ => None, + } +} diff --git a/vendor/serde/src/de/utf8.rs b/vendor/serde/src/de/utf8.rs deleted file mode 100644 index 96731cd63..000000000 --- a/vendor/serde/src/de/utf8.rs +++ /dev/null @@ -1,46 +0,0 @@ -use lib::*; - -const TAG_CONT: u8 = 0b1000_0000; -const TAG_TWO_B: u8 = 0b1100_0000; -const TAG_THREE_B: u8 = 0b1110_0000; -const TAG_FOUR_B: u8 = 0b1111_0000; -const MAX_ONE_B: u32 = 0x80; -const MAX_TWO_B: u32 = 0x800; -const MAX_THREE_B: u32 = 0x10000; - -#[inline] -pub fn encode(c: char) -> Encode { - let code = c as u32; - let mut buf = [0; 4]; - let pos = if code < MAX_ONE_B { - buf[3] = code as u8; - 3 - } else if code < MAX_TWO_B { - buf[2] = (code >> 6 & 0x1F) as u8 | TAG_TWO_B; - buf[3] = (code & 0x3F) as u8 | TAG_CONT; - 2 - } else if code < MAX_THREE_B { - buf[1] = (code >> 12 & 0x0F) as u8 | TAG_THREE_B; - buf[2] = (code >> 6 & 0x3F) as u8 | TAG_CONT; - buf[3] = (code & 0x3F) as u8 | TAG_CONT; - 1 - } else { - buf[0] = (code >> 18 & 0x07) as u8 | TAG_FOUR_B; - buf[1] = (code >> 12 & 0x3F) as u8 | TAG_CONT; - buf[2] = (code >> 6 & 0x3F) as u8 | TAG_CONT; - buf[3] = (code & 0x3F) as u8 | TAG_CONT; - 0 - }; - Encode { buf, pos } -} - -pub struct Encode { - buf: [u8; 4], - pos: usize, -} - -impl Encode { - pub fn as_str(&self) -> &str { - str::from_utf8(&self.buf[self.pos..]).unwrap() - } -} diff --git a/vendor/serde/src/de/value.rs b/vendor/serde/src/de/value.rs index 392f8a239..1234b8103 100644 --- a/vendor/serde/src/de/value.rs +++ b/vendor/serde/src/de/value.rs @@ -21,12 +21,11 @@ //! } //! ``` -use lib::*; +use crate::lib::*; use self::private::{First, Second}; -use __private::size_hint; -use de::{self, Deserializer, Expected, IntoDeserializer, SeqAccess, Visitor}; -use ser; +use crate::de::{self, size_hint, Deserializer, Expected, IntoDeserializer, SeqAccess, Visitor}; +use crate::ser; //////////////////////////////////////////////////////////////////////////////// @@ -293,20 +292,17 @@ primitive_deserializer!(i8, "an `i8`.", I8Deserializer, visit_i8); primitive_deserializer!(i16, "an `i16`.", I16Deserializer, visit_i16); primitive_deserializer!(i32, "an `i32`.", I32Deserializer, visit_i32); primitive_deserializer!(i64, "an `i64`.", I64Deserializer, visit_i64); +primitive_deserializer!(i128, "an `i128`.", I128Deserializer, visit_i128); primitive_deserializer!(isize, "an `isize`.", IsizeDeserializer, visit_i64 as i64); primitive_deserializer!(u8, "a `u8`.", U8Deserializer, visit_u8); primitive_deserializer!(u16, "a `u16`.", U16Deserializer, visit_u16); primitive_deserializer!(u64, "a `u64`.", U64Deserializer, visit_u64); +primitive_deserializer!(u128, "a `u128`.", U128Deserializer, visit_u128); primitive_deserializer!(usize, "a `usize`.", UsizeDeserializer, visit_u64 as u64); primitive_deserializer!(f32, "an `f32`.", F32Deserializer, visit_f32); primitive_deserializer!(f64, "an `f64`.", F64Deserializer, visit_f64); primitive_deserializer!(char, "a `char`.", CharDeserializer, visit_char); -serde_if_integer128! { - primitive_deserializer!(i128, "an `i128`.", I128Deserializer, visit_i128); - primitive_deserializer!(u128, "a `u128`.", U128Deserializer, visit_u128); -} - /// A deserializer holding a `u32`. pub struct U32Deserializer { value: u32, @@ -937,8 +933,8 @@ where where V: de::Visitor<'de>, { - let v = try!(visitor.visit_seq(&mut self)); - try!(self.end()); + let v = tri!(visitor.visit_seq(&mut self)); + tri!(self.end()); Ok(v) } @@ -1162,8 +1158,8 @@ where where V: de::Visitor<'de>, { - let value = try!(visitor.visit_map(&mut self)); - try!(self.end()); + let value = tri!(visitor.visit_map(&mut self)); + tri!(self.end()); Ok(value) } @@ -1171,8 +1167,8 @@ where where V: de::Visitor<'de>, { - let value = try!(visitor.visit_seq(&mut self)); - try!(self.end()); + let value = tri!(visitor.visit_seq(&mut self)); + tri!(self.end()); Ok(value) } @@ -1236,8 +1232,8 @@ where { match self.next_pair() { Some((key, value)) => { - let key = try!(kseed.deserialize(key.into_deserializer())); - let value = try!(vseed.deserialize(value.into_deserializer())); + let key = tri!(kseed.deserialize(key.into_deserializer())); + let value = tri!(vseed.deserialize(value.into_deserializer())); Ok(Some((key, value))) } None => Ok(None), @@ -1341,7 +1337,7 @@ where V: de::Visitor<'de>, { let mut pair_visitor = PairVisitor(Some(self.0), Some(self.1), PhantomData); - let pair = try!(visitor.visit_seq(&mut pair_visitor)); + let pair = tri!(visitor.visit_seq(&mut pair_visitor)); if pair_visitor.1.is_none() { Ok(pair) } else { @@ -1501,7 +1497,7 @@ where where T: de::DeserializeSeed<'de>, { - match try!(self.map.next_key_seed(seed)) { + match tri!(self.map.next_key_seed(seed)) { Some(key) => Ok((key, private::map_as_enum(self.map))), None => Err(de::Error::invalid_type(de::Unexpected::Map, &"enum")), } @@ -1546,9 +1542,11 @@ where //////////////////////////////////////////////////////////////////////////////// mod private { - use lib::*; + use crate::lib::*; - use de::{self, DeserializeSeed, Deserializer, MapAccess, Unexpected, VariantAccess, Visitor}; + use crate::de::{ + self, DeserializeSeed, Deserializer, MapAccess, Unexpected, VariantAccess, Visitor, + }; pub struct UnitOnly { marker: PhantomData, -- cgit v1.2.3