summaryrefslogtreecommitdiffstats
path: root/vendor/serde/src/de/impls.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:59:35 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:59:35 +0000
commitd1b2d29528b7794b41e66fc2136e395a02f8529b (patch)
treea4a17504b260206dec3cf55b2dca82929a348ac2 /vendor/serde/src/de/impls.rs
parentReleasing progress-linux version 1.72.1+dfsg1-1~progress7.99u1. (diff)
downloadrustc-d1b2d29528b7794b41e66fc2136e395a02f8529b.tar.xz
rustc-d1b2d29528b7794b41e66fc2136e395a02f8529b.zip
Merging upstream version 1.73.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/serde/src/de/impls.rs')
-rw-r--r--vendor/serde/src/de/impls.rs323
1 files changed, 299 insertions, 24 deletions
diff --git a/vendor/serde/src/de/impls.rs b/vendor/serde/src/de/impls.rs
index 7dd3bc327..12fbdfdb3 100644
--- a/vendor/serde/src/de/impls.rs
+++ b/vendor/serde/src/de/impls.rs
@@ -681,8 +681,8 @@ impl<'de> Visitor<'de> for CStringVisitor {
where
A: SeqAccess<'de>,
{
- let len = size_hint::cautious(seq.size_hint());
- let mut values = Vec::with_capacity(len);
+ let capacity = size_hint::cautious::<u8>(seq.size_hint());
+ let mut values = Vec::<u8>::with_capacity(capacity);
while let Some(value) = try!(seq.next_element()) {
values.push(value);
@@ -936,7 +936,7 @@ macro_rules! seq_impl {
A: SeqAccess<'de>,
{
$clear(&mut self.0);
- $reserve(&mut self.0, size_hint::cautious($access.size_hint()));
+ $reserve(&mut self.0, size_hint::cautious::<T>($access.size_hint()));
// FIXME: try to overwrite old values here? (Vec, VecDeque, LinkedList)
while let Some(value) = try!($access.next_element()) {
@@ -962,7 +962,7 @@ seq_impl!(
BinaryHeap<T: Ord>,
seq,
BinaryHeap::clear,
- BinaryHeap::with_capacity(size_hint::cautious(seq.size_hint())),
+ BinaryHeap::with_capacity(size_hint::cautious::<T>(seq.size_hint())),
BinaryHeap::reserve,
BinaryHeap::push
);
@@ -992,7 +992,7 @@ seq_impl!(
HashSet<T: Eq + Hash, S: BuildHasher + Default>,
seq,
HashSet::clear,
- HashSet::with_capacity_and_hasher(size_hint::cautious(seq.size_hint()), S::default()),
+ HashSet::with_capacity_and_hasher(size_hint::cautious::<T>(seq.size_hint()), S::default()),
HashSet::reserve,
HashSet::insert
);
@@ -1002,7 +1002,7 @@ seq_impl!(
VecDeque<T>,
seq,
VecDeque::clear,
- VecDeque::with_capacity(size_hint::cautious(seq.size_hint())),
+ VecDeque::with_capacity(size_hint::cautious::<T>(seq.size_hint())),
VecDeque::reserve,
VecDeque::push_back
);
@@ -1036,7 +1036,8 @@ where
where
A: SeqAccess<'de>,
{
- let mut values = Vec::with_capacity(size_hint::cautious(seq.size_hint()));
+ let capacity = size_hint::cautious::<T>(seq.size_hint());
+ let mut values = Vec::<T>::with_capacity(capacity);
while let Some(value) = try!(seq.next_element()) {
values.push(value);
@@ -1072,7 +1073,7 @@ where
where
A: SeqAccess<'de>,
{
- let hint = size_hint::cautious(seq.size_hint());
+ let hint = size_hint::cautious::<T>(seq.size_hint());
if let Some(additional) = hint.checked_sub(self.0.len()) {
self.0.reserve(additional);
}
@@ -1416,7 +1417,7 @@ map_impl!(BTreeMap<K: Ord, V>, map, BTreeMap::new());
map_impl!(
HashMap<K: Eq + Hash, V, S: BuildHasher + Default>,
map,
- HashMap::with_capacity_and_hasher(size_hint::cautious(map.size_hint()), S::default())
+ HashMap::with_capacity_and_hasher(size_hint::cautious::<(K, V)>(map.size_hint()), S::default())
);
////////////////////////////////////////////////////////////////////////////////
@@ -1450,7 +1451,7 @@ macro_rules! variant_identifier {
$($variant),*
}
- static $variants_name: &'static [&'static str] = &[$(stringify!($variant)),*];
+ static $variants_name: &[&str] = &[$(stringify!($variant)),*];
impl<'de> Deserialize<'de> for $name_kind {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
@@ -1587,7 +1588,7 @@ macro_rules! parse_socket_impl {
if deserializer.is_human_readable() {
deserializer.deserialize_str(FromStrVisitor::new($expecting))
} else {
- <(_, u16)>::deserialize(deserializer).map(|(ip, port)| $new(ip, port))
+ <(_, u16)>::deserialize(deserializer).map($new)
}
}
}
@@ -1614,12 +1615,10 @@ impl<'de> Deserialize<'de> for net::SocketAddr {
}
#[cfg(feature = "std")]
-parse_socket_impl!("IPv4 socket address" net::SocketAddrV4, net::SocketAddrV4::new);
+parse_socket_impl!("IPv4 socket address" net::SocketAddrV4, |(ip, port)| net::SocketAddrV4::new(ip, port));
#[cfg(feature = "std")]
-parse_socket_impl!("IPv6 socket address" net::SocketAddrV6, |ip, port| net::SocketAddrV6::new(
- ip, port, 0, 0
-));
+parse_socket_impl!("IPv6 socket address" net::SocketAddrV6, |(ip, port)| net::SocketAddrV6::new(ip, port, 0, 0));
////////////////////////////////////////////////////////////////////////////////
@@ -2098,7 +2097,7 @@ impl<'de> Deserialize<'de> for Duration {
}
}
- const FIELDS: &'static [&'static str] = &["secs", "nanos"];
+ const FIELDS: &[&str] = &["secs", "nanos"];
deserializer.deserialize_struct("Duration", FIELDS, DurationVisitor)
}
}
@@ -2240,7 +2239,7 @@ impl<'de> Deserialize<'de> for SystemTime {
}
}
- const FIELDS: &'static [&'static str] = &["secs_since_epoch", "nanos_since_epoch"];
+ const FIELDS: &[&str] = &["secs_since_epoch", "nanos_since_epoch"];
let duration = try!(deserializer.deserialize_struct("SystemTime", FIELDS, DurationVisitor));
#[cfg(not(no_systemtime_checked_add))]
let ret = UNIX_EPOCH
@@ -2258,9 +2257,9 @@ impl<'de> Deserialize<'de> for SystemTime {
//
// #[derive(Deserialize)]
// #[serde(deny_unknown_fields)]
-// struct Range {
-// start: u64,
-// end: u32,
+// struct Range<Idx> {
+// start: Idx,
+// end: Idx,
// }
impl<'de, Idx> Deserialize<'de> for Range<Idx>
where
@@ -2308,7 +2307,7 @@ mod range {
use de::{Deserialize, Deserializer, Error, MapAccess, SeqAccess, Visitor};
- pub const FIELDS: &'static [&'static str] = &["start", "end"];
+ pub const FIELDS: &[&str] = &["start", "end"];
// If this were outside of the serde crate, it would just use:
//
@@ -2434,6 +2433,282 @@ mod range {
////////////////////////////////////////////////////////////////////////////////
+// Similar to:
+//
+// #[derive(Deserialize)]
+// #[serde(deny_unknown_fields)]
+// struct RangeFrom<Idx> {
+// start: Idx,
+// }
+impl<'de, Idx> Deserialize<'de> for RangeFrom<Idx>
+where
+ Idx: Deserialize<'de>,
+{
+ fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
+ where
+ D: Deserializer<'de>,
+ {
+ let start = try!(deserializer.deserialize_struct(
+ "RangeFrom",
+ range_from::FIELDS,
+ range_from::RangeFromVisitor {
+ expecting: "struct RangeFrom",
+ phantom: PhantomData,
+ },
+ ));
+ Ok(start..)
+ }
+}
+
+mod range_from {
+ use lib::*;
+
+ use de::{Deserialize, Deserializer, Error, MapAccess, SeqAccess, Visitor};
+
+ pub const FIELDS: &[&str] = &["end"];
+
+ // If this were outside of the serde crate, it would just use:
+ //
+ // #[derive(Deserialize)]
+ // #[serde(field_identifier, rename_all = "lowercase")]
+ enum Field {
+ End,
+ }
+
+ impl<'de> Deserialize<'de> for Field {
+ fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
+ where
+ D: Deserializer<'de>,
+ {
+ struct FieldVisitor;
+
+ impl<'de> Visitor<'de> for FieldVisitor {
+ type Value = Field;
+
+ fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
+ formatter.write_str("`end`")
+ }
+
+ fn visit_str<E>(self, value: &str) -> Result<Self::Value, E>
+ where
+ E: Error,
+ {
+ match value {
+ "end" => Ok(Field::End),
+ _ => Err(Error::unknown_field(value, FIELDS)),
+ }
+ }
+
+ fn visit_bytes<E>(self, value: &[u8]) -> Result<Self::Value, E>
+ where
+ E: Error,
+ {
+ match value {
+ b"end" => Ok(Field::End),
+ _ => {
+ let value = ::__private::from_utf8_lossy(value);
+ Err(Error::unknown_field(&*value, FIELDS))
+ }
+ }
+ }
+ }
+
+ deserializer.deserialize_identifier(FieldVisitor)
+ }
+ }
+
+ pub struct RangeFromVisitor<Idx> {
+ pub expecting: &'static str,
+ pub phantom: PhantomData<Idx>,
+ }
+
+ impl<'de, Idx> Visitor<'de> for RangeFromVisitor<Idx>
+ where
+ Idx: Deserialize<'de>,
+ {
+ type Value = Idx;
+
+ fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
+ formatter.write_str(self.expecting)
+ }
+
+ fn visit_seq<A>(self, mut seq: A) -> Result<Self::Value, A::Error>
+ where
+ A: SeqAccess<'de>,
+ {
+ let end: Idx = match try!(seq.next_element()) {
+ Some(value) => value,
+ None => {
+ return Err(Error::invalid_length(0, &self));
+ }
+ };
+ Ok(end)
+ }
+
+ fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error>
+ where
+ A: MapAccess<'de>,
+ {
+ let mut end: Option<Idx> = None;
+ while let Some(key) = try!(map.next_key()) {
+ match key {
+ Field::End => {
+ if end.is_some() {
+ return Err(<A::Error as Error>::duplicate_field("end"));
+ }
+ end = Some(try!(map.next_value()));
+ }
+ }
+ }
+ let end = match end {
+ Some(end) => end,
+ None => return Err(<A::Error as Error>::missing_field("end")),
+ };
+ Ok(end)
+ }
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+
+// Similar to:
+//
+// #[derive(Deserialize)]
+// #[serde(deny_unknown_fields)]
+// struct RangeTo<Idx> {
+// start: Idx,
+// }
+impl<'de, Idx> Deserialize<'de> for RangeTo<Idx>
+where
+ Idx: Deserialize<'de>,
+{
+ fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
+ where
+ D: Deserializer<'de>,
+ {
+ let end = try!(deserializer.deserialize_struct(
+ "RangeTo",
+ range_to::FIELDS,
+ range_to::RangeToVisitor {
+ expecting: "struct RangeTo",
+ phantom: PhantomData,
+ },
+ ));
+ Ok(..end)
+ }
+}
+
+mod range_to {
+ use lib::*;
+
+ use de::{Deserialize, Deserializer, Error, MapAccess, SeqAccess, Visitor};
+
+ pub const FIELDS: &[&str] = &["start"];
+
+ // If this were outside of the serde crate, it would just use:
+ //
+ // #[derive(Deserialize)]
+ // #[serde(field_identifier, rename_all = "lowercase")]
+ enum Field {
+ Start,
+ }
+
+ impl<'de> Deserialize<'de> for Field {
+ fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
+ where
+ D: Deserializer<'de>,
+ {
+ struct FieldVisitor;
+
+ impl<'de> Visitor<'de> for FieldVisitor {
+ type Value = Field;
+
+ fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
+ formatter.write_str("`start`")
+ }
+
+ fn visit_str<E>(self, value: &str) -> Result<Self::Value, E>
+ where
+ E: Error,
+ {
+ match value {
+ "start" => Ok(Field::Start),
+ _ => Err(Error::unknown_field(value, FIELDS)),
+ }
+ }
+
+ fn visit_bytes<E>(self, value: &[u8]) -> Result<Self::Value, E>
+ where
+ E: Error,
+ {
+ match value {
+ b"start" => Ok(Field::Start),
+ _ => {
+ let value = ::__private::from_utf8_lossy(value);
+ Err(Error::unknown_field(&*value, FIELDS))
+ }
+ }
+ }
+ }
+
+ deserializer.deserialize_identifier(FieldVisitor)
+ }
+ }
+
+ pub struct RangeToVisitor<Idx> {
+ pub expecting: &'static str,
+ pub phantom: PhantomData<Idx>,
+ }
+
+ impl<'de, Idx> Visitor<'de> for RangeToVisitor<Idx>
+ where
+ Idx: Deserialize<'de>,
+ {
+ type Value = Idx;
+
+ fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
+ formatter.write_str(self.expecting)
+ }
+
+ fn visit_seq<A>(self, mut seq: A) -> Result<Self::Value, A::Error>
+ where
+ A: SeqAccess<'de>,
+ {
+ let start: Idx = match try!(seq.next_element()) {
+ Some(value) => value,
+ None => {
+ return Err(Error::invalid_length(0, &self));
+ }
+ };
+ Ok(start)
+ }
+
+ fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error>
+ where
+ A: MapAccess<'de>,
+ {
+ let mut start: Option<Idx> = None;
+ while let Some(key) = try!(map.next_key()) {
+ match key {
+ Field::Start => {
+ if start.is_some() {
+ return Err(<A::Error as Error>::duplicate_field("start"));
+ }
+ start = Some(try!(map.next_value()));
+ }
+ }
+ }
+ let start = match start {
+ Some(start) => start,
+ None => return Err(<A::Error as Error>::missing_field("start")),
+ };
+ Ok(start)
+ }
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+
#[cfg(any(not(no_ops_bound), all(feature = "std", not(no_collections_bound))))]
impl<'de, T> Deserialize<'de> for Bound<T>
where
@@ -2534,7 +2809,7 @@ where
}
}
- const VARIANTS: &'static [&'static str] = &["Unbounded", "Included", "Excluded"];
+ const VARIANTS: &[&str] = &["Unbounded", "Included", "Excluded"];
deserializer.deserialize_enum("Bound", VARIANTS, BoundVisitor(PhantomData))
}
@@ -2642,7 +2917,7 @@ where
}
}
- const VARIANTS: &'static [&'static str] = &["Ok", "Err"];
+ const VARIANTS: &[&str] = &["Ok", "Err"];
deserializer.deserialize_enum("Result", VARIANTS, ResultVisitor(PhantomData))
}
@@ -2708,7 +2983,7 @@ struct FromStrVisitor<T> {
impl<T> FromStrVisitor<T> {
fn new(expecting: &'static str) -> Self {
FromStrVisitor {
- expecting: expecting,
+ expecting,
ty: PhantomData,
}
}