diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-18 02:49:50 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-18 02:49:50 +0000 |
commit | 9835e2ae736235810b4ea1c162ca5e65c547e770 (patch) | |
tree | 3fcebf40ed70e581d776a8a4c65923e8ec20e026 /vendor/serde_json/src | |
parent | Releasing progress-linux version 1.70.0+dfsg2-1~progress7.99u1. (diff) | |
download | rustc-9835e2ae736235810b4ea1c162ca5e65c547e770.tar.xz rustc-9835e2ae736235810b4ea1c162ca5e65c547e770.zip |
Merging upstream version 1.71.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/serde_json/src')
-rw-r--r-- | vendor/serde_json/src/error.rs | 2 | ||||
-rw-r--r-- | vendor/serde_json/src/lib.rs | 21 | ||||
-rw-r--r-- | vendor/serde_json/src/number.rs | 29 | ||||
-rw-r--r-- | vendor/serde_json/src/raw.rs | 2 | ||||
-rw-r--r-- | vendor/serde_json/src/value/from.rs | 2 | ||||
-rw-r--r-- | vendor/serde_json/src/value/mod.rs | 8 | ||||
-rw-r--r-- | vendor/serde_json/src/value/partial_eq.rs | 10 | ||||
-rw-r--r-- | vendor/serde_json/src/value/ser.rs | 43 |
8 files changed, 90 insertions, 27 deletions
diff --git a/vendor/serde_json/src/error.rs b/vendor/serde_json/src/error.rs index 1875ef08b..0898baf90 100644 --- a/vendor/serde_json/src/error.rs +++ b/vendor/serde_json/src/error.rs @@ -319,7 +319,7 @@ impl serde::de::StdError for Error { #[cfg(feature = "std")] fn source(&self) -> Option<&(dyn error::Error + 'static)> { match &self.err.code { - ErrorCode::Io(err) => Some(err), + ErrorCode::Io(err) => err.source(), _ => None, } } diff --git a/vendor/serde_json/src/lib.rs b/vendor/serde_json/src/lib.rs index fdd95a121..95242d40b 100644 --- a/vendor/serde_json/src/lib.rs +++ b/vendor/serde_json/src/lib.rs @@ -104,7 +104,7 @@ //! a JSON string to a Rust string with [`as_str()`] or avoiding the use of //! `Value` as described in the following section. //! -//! [`as_str()`]: https://docs.serde.rs/serde_json/enum.Value.html#method.as_str +//! [`as_str()`]: crate::Value::as_str //! //! The `Value` representation is sufficient for very basic tasks but can be //! tedious to work with for anything more significant. Error handling is @@ -290,17 +290,17 @@ //! For JSON support in Serde without a memory allocator, please see the //! [`serde-json-core`] crate. //! -//! [value]: https://docs.serde.rs/serde_json/value/enum.Value.html -//! [from_str]: https://docs.serde.rs/serde_json/de/fn.from_str.html -//! [from_slice]: https://docs.serde.rs/serde_json/de/fn.from_slice.html -//! [from_reader]: https://docs.serde.rs/serde_json/de/fn.from_reader.html -//! [to_string]: https://docs.serde.rs/serde_json/ser/fn.to_string.html -//! [to_vec]: https://docs.serde.rs/serde_json/ser/fn.to_vec.html -//! [to_writer]: https://docs.serde.rs/serde_json/ser/fn.to_writer.html -//! [macro]: https://docs.serde.rs/serde_json/macro.json.html +//! [value]: crate::value::Value +//! [from_str]: crate::de::from_str +//! [from_slice]: crate::de::from_slice +//! [from_reader]: crate::de::from_reader +//! [to_string]: crate::ser::to_string +//! [to_vec]: crate::ser::to_vec +//! [to_writer]: crate::ser::to_writer +//! [macro]: crate::json //! [`serde-json-core`]: https://github.com/rust-embedded-community/serde-json-core -#![doc(html_root_url = "https://docs.rs/serde_json/1.0.91")] +#![doc(html_root_url = "https://docs.rs/serde_json/1.0.95")] // Ignored clippy lints #![allow( clippy::collapsible_else_if, @@ -338,6 +338,7 @@ clippy::enum_glob_use, clippy::if_not_else, clippy::integer_division, + clippy::let_underscore_untyped, clippy::map_err_ignore, clippy::match_same_arms, clippy::similar_names, diff --git a/vendor/serde_json/src/number.rs b/vendor/serde_json/src/number.rs index 21a76411c..5ecbde873 100644 --- a/vendor/serde_json/src/number.rs +++ b/vendor/serde_json/src/number.rs @@ -279,6 +279,35 @@ impl Number { } } + pub(crate) fn as_f32(&self) -> Option<f32> { + #[cfg(not(feature = "arbitrary_precision"))] + match self.n { + N::PosInt(n) => Some(n as f32), + N::NegInt(n) => Some(n as f32), + N::Float(n) => Some(n as f32), + } + #[cfg(feature = "arbitrary_precision")] + self.n.parse::<f32>().ok().filter(|float| float.is_finite()) + } + + pub(crate) fn from_f32(f: f32) -> Option<Number> { + if f.is_finite() { + let n = { + #[cfg(not(feature = "arbitrary_precision"))] + { + N::Float(f as f64) + } + #[cfg(feature = "arbitrary_precision")] + { + ryu::Buffer::new().format_finite(f).to_owned() + } + }; + Some(Number { n }) + } else { + None + } + } + #[cfg(feature = "arbitrary_precision")] /// Not public API. Only tests use this. #[doc(hidden)] diff --git a/vendor/serde_json/src/raw.rs b/vendor/serde_json/src/raw.rs index c8377ac82..6aa4ffcb6 100644 --- a/vendor/serde_json/src/raw.rs +++ b/vendor/serde_json/src/raw.rs @@ -112,7 +112,7 @@ use serde::ser::{Serialize, SerializeStruct, Serializer}; /// raw_value: Box<RawValue>, /// } /// ``` -#[repr(C)] +#[cfg_attr(not(doc), repr(transparent))] #[cfg_attr(docsrs, doc(cfg(feature = "raw_value")))] pub struct RawValue { json: str, diff --git a/vendor/serde_json/src/value/from.rs b/vendor/serde_json/src/value/from.rs index c5a6a3960..462ad3f51 100644 --- a/vendor/serde_json/src/value/from.rs +++ b/vendor/serde_json/src/value/from.rs @@ -40,7 +40,7 @@ impl From<f32> for Value { /// let x: Value = f.into(); /// ``` fn from(f: f32) -> Self { - From::from(f as f64) + Number::from_f32(f).map_or(Value::Null, Value::Number) } } diff --git a/vendor/serde_json/src/value/mod.rs b/vendor/serde_json/src/value/mod.rs index c467df6cc..470b6b24d 100644 --- a/vendor/serde_json/src/value/mod.rs +++ b/vendor/serde_json/src/value/mod.rs @@ -85,10 +85,10 @@ //! # untyped_example().unwrap(); //! ``` //! -//! [macro]: https://docs.serde.rs/serde_json/macro.json.html -//! [from_str]: https://docs.serde.rs/serde_json/de/fn.from_str.html -//! [from_slice]: https://docs.serde.rs/serde_json/de/fn.from_slice.html -//! [from_reader]: https://docs.serde.rs/serde_json/de/fn.from_reader.html +//! [macro]: crate::json +//! [from_str]: crate::de::from_str +//! [from_slice]: crate::de::from_slice +//! [from_reader]: crate::de::from_reader use crate::error::Error; use crate::io; diff --git a/vendor/serde_json/src/value/partial_eq.rs b/vendor/serde_json/src/value/partial_eq.rs index b4ef84c4f..6b2e350b6 100644 --- a/vendor/serde_json/src/value/partial_eq.rs +++ b/vendor/serde_json/src/value/partial_eq.rs @@ -9,6 +9,13 @@ fn eq_u64(value: &Value, other: u64) -> bool { value.as_u64().map_or(false, |i| i == other) } +fn eq_f32(value: &Value, other: f32) -> bool { + match value { + Value::Number(n) => n.as_f32().map_or(false, |i| i == other), + _ => false, + } +} + fn eq_f64(value: &Value, other: f64) -> bool { value.as_f64().map_or(false, |i| i == other) } @@ -90,6 +97,7 @@ macro_rules! partialeq_numeric { partialeq_numeric! { eq_i64[i8 i16 i32 i64 isize] eq_u64[u8 u16 u32 u64 usize] - eq_f64[f32 f64] + eq_f32[f32] + eq_f64[f64] eq_bool[bool] } diff --git a/vendor/serde_json/src/value/ser.rs b/vendor/serde_json/src/value/ser.rs index 892a63d5f..875d22e24 100644 --- a/vendor/serde_json/src/value/ser.rs +++ b/vendor/serde_json/src/value/ser.rs @@ -1,10 +1,11 @@ use crate::error::{Error, ErrorCode, Result}; use crate::map::Map; -use crate::number::Number; use crate::value::{to_value, Value}; use alloc::borrow::ToOwned; use alloc::string::{String, ToString}; use alloc::vec::Vec; +#[cfg(not(feature = "arbitrary_precision"))] +use core::convert::TryFrom; use core::fmt::Display; use core::result; use serde::ser::{Impossible, Serialize}; @@ -92,9 +93,22 @@ impl serde::Serializer for Serializer { Ok(Value::Number(value.into())) } - #[cfg(feature = "arbitrary_precision")] fn serialize_i128(self, value: i128) -> Result<Value> { - Ok(Value::Number(value.into())) + #[cfg(feature = "arbitrary_precision")] + { + Ok(Value::Number(value.into())) + } + + #[cfg(not(feature = "arbitrary_precision"))] + { + if let Ok(value) = u64::try_from(value) { + Ok(Value::Number(value.into())) + } else if let Ok(value) = i64::try_from(value) { + Ok(Value::Number(value.into())) + } else { + Err(Error::syntax(ErrorCode::NumberOutOfRange, 0, 0)) + } + } } #[inline] @@ -117,19 +131,30 @@ impl serde::Serializer for Serializer { Ok(Value::Number(value.into())) } - #[cfg(feature = "arbitrary_precision")] fn serialize_u128(self, value: u128) -> Result<Value> { - Ok(Value::Number(value.into())) + #[cfg(feature = "arbitrary_precision")] + { + Ok(Value::Number(value.into())) + } + + #[cfg(not(feature = "arbitrary_precision"))] + { + if let Ok(value) = u64::try_from(value) { + Ok(Value::Number(value.into())) + } else { + Err(Error::syntax(ErrorCode::NumberOutOfRange, 0, 0)) + } + } } #[inline] - fn serialize_f32(self, value: f32) -> Result<Value> { - self.serialize_f64(value as f64) + fn serialize_f32(self, float: f32) -> Result<Value> { + Ok(Value::from(float)) } #[inline] - fn serialize_f64(self, value: f64) -> Result<Value> { - Ok(Number::from_f64(value).map_or(Value::Null, Value::Number)) + fn serialize_f64(self, float: f64) -> Result<Value> { + Ok(Value::from(float)) } #[inline] |