From 6d44b9fac9269b4decf76acac5d68e8ec9d10c58 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Thu, 11 Jan 2024 20:16:54 -0800 Subject: [PATCH 01/30] Ignore unconditional_recursion clippy lint due to false positive https://github.com/rust-lang/rust-clippy/issues/12133 warning: function cannot return without recursing --> src/map.rs:276:5 | 276 | / fn eq(&self, other: &Self) -> bool { 277 | | self.map.eq(&other.map) 278 | | } | |_____^ | note: recursive call site --> src/map.rs:277:9 | 277 | self.map.eq(&other.map) | ^^^^^^^^^^^^^^^^^^^^^^^ = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unconditional_recursion = note: `-W clippy::unconditional-recursion` implied by `-W clippy::all` = help: to override `-W clippy::all` add `#[allow(clippy::unconditional_recursion)]` --- src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib.rs b/src/lib.rs index 3cdbd3ae3..238027b6f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -316,6 +316,7 @@ clippy::needless_late_init, clippy::return_self_not_must_use, clippy::transmute_ptr_to_ptr, + clippy::unconditional_recursion, // https://github.com/rust-lang/rust-clippy/issues/12133 clippy::unnecessary_wraps )] // Ignored clippy_pedantic lints From 2909b0bac6bce0316ae5d7a62edc819c8b9d1173 Mon Sep 17 00:00:00 2001 From: keienWang <42377006+keienWang@users.noreply.github.com> Date: Fri, 26 Jan 2024 22:00:51 +0800 Subject: [PATCH 02/30] fix: Correct spelling error Fixed a spelling error in the second paragraph of the README file. - Changed "exponet" to "exponent" --- src/lexical/num.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lexical/num.rs b/src/lexical/num.rs index e47e00341..af10afd7a 100644 --- a/src/lexical/num.rs +++ b/src/lexical/num.rs @@ -223,7 +223,7 @@ pub trait Float: Number { const NEGATIVE_INFINITY_BITS: Self::Unsigned; /// Size of the significand (mantissa) without hidden bit. const MANTISSA_SIZE: i32; - /// Bias of the exponet + /// Bias of the exponent const EXPONENT_BIAS: i32; /// Exponent portion of a denormal float. const DENORMAL_EXPONENT: i32; From 296fafb8f32e8442ef8e4d5725c15ffca726b288 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Fri, 26 Jan 2024 13:03:05 -0800 Subject: [PATCH 03/30] Factor out JSON-specific Display impl for serde::de::Unexpected --- src/error.rs | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/error.rs b/src/error.rs index 03555eb4c..c260fe17e 100644 --- a/src/error.rs +++ b/src/error.rs @@ -438,11 +438,11 @@ impl de::Error for Error { #[cold] fn invalid_type(unexp: de::Unexpected, exp: &dyn de::Expected) -> Self { - if let de::Unexpected::Unit = unexp { - Error::custom(format_args!("invalid type: null, expected {}", exp)) - } else { - Error::custom(format_args!("invalid type: {}, expected {}", unexp, exp)) - } + Error::custom(format_args!( + "invalid type: {}, expected {}", + JsonUnexpected(unexp), + exp, + )) } } @@ -453,6 +453,18 @@ impl ser::Error for Error { } } +struct JsonUnexpected<'a>(de::Unexpected<'a>); + +impl<'a> Display for JsonUnexpected<'a> { + fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { + if let de::Unexpected::Unit = self.0 { + formatter.write_str("null") + } else { + Display::fmt(&self.0, formatter) + } + } +} + // Parse our own error message that looks like "{} at line {} column {}" to work // around erased-serde round-tripping the error through de::Error::custom. fn make_error(mut msg: String) -> Error { From 62ca3e4c01c2e62cd5c2a32e9104f386e5ce7808 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Fri, 26 Jan 2024 13:04:35 -0800 Subject: [PATCH 04/30] Handle Unexpected::Unit in Error::invalid_value --- src/error.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/error.rs b/src/error.rs index c260fe17e..0e3323972 100644 --- a/src/error.rs +++ b/src/error.rs @@ -444,6 +444,15 @@ impl de::Error for Error { exp, )) } + + #[cold] + fn invalid_value(unexp: de::Unexpected, exp: &dyn de::Expected) -> Self { + Error::custom(format_args!( + "invalid value: {}, expected {}", + JsonUnexpected(unexp), + exp, + )) + } } impl ser::Error for Error { From 83d7bad54ba5db3a44198d6df0ff2e81621683fa Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Fri, 26 Jan 2024 13:14:48 -0800 Subject: [PATCH 05/30] Format f64 in error messages using ryu --- src/error.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/error.rs b/src/error.rs index 0e3323972..fbf9eb14e 100644 --- a/src/error.rs +++ b/src/error.rs @@ -466,10 +466,14 @@ struct JsonUnexpected<'a>(de::Unexpected<'a>); impl<'a> Display for JsonUnexpected<'a> { fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { - if let de::Unexpected::Unit = self.0 { - formatter.write_str("null") - } else { - Display::fmt(&self.0, formatter) + match self.0 { + de::Unexpected::Unit => formatter.write_str("null"), + de::Unexpected::Float(value) => write!( + formatter, + "floating point `{}`", + ryu::Buffer::new().format(value), + ), + unexp => Display::fmt(&unexp, formatter), } } } From 7fece969e3b480ec620419d65c2aeb08776bebcb Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Fri, 26 Jan 2024 14:02:01 -0800 Subject: [PATCH 06/30] Release 1.0.112 --- Cargo.toml | 2 +- src/lib.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d4ea3c8d2..4166d7a87 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "serde_json" -version = "1.0.111" +version = "1.0.112" authors = ["Erick Tryzelaar ", "David Tolnay "] categories = ["encoding", "parser-implementations", "no-std"] description = "A JSON serialization file format" diff --git a/src/lib.rs b/src/lib.rs index 238027b6f..9526fc1bb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -299,7 +299,7 @@ //! [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.111")] +#![doc(html_root_url = "https://docs.rs/serde_json/1.0.112")] // Ignored clippy lints #![allow( clippy::collapsible_else_if, From ca3c2ca3696cab79b8b279be7569ee1647250f1e Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sun, 28 Jan 2024 19:36:33 -0800 Subject: [PATCH 07/30] Add swap_remove and shift_remove methods on Map --- Cargo.toml | 4 +-- src/map.rs | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 84 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4166d7a87..2e21afb3a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,7 @@ repository = "https://github.com/serde-rs/json" rust-version = "1.56" [dependencies] -indexmap = { version = "2", optional = true } +indexmap = { version = "2.2.1", optional = true } itoa = "1.0" ryu = "1.0" serde = { version = "1.0.194", default-features = false } @@ -32,7 +32,7 @@ trybuild = { version = "1.0.81", features = ["diff"] } doc-scrape-examples = false [package.metadata.docs.rs] -features = ["raw_value", "unbounded_depth"] +features = ["preserve_order", "raw_value", "unbounded_depth"] targets = ["x86_64-unknown-linux-gnu"] rustdoc-args = ["--cfg", "docsrs", "--generate-link-to-definition"] diff --git a/src/map.rs b/src/map.rs index 675058ba1..1d74e1b2b 100644 --- a/src/map.rs +++ b/src/map.rs @@ -130,6 +130,12 @@ impl Map { /// /// The key may be any borrowed form of the map's key type, but the ordering /// on the borrowed form *must* match the ordering on the key type. + /// + /// If serde_json's "preserve_order" is enabled, `.remove(key)` is + /// equivalent to [`.swap_remove(key)`][Self::swap_remove], replacing this + /// entry's position with the last element. If you need to preserve the + /// relative order of the keys in the map, use + /// [`.shift_remove(key)`][Self::shift_remove] instead. #[inline] pub fn remove(&mut self, key: &Q) -> Option where @@ -137,7 +143,7 @@ impl Map { Q: ?Sized + Ord + Eq + Hash, { #[cfg(feature = "preserve_order")] - return self.map.swap_remove(key); + return self.swap_remove(key); #[cfg(not(feature = "preserve_order"))] return self.map.remove(key); } @@ -147,12 +153,86 @@ impl Map { /// /// The key may be any borrowed form of the map's key type, but the ordering /// on the borrowed form *must* match the ordering on the key type. + /// + /// If serde_json's "preserve_order" is enabled, `.remove_entry(key)` is + /// equivalent to [`.swap_remove_entry(key)`][Self::swap_remove_entry], + /// replacing this entry's position with the last element. If you need to + /// preserve the relative order of the keys in the map, use + /// [`.shift_remove_entry(key)`][Self::shift_remove_entry] instead. + #[inline] pub fn remove_entry(&mut self, key: &Q) -> Option<(String, Value)> where String: Borrow, Q: ?Sized + Ord + Eq + Hash, { - self.map.remove_entry(key) + #[cfg(feature = "preserve_order")] + return self.swap_remove_entry(key); + #[cfg(not(feature = "preserve_order"))] + return self.map.remove_entry(key); + } + + /// Removes and returns the value corresponding to the key from the map. + /// + /// Like [`Vec::swap_remove`], the entry is removed by swapping it with the + /// last element of the map and popping it off. This perturbs the position + /// of what used to be the last element! + #[cfg(feature = "preserve_order")] + #[cfg_attr(docsrs, doc(cfg(feature = "preserve_order")))] + #[inline] + pub fn swap_remove(&mut self, key: &Q) -> Option + where + String: Borrow, + Q: ?Sized + Ord + Eq + Hash, + { + self.map.swap_remove(key) + } + + /// Remove and return the key-value pair. + /// + /// Like [`Vec::swap_remove`], the entry is removed by swapping it with the + /// last element of the map and popping it off. This perturbs the position + /// of what used to be the last element! + #[cfg(feature = "preserve_order")] + #[cfg_attr(docsrs, doc(cfg(feature = "preserve_order")))] + #[inline] + pub fn swap_remove_entry(&mut self, key: &Q) -> Option<(String, Value)> + where + String: Borrow, + Q: ?Sized + Ord + Eq + Hash, + { + self.map.swap_remove_entry(key) + } + + /// Removes and returns the value corresponding to the key from the map. + /// + /// Like [`Vec::remove`], the entry is removed by shifting all of the + /// elements that follow it, preserving their relative order. This perturbs + /// the index of all of those elements! + #[cfg(feature = "preserve_order")] + #[cfg_attr(docsrs, doc(cfg(feature = "preserve_order")))] + #[inline] + pub fn shift_remove(&mut self, key: &Q) -> Option + where + String: Borrow, + Q: ?Sized + Ord + Eq + Hash, + { + self.map.shift_remove(key) + } + + /// Remove and return the key-value pair. + /// + /// Like [`Vec::remove`], the entry is removed by shifting all of the + /// elements that follow it, preserving their relative order. This perturbs + /// the index of all of those elements! + #[cfg(feature = "preserve_order")] + #[cfg_attr(docsrs, doc(cfg(feature = "preserve_order")))] + #[inline] + pub fn shift_remove_entry(&mut self, key: &Q) -> Option<(String, Value)> + where + String: Borrow, + Q: ?Sized + Ord + Eq + Hash, + { + self.map.shift_remove_entry(key) } /// Moves all elements from other into self, leaving other empty. From 09d865b34b9701be52764dc9bf571b1a16e9d3dc Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sun, 28 Jan 2024 19:44:38 -0800 Subject: [PATCH 08/30] Release 1.0.113 --- Cargo.toml | 2 +- src/lib.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2e21afb3a..cedde61e4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "serde_json" -version = "1.0.112" +version = "1.0.113" authors = ["Erick Tryzelaar ", "David Tolnay "] categories = ["encoding", "parser-implementations", "no-std"] description = "A JSON serialization file format" diff --git a/src/lib.rs b/src/lib.rs index 9526fc1bb..aa3fcfc8d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -299,7 +299,7 @@ //! [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.112")] +#![doc(html_root_url = "https://docs.rs/serde_json/1.0.113")] // Ignored clippy lints #![allow( clippy::collapsible_else_if, From ca05f69943e18d70c2219ea41fcb67f2849b7eed Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Wed, 7 Feb 2024 21:15:13 -0800 Subject: [PATCH 09/30] Remove unused Float::is_sign_negative trait method warning: method `is_sign_negative` is never used --> src/lexical/num.rs:251:8 | 175 | pub trait Float: Number { | ----- method in this trait ... 251 | fn is_sign_negative(self) -> bool; | ^^^^^^^^^^^^^^^^ | = note: `#[warn(dead_code)]` on by default --- src/lexical/num.rs | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/lexical/num.rs b/src/lexical/num.rs index af10afd7a..75eee01b8 100644 --- a/src/lexical/num.rs +++ b/src/lexical/num.rs @@ -248,7 +248,6 @@ pub trait Float: Number { fn from_bits(u: Self::Unsigned) -> Self; fn to_bits(self) -> Self::Unsigned; fn is_sign_positive(self) -> bool; - fn is_sign_negative(self) -> bool; /// Returns true if the float is a denormal. #[inline] @@ -368,11 +367,6 @@ impl Float for f32 { fn is_sign_positive(self) -> bool { f32::is_sign_positive(self) } - - #[inline] - fn is_sign_negative(self) -> bool { - f32::is_sign_negative(self) - } } impl Float for f64 { @@ -432,9 +426,4 @@ impl Float for f64 { fn is_sign_positive(self) -> bool { f64::is_sign_positive(self) } - - #[inline] - fn is_sign_negative(self) -> bool { - f64::is_sign_negative(self) - } } From 34a04c5f7febdf80e05743e38d5cb1880a83b6f6 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Fri, 9 Feb 2024 18:58:46 -0800 Subject: [PATCH 10/30] Ignore incompatible_msrv clippy false positives in test https://github.com/rust-lang/rust-clippy/issues/12257 warning: current MSRV (Minimum Supported Rust Version) is `1.56.0` but this item is stable since `1.71.0` --> tests/test.rs:2500:25 | 2500 | assert_ne!(rand.hash_one(k1), rand.hash_one(k2)); | ^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#incompatible_msrv = note: `-W clippy::incompatible-msrv` implied by `-W clippy::all` = help: to override `-W clippy::all` add `#[allow(clippy::incompatible_msrv)]` warning: current MSRV (Minimum Supported Rust Version) is `1.56.0` but this item is stable since `1.71.0` --> tests/test.rs:2500:44 | 2500 | assert_ne!(rand.hash_one(k1), rand.hash_one(k2)); | ^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#incompatible_msrv warning: current MSRV (Minimum Supported Rust Version) is `1.56.0` but this item is stable since `1.71.0` --> tests/test.rs:2503:25 | 2503 | assert_eq!(rand.hash_one(k1), rand.hash_one(k2)); | ^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#incompatible_msrv warning: current MSRV (Minimum Supported Rust Version) is `1.56.0` but this item is stable since `1.71.0` --> tests/test.rs:2503:44 | 2503 | assert_eq!(rand.hash_one(k1), rand.hash_one(k2)); | ^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#incompatible_msrv --- tests/test.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test.rs b/tests/test.rs index 05b7f86fc..9a8e7ca73 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -5,6 +5,7 @@ clippy::derive_partial_eq_without_eq, clippy::excessive_precision, clippy::float_cmp, + clippy::incompatible_msrv, // https://github.com/rust-lang/rust-clippy/issues/12257 clippy::items_after_statements, clippy::let_underscore_untyped, clippy::shadow_unrelated, From 6fb70262e894168ac631b2232a1b7b3a7781ebe5 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Mon, 19 Feb 2024 15:44:01 -0800 Subject: [PATCH 11/30] Work around prelude redundant import warnings https://github.com/rust-lang/rust/pull/117772 warning: the item `String` is imported redundantly --> src/de.rs:8:5 | 8 | use alloc::string::String; | ^^^^^^^^^^^^^^^^^^^^^ | ::: nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/prelude/mod.rs:125:13 | 125 | pub use super::v1::*; | --------- the item `String` is already defined here | = note: `#[warn(unused_imports)]` on by default warning: the item `Vec` is imported redundantly --> src/de.rs:9:5 | 9 | use alloc::vec::Vec; | ^^^^^^^^^^^^^^^ | ::: nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/prelude/mod.rs:125:13 | 125 | pub use super::v1::*; | --------- the item `Vec` is already defined here warning: the item `Box` is imported redundantly --> src/error.rs:4:5 | 4 | use alloc::boxed::Box; | ^^^^^^^^^^^^^^^^^ | ::: nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/prelude/mod.rs:125:13 | 125 | pub use super::v1::*; | --------- the item `Box` is already defined here warning: the item `String` is imported redundantly --> src/error.rs:5:21 | 5 | use alloc::string::{String, ToString}; | ^^^^^^ | ::: nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/prelude/mod.rs:125:13 | 125 | pub use super::v1::*; | --------- the item `String` is already defined here warning: the item `ToString` is imported redundantly --> src/error.rs:5:29 | 5 | use alloc::string::{String, ToString}; | ^^^^^^^^ | ::: nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/prelude/mod.rs:125:13 | 125 | pub use super::v1::*; | --------- the item `ToString` is already defined here warning: the item `String` is imported redundantly --> src/map.rs:10:5 | 10 | use alloc::string::String; | ^^^^^^^^^^^^^^^^^^^^^ | ::: nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/prelude/mod.rs:125:13 | 125 | pub use super::v1::*; | --------- the item `String` is already defined here warning: the item `indexmap` is imported redundantly --> src/map.rs:23:16 | 23 | use indexmap::{self, IndexMap}; | ^^^^ the item `indexmap` is already defined here | = note: `#[warn(unused_imports)]` on by default warning: the item `String` is imported redundantly --> src/ser.rs:5:21 | 5 | use alloc::string::{String, ToString}; | ^^^^^^ | ::: nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/prelude/mod.rs:125:13 | 125 | pub use super::v1::*; | --------- the item `String` is already defined here warning: the item `ToString` is imported redundantly --> src/ser.rs:5:29 | 5 | use alloc::string::{String, ToString}; | ^^^^^^^^ | ::: nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/prelude/mod.rs:125:13 | 125 | pub use super::v1::*; | --------- the item `ToString` is already defined here warning: the item `Vec` is imported redundantly --> src/ser.rs:6:5 | 6 | use alloc::vec::Vec; | ^^^^^^^^^^^^^^^ | ::: nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/prelude/mod.rs:125:13 | 125 | pub use super::v1::*; | --------- the item `Vec` is already defined here warning: the item `String` is imported redundantly --> src/value/mod.rs:95:5 | 95 | use alloc::string::String; | ^^^^^^^^^^^^^^^^^^^^^ | ::: nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/prelude/mod.rs:125:13 | 125 | pub use super::v1::*; | --------- the item `String` is already defined here warning: the item `Vec` is imported redundantly --> src/value/mod.rs:96:5 | 96 | use alloc::vec::Vec; | ^^^^^^^^^^^^^^^ | ::: nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/prelude/mod.rs:125:13 | 125 | pub use super::v1::*; | --------- the item `Vec` is already defined here warning: the item `ToOwned` is imported redundantly --> src/value/de.rs:5:26 | 5 | use alloc::borrow::{Cow, ToOwned}; | ^^^^^^^ | ::: nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/prelude/mod.rs:125:13 | 125 | pub use super::v1::*; | --------- the item `ToOwned` is already defined here warning: the item `String` is imported redundantly --> src/value/de.rs:6:5 | 6 | use alloc::string::String; | ^^^^^^^^^^^^^^^^^^^^^ | ::: nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/prelude/mod.rs:125:13 | 125 | pub use super::v1::*; | --------- the item `String` is already defined here warning: the item `Vec` is imported redundantly --> src/value/de.rs:9:24 | 9 | use alloc::vec::{self, Vec}; | ^^^ | ::: nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/prelude/mod.rs:125:13 | 125 | pub use super::v1::*; | --------- the item `Vec` is already defined here warning: the item `String` is imported redundantly --> src/value/from.rs:5:21 | 5 | use alloc::string::{String, ToString}; | ^^^^^^ | ::: nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/prelude/mod.rs:125:13 | 125 | pub use super::v1::*; | --------- the item `String` is already defined here warning: the item `ToString` is imported redundantly --> src/value/from.rs:5:29 | 5 | use alloc::string::{String, ToString}; | ^^^^^^^^ | ::: nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/prelude/mod.rs:125:13 | 125 | pub use super::v1::*; | --------- the item `ToString` is already defined here warning: the item `Vec` is imported redundantly --> src/value/from.rs:6:5 | 6 | use alloc::vec::Vec; | ^^^^^^^^^^^^^^^ | ::: nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/prelude/mod.rs:125:13 | 125 | pub use super::v1::*; | --------- the item `Vec` is already defined here warning: the item `ToOwned` is imported redundantly --> src/value/index.rs:3:5 | 3 | use alloc::borrow::ToOwned; | ^^^^^^^^^^^^^^^^^^^^^^ | ::: nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/prelude/mod.rs:125:13 | 125 | pub use super::v1::*; | --------- the item `ToOwned` is already defined here warning: the item `String` is imported redundantly --> src/value/index.rs:4:5 | 4 | use alloc::string::String; | ^^^^^^^^^^^^^^^^^^^^^ | ::: nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/prelude/mod.rs:125:13 | 125 | pub use super::v1::*; | --------- the item `String` is already defined here warning: the item `String` is imported redundantly --> src/value/partial_eq.rs:2:5 | 2 | use alloc::string::String; | ^^^^^^^^^^^^^^^^^^^^^ | ::: nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/prelude/mod.rs:125:13 | 125 | pub use super::v1::*; | --------- the item `String` is already defined here warning: the item `ToOwned` is imported redundantly --> src/value/ser.rs:4:5 | 4 | use alloc::borrow::ToOwned; | ^^^^^^^^^^^^^^^^^^^^^^ | ::: nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/prelude/mod.rs:125:13 | 125 | pub use super::v1::*; | --------- the item `ToOwned` is already defined here warning: the item `String` is imported redundantly --> src/value/ser.rs:5:21 | 5 | use alloc::string::{String, ToString}; | ^^^^^^ | ::: nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/prelude/mod.rs:125:13 | 125 | pub use super::v1::*; | --------- the item `String` is already defined here warning: the item `ToString` is imported redundantly --> src/value/ser.rs:5:29 | 5 | use alloc::string::{String, ToString}; | ^^^^^^^^ | ::: nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/prelude/mod.rs:125:13 | 125 | pub use super::v1::*; | --------- the item `ToString` is already defined here warning: the item `Vec` is imported redundantly --> src/value/ser.rs:6:5 | 6 | use alloc::vec::Vec; | ^^^^^^^^^^^^^^^ | ::: nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/prelude/mod.rs:125:13 | 125 | pub use super::v1::*; | --------- the item `Vec` is already defined here warning: the item `Vec` is imported redundantly --> src/read.rs:2:5 | 2 | use alloc::vec::Vec; | ^^^^^^^^^^^^^^^ | ::: nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/prelude/mod.rs:125:13 | 125 | pub use super::v1::*; | --------- the item `Vec` is already defined here warning: the item `ToString` is imported redundantly --> tests/test.rs:46:5 | 46 | use std::string::ToString; | ^^^^^^^^^^^^^^^^^^^^^ | ::: nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/prelude/mod.rs:125:13 | 125 | pub use super::v1::*; | --------- the item `ToString` is already defined here | = note: `#[warn(unused_imports)]` on by default warning: the item `Vec` is imported redundantly --> tests/../src/lexical/bignum.rs:6:5 | 6 | use alloc::vec::Vec; | ^^^^^^^^^^^^^^^ | ::: nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/prelude/mod.rs:125:13 | 125 | pub use super::v1::*; | --------- the item `Vec` is already defined here | = note: `#[warn(unused_imports)]` on by default --- src/lexical/bignum.rs | 1 + src/lib.rs | 5 ++++- src/map.rs | 10 +++++++++- src/read.rs | 2 ++ tests/test.rs | 1 - 5 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/lexical/bignum.rs b/src/lexical/bignum.rs index f9551f534..4fa7eed6d 100644 --- a/src/lexical/bignum.rs +++ b/src/lexical/bignum.rs @@ -3,6 +3,7 @@ //! Big integer type definition. use super::math::*; +#[allow(unused_imports)] use alloc::vec::Vec; /// Storage for a big integer type. diff --git a/src/lib.rs b/src/lib.rs index aa3fcfc8d..876ff199d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -360,11 +360,14 @@ #![deny(clippy::question_mark_used)] #![allow(non_upper_case_globals)] #![deny(missing_docs)] -#![cfg_attr(not(feature = "std"), no_std)] +#![no_std] #![cfg_attr(docsrs, feature(doc_cfg))] extern crate alloc; +#[cfg(feature = "std")] +extern crate std; + #[cfg(feature = "std")] #[cfg_attr(docsrs, doc(cfg(feature = "std")))] #[doc(inline)] diff --git a/src/map.rs b/src/map.rs index 1d74e1b2b..520cd6cf5 100644 --- a/src/map.rs +++ b/src/map.rs @@ -20,7 +20,7 @@ use serde::de; #[cfg(not(feature = "preserve_order"))] use alloc::collections::{btree_map, BTreeMap}; #[cfg(feature = "preserve_order")] -use indexmap::{self, IndexMap}; +use indexmap::IndexMap; /// Represents a JSON key/value type. pub struct Map { @@ -176,6 +176,8 @@ impl Map { /// Like [`Vec::swap_remove`], the entry is removed by swapping it with the /// last element of the map and popping it off. This perturbs the position /// of what used to be the last element! + /// + /// [`Vec::swap_remove`]: std::vec::Vec::swap_remove #[cfg(feature = "preserve_order")] #[cfg_attr(docsrs, doc(cfg(feature = "preserve_order")))] #[inline] @@ -192,6 +194,8 @@ impl Map { /// Like [`Vec::swap_remove`], the entry is removed by swapping it with the /// last element of the map and popping it off. This perturbs the position /// of what used to be the last element! + /// + /// [`Vec::swap_remove`]: std::vec::Vec::swap_remove #[cfg(feature = "preserve_order")] #[cfg_attr(docsrs, doc(cfg(feature = "preserve_order")))] #[inline] @@ -208,6 +212,8 @@ impl Map { /// Like [`Vec::remove`], the entry is removed by shifting all of the /// elements that follow it, preserving their relative order. This perturbs /// the index of all of those elements! + /// + /// [`Vec::remove`]: std::vec::Vec::remove #[cfg(feature = "preserve_order")] #[cfg_attr(docsrs, doc(cfg(feature = "preserve_order")))] #[inline] @@ -224,6 +230,8 @@ impl Map { /// Like [`Vec::remove`], the entry is removed by shifting all of the /// elements that follow it, preserving their relative order. This perturbs /// the index of all of those elements! + /// + /// [`Vec::remove`]: std::vec::Vec::remove #[cfg(feature = "preserve_order")] #[cfg_attr(docsrs, doc(cfg(feature = "preserve_order")))] #[inline] diff --git a/src/read.rs b/src/read.rs index 7446f28b9..06ac907e2 100644 --- a/src/read.rs +++ b/src/read.rs @@ -14,6 +14,8 @@ use crate::iter::LineColIterator; use crate::raw::BorrowedRawDeserializer; #[cfg(all(feature = "raw_value", feature = "std"))] use crate::raw::OwnedRawDeserializer; +#[cfg(all(feature = "raw_value", feature = "std"))] +use alloc::string::String; #[cfg(feature = "raw_value")] use serde::de::Visitor; diff --git a/tests/test.rs b/tests/test.rs index 9a8e7ca73..543dbd0b1 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -43,7 +43,6 @@ use std::iter; use std::marker::PhantomData; use std::mem; use std::str::FromStr; -use std::string::ToString; use std::{f32, f64}; use std::{i16, i32, i64, i8}; use std::{u16, u32, u64, u8}; From e1b3a6d8a161ff5ec4865b487d148c17d0188e3e Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Mon, 19 Feb 2024 16:12:45 -0800 Subject: [PATCH 12/30] Release 1.0.114 --- Cargo.toml | 2 +- src/lib.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index cedde61e4..630f44846 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "serde_json" -version = "1.0.113" +version = "1.0.114" authors = ["Erick Tryzelaar ", "David Tolnay "] categories = ["encoding", "parser-implementations", "no-std"] description = "A JSON serialization file format" diff --git a/src/lib.rs b/src/lib.rs index 876ff199d..f10bedb1c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -299,7 +299,7 @@ //! [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.113")] +#![doc(html_root_url = "https://docs.rs/serde_json/1.0.114")] // Ignored clippy lints #![allow( clippy::collapsible_else_if, From fedf8341eedd6fc0ad5c5336d1747463c7d85ece Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sun, 25 Feb 2024 19:50:16 -0800 Subject: [PATCH 13/30] Ignore non_local_definitions false positive in test https://github.com/rust-lang/rust/issues/121621 warning: non-local `impl` definition, they should be avoided as they go against expectation --> tests/test.rs:2338:5 | 2338 | / impl<'de> Deserialize<'de> for &'de RawMapKey { 2339 | | fn deserialize(deserializer: D) -> Result 2340 | | where 2341 | | D: serde::Deserializer<'de>, ... | 2345 | | } 2346 | | } | |_____^ | = help: move this `impl` block outside the of the current function `test_raw_value_in_map_key` = note: an `impl` definition is non-local if it is nested inside an item and neither the type nor the trait are at the same nesting level as the `impl` block = note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue = note: `#[warn(non_local_definitions)]` on by default --- tests/test.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/test.rs b/tests/test.rs index 543dbd0b1..c227b9066 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -2335,6 +2335,8 @@ fn test_raw_value_in_map_key() { #[repr(transparent)] struct RawMapKey(RawValue); + #[allow(unknown_lints)] + #[allow(non_local_definitions)] // false positive: https://github.com/rust-lang/rust/issues/121621 impl<'de> Deserialize<'de> for &'de RawMapKey { fn deserialize(deserializer: D) -> Result where From a25f6c6f2af1ac268175e79ad8d537106dbb3a3a Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Fri, 22 Mar 2024 15:01:47 -0700 Subject: [PATCH 14/30] Remove conditional on repr(transparent) --- src/raw.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/raw.rs b/src/raw.rs index a2bf0ecbb..22d14441e 100644 --- a/src/raw.rs +++ b/src/raw.rs @@ -112,8 +112,8 @@ use serde::ser::{Serialize, SerializeStruct, Serializer}; /// raw_value: Box, /// } /// ``` -#[cfg_attr(not(doc), repr(transparent))] #[cfg_attr(docsrs, doc(cfg(feature = "raw_value")))] +#[repr(transparent)] pub struct RawValue { json: str, } From d2dbbf7055666b42957dee59b6a4ea57413517ff Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sat, 23 Mar 2024 20:19:13 -0700 Subject: [PATCH 15/30] Ignore dead code lint in tests New in nightly-2024-03-24 from https://github.com/rust-lang/rust/pull/119552. warning: field `x` is never read --> tests/regression/issue795.rs:11:15 | 11 | Variant { x: u8 }, | ------- ^ | | | field in this variant | = note: `#[warn(dead_code)]` on by default warning: field `i` is never read --> tests/regression/issue845.rs:63:9 | 61 | pub struct Struct { | ------ field in this struct 62 | #[serde(deserialize_with = "deserialize_integer_or_string")] 63 | pub i: i64, | ^ | = note: `Struct` has a derived impl for the trait `Debug`, but this is intentionally ignored during dead code analysis --- tests/regression/issue795.rs | 5 ++++- tests/regression/issue845.rs | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/regression/issue795.rs b/tests/regression/issue795.rs index bb82852c5..411e8af5d 100644 --- a/tests/regression/issue795.rs +++ b/tests/regression/issue795.rs @@ -8,7 +8,10 @@ use std::fmt; #[derive(Debug)] pub enum Enum { - Variant { x: u8 }, + Variant { + #[allow(dead_code)] + x: u8, + }, } impl<'de> Deserialize<'de> for Enum { diff --git a/tests/regression/issue845.rs b/tests/regression/issue845.rs index e8b0c0fd0..7b6564dad 100644 --- a/tests/regression/issue845.rs +++ b/tests/regression/issue845.rs @@ -60,6 +60,7 @@ where #[derive(Deserialize, Debug)] pub struct Struct { #[serde(deserialize_with = "deserialize_integer_or_string")] + #[allow(dead_code)] pub i: i64, } From 4a0be88b5ac6cda971a52df9f027b551fe566347 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sat, 23 Mar 2024 20:24:22 -0700 Subject: [PATCH 16/30] Format regression tests with rustfmt --- tests/regression/issue520.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/regression/issue520.rs b/tests/regression/issue520.rs index 9ed367731..730ecc60a 100644 --- a/tests/regression/issue520.rs +++ b/tests/regression/issue520.rs @@ -1,6 +1,6 @@ #![allow(clippy::float_cmp)] -use serde_derive::{Serialize, Deserialize}; +use serde_derive::{Deserialize, Serialize}; #[derive(Serialize, Deserialize, Debug)] #[serde(tag = "type", content = "data")] From 3a3f61b1c9a2dce973179fad1650f709f63bdaa5 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sun, 24 Mar 2024 19:53:11 -0700 Subject: [PATCH 17/30] Temporarily disable miri on doctests --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d9979825e..e4accd879 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -89,8 +89,8 @@ jobs: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@miri - run: cargo miri setup - - run: cargo miri test - - run: cargo miri test --features preserve_order,float_roundtrip,arbitrary_precision,raw_value + - run: cargo miri test --all-targets # exclude doctests https://github.com/rust-lang/miri/issues/3404 + - run: cargo miri test --features preserve_order,float_roundtrip,arbitrary_precision,raw_value --all-targets clippy: name: Clippy From 840da8e89241d46482c40038d3acdb6745ed4f05 Mon Sep 17 00:00:00 2001 From: Jon Heinritz Date: Mon, 25 Mar 2024 09:06:15 +0100 Subject: [PATCH 18/30] Fix missing backticks in doc comments This was leading to rustdocs markdown parser to interpret slices like &[u8] as & and a link to u8 --- README.md | 2 +- src/lexical/large_powers32.rs | 2 +- src/lexical/large_powers64.rs | 2 +- src/lib.rs | 2 +- src/read.rs | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index a3ba288f1..be70b7b06 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,7 @@ enum Value { A string of JSON data can be parsed into a `serde_json::Value` by the [`serde_json::from_str`][from_str] function. There is also -[`from_slice`][from_slice] for parsing from a byte slice &\[u8\] and +[`from_slice`][from_slice] for parsing from a byte slice `&[u8]` and [`from_reader`][from_reader] for parsing from any `io::Read` like a File or a TCP stream. diff --git a/src/lexical/large_powers32.rs b/src/lexical/large_powers32.rs index 799119726..eb8582f5f 100644 --- a/src/lexical/large_powers32.rs +++ b/src/lexical/large_powers32.rs @@ -2,7 +2,7 @@ //! Precalculated large powers for 32-bit limbs. -/// Large powers (&[u32]) for base5 operations. +/// Large powers (`&[u32]`) for base5 operations. const POW5_1: [u32; 1] = [5]; const POW5_2: [u32; 1] = [25]; const POW5_3: [u32; 1] = [625]; diff --git a/src/lexical/large_powers64.rs b/src/lexical/large_powers64.rs index ee3656108..96554eac1 100644 --- a/src/lexical/large_powers64.rs +++ b/src/lexical/large_powers64.rs @@ -2,7 +2,7 @@ //! Precalculated large powers for 64-bit limbs. -/// Large powers (&[u64]) for base5 operations. +/// Large powers (`&[u64]`) for base5 operations. const POW5_1: [u64; 1] = [5]; const POW5_2: [u64; 1] = [25]; const POW5_3: [u64; 1] = [625]; diff --git a/src/lib.rs b/src/lib.rs index f10bedb1c..da0da469f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -56,7 +56,7 @@ //! //! A string of JSON data can be parsed into a `serde_json::Value` by the //! [`serde_json::from_str`][from_str] function. There is also [`from_slice`] -//! for parsing from a byte slice &\[u8\] and [`from_reader`] for parsing from +//! for parsing from a byte slice `&[u8]` and [`from_reader`] for parsing from //! any `io::Read` like a File or a TCP stream. //! //! ``` diff --git a/src/read.rs b/src/read.rs index 06ac907e2..a426911c7 100644 --- a/src/read.rs +++ b/src/read.rs @@ -20,7 +20,7 @@ use alloc::string::String; use serde::de::Visitor; /// Trait used by the deserializer for iterating over input. This is manually -/// "specialized" for iterating over &[u8]. Once feature(specialization) is +/// "specialized" for iterating over `&[u8]`. Once feature(specialization) is /// stable we can use actual specialization. /// /// This trait is sealed and cannot be implemented for types outside of From 218770bb7531b0e491a2883eafc40ade5b1eeaf5 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Mon, 25 Mar 2024 22:24:55 -0700 Subject: [PATCH 19/30] Explicitly install a Rust toolchain for cargo-outdated job Debugging a recent cargo-outdated bug, it would have been nice not to wonder whether a rustc version change in GitHub's runner image was a contributing factor. --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e4accd879..75cc7bfe6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -132,6 +132,7 @@ jobs: timeout-minutes: 45 steps: - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable - uses: dtolnay/install@cargo-outdated - run: cargo outdated --exit-code 1 - run: cargo outdated --manifest-path fuzz/Cargo.toml --exit-code 1 From b1ebf3888ed728c66c69581ba8d9c4aa7483f486 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Mon, 25 Mar 2024 23:03:48 -0700 Subject: [PATCH 20/30] Release 1.0.115 --- Cargo.toml | 2 +- src/lib.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 630f44846..38b6d6ec8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "serde_json" -version = "1.0.114" +version = "1.0.115" authors = ["Erick Tryzelaar ", "David Tolnay "] categories = ["encoding", "parser-implementations", "no-std"] description = "A JSON serialization file format" diff --git a/src/lib.rs b/src/lib.rs index da0da469f..32c4fc456 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -299,7 +299,7 @@ //! [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.114")] +#![doc(html_root_url = "https://docs.rs/serde_json/1.0.115")] // Ignored clippy lints #![allow( clippy::collapsible_else_if, From 0baba2877595e31d57adafd5db2f94074f4a4c2e Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Fri, 5 Apr 2024 19:05:51 -0700 Subject: [PATCH 21/30] Resolve legacy_numeric_constants clippy lints warning: usage of a legacy numeric method --> src/de.rs:484:73 | 484 | ... if overflow!(significand * 10 + digit, u64::max_value()) { | ^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants = note: `#[warn(clippy::legacy_numeric_constants)]` on by default help: use the associated constant instead | 484 | if overflow!(significand * 10 + digit, u64::MAX) { | ~~~ warning: usage of a legacy numeric method --> src/de.rs:536:57 | 536 | if overflow!(significand * 10 + digit, u64::max_value()) { | ^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants help: use the associated constant instead | 536 | if overflow!(significand * 10 + digit, u64::MAX) { | ~~~ warning: usage of a legacy numeric method --> src/de.rs:600:49 | 600 | if overflow!(exp * 10 + digit, i32::max_value()) { | ^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants help: use the associated constant instead | 600 | if overflow!(exp * 10 + digit, i32::MAX) { | ~~~ warning: usage of a legacy numeric method --> src/number.rs:100:39 | 100 | N::PosInt(v) => v <= i64::max_value() as u64, | ^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants help: use the associated constant instead | 100 | N::PosInt(v) => v <= i64::MAX as u64, | ~~~ warning: usage of a legacy numeric method --> src/number.rs:192:30 | 192 | if n <= i64::max_value() as u64 { | ^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants help: use the associated constant instead | 192 | if n <= i64::MAX as u64 { | ~~~ warning: usage of a legacy numeric method --> tests/../src/lexical/exponent.rs:11:21 | 11 | if value > i32::max_value() as usize { | ^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants = note: `#[warn(clippy::legacy_numeric_constants)]` on by default help: use the associated constant instead | 11 | if value > i32::MAX as usize { | ~~~ warning: usage of a legacy numeric method --> tests/../src/lexical/exponent.rs:12:14 | 12 | i32::max_value() | ^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants help: use the associated constant instead | 12 | i32::MAX | ~~~ warning: usage of a legacy numeric method --> tests/../src/lexical/rounding.rs:28:14 | 28 | u64::max_value() | ^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants help: use the associated constant instead | 28 | u64::MAX | ~~~ warning: usage of a legacy numeric method --> tests/lexical/exponent.rs:21:34 | 21 | scientific_exponent(i32::min_value(), 0, 0), | ^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants help: use the associated constant instead | 21 | scientific_exponent(i32::MIN, 0, 0), | ~~~ warning: usage of a legacy numeric method --> tests/lexical/exponent.rs:22:14 | 22 | i32::min_value() | ^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants help: use the associated constant instead | 22 | i32::MIN | ~~~ warning: usage of a legacy numeric method --> tests/lexical/exponent.rs:25:34 | 25 | scientific_exponent(i32::min_value(), 0, 5), | ^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants help: use the associated constant instead | 25 | scientific_exponent(i32::MIN, 0, 5), | ~~~ warning: usage of a legacy numeric method --> tests/lexical/exponent.rs:26:14 | 26 | i32::min_value() | ^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants help: use the associated constant instead | 26 | i32::MIN | ~~~ warning: usage of a legacy numeric method --> tests/lexical/exponent.rs:31:34 | 31 | scientific_exponent(i32::max_value(), 0, 0), | ^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants help: use the associated constant instead | 31 | scientific_exponent(i32::MAX, 0, 0), | ~~~ warning: usage of a legacy numeric method --> tests/lexical/exponent.rs:32:14 | 32 | i32::max_value() - 1 | ^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants help: use the associated constant instead | 32 | i32::MAX - 1 | ~~~ warning: usage of a legacy numeric method --> tests/lexical/exponent.rs:35:34 | 35 | scientific_exponent(i32::max_value(), 5, 0), | ^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants help: use the associated constant instead | 35 | scientific_exponent(i32::MAX, 5, 0), | ~~~ warning: usage of a legacy numeric method --> tests/lexical/exponent.rs:36:14 | 36 | i32::max_value() | ^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants help: use the associated constant instead | 36 | i32::MAX | ~~~ warning: usage of a legacy numeric method --> tests/lexical/exponent.rs:45:32 | 45 | mantissa_exponent(i32::max_value(), 5, 0), | ^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants help: use the associated constant instead | 45 | mantissa_exponent(i32::MAX, 5, 0), | ~~~ warning: usage of a legacy numeric method --> tests/lexical/exponent.rs:46:14 | 46 | i32::max_value() - 5 | ^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants help: use the associated constant instead | 46 | i32::MAX - 5 | ~~~ warning: usage of a legacy numeric method --> tests/lexical/exponent.rs:48:39 | 48 | assert_eq!(mantissa_exponent(i32::max_value(), 0, 5), i32::max_value()); | ^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants help: use the associated constant instead | 48 | assert_eq!(mantissa_exponent(i32::MAX, 0, 5), i32::max_value()); | ~~~ warning: usage of a legacy numeric method --> tests/lexical/exponent.rs:48:64 | 48 | assert_eq!(mantissa_exponent(i32::max_value(), 0, 5), i32::max_value()); | ^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants help: use the associated constant instead | 48 | assert_eq!(mantissa_exponent(i32::max_value(), 0, 5), i32::MAX); | ~~~ warning: usage of a legacy numeric method --> tests/lexical/exponent.rs:49:39 | 49 | assert_eq!(mantissa_exponent(i32::min_value(), 5, 0), i32::min_value()); | ^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants help: use the associated constant instead | 49 | assert_eq!(mantissa_exponent(i32::MIN, 5, 0), i32::min_value()); | ~~~ warning: usage of a legacy numeric method --> tests/lexical/exponent.rs:49:64 | 49 | assert_eq!(mantissa_exponent(i32::min_value(), 5, 0), i32::min_value()); | ^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants help: use the associated constant instead | 49 | assert_eq!(mantissa_exponent(i32::min_value(), 5, 0), i32::MIN); | ~~~ warning: usage of a legacy numeric method --> tests/lexical/exponent.rs:51:32 | 51 | mantissa_exponent(i32::min_value(), 0, 5), | ^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants help: use the associated constant instead | 51 | mantissa_exponent(i32::MIN, 0, 5), | ~~~ warning: usage of a legacy numeric method --> tests/lexical/exponent.rs:52:14 | 52 | i32::min_value() + 5 | ^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants help: use the associated constant instead | 52 | i32::MIN + 5 | ~~~ warning: importing legacy numeric constants --> tests/test.rs:47:11 | 47 | use std::{i16, i32, i64, i8}; | ^^^ | = help: remove this import = note: then `i16::` will resolve to the respective associated constant = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants = note: `#[warn(clippy::legacy_numeric_constants)]` on by default warning: importing legacy numeric constants --> tests/test.rs:47:16 | 47 | use std::{i16, i32, i64, i8}; | ^^^ | = help: remove this import = note: then `i32::` will resolve to the respective associated constant = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants warning: importing legacy numeric constants --> tests/test.rs:47:21 | 47 | use std::{i16, i32, i64, i8}; | ^^^ | = help: remove this import = note: then `i64::` will resolve to the respective associated constant = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants warning: importing legacy numeric constants --> tests/test.rs:47:26 | 47 | use std::{i16, i32, i64, i8}; | ^^ | = help: remove this import = note: then `i8::` will resolve to the respective associated constant = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants warning: importing legacy numeric constants --> tests/test.rs:48:11 | 48 | use std::{u16, u32, u64, u8}; | ^^^ | = help: remove this import = note: then `u16::` will resolve to the respective associated constant = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants warning: importing legacy numeric constants --> tests/test.rs:48:16 | 48 | use std::{u16, u32, u64, u8}; | ^^^ | = help: remove this import = note: then `u32::` will resolve to the respective associated constant = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants warning: importing legacy numeric constants --> tests/test.rs:48:21 | 48 | use std::{u16, u32, u64, u8}; | ^^^ | = help: remove this import = note: then `u64::` will resolve to the respective associated constant = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants warning: importing legacy numeric constants --> tests/test.rs:48:26 | 48 | use std::{u16, u32, u64, u8}; | ^^ | = help: remove this import = note: then `u8::` will resolve to the respective associated constant = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants warning: usage of a legacy numeric constant --> tests/test.rs:161:22 | 161 | let v = to_value(::std::f64::NAN.copysign(1.0)).unwrap(); | ^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants help: use the associated constant instead | 161 | let v = to_value(f64::NAN.copysign(1.0)).unwrap(); | ~~~~~~~~ warning: usage of a legacy numeric constant --> tests/test.rs:164:22 | 164 | let v = to_value(::std::f64::NAN.copysign(-1.0)).unwrap(); | ^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants help: use the associated constant instead | 164 | let v = to_value(f64::NAN.copysign(-1.0)).unwrap(); | ~~~~~~~~ warning: usage of a legacy numeric constant --> tests/test.rs:167:22 | 167 | let v = to_value(::std::f64::INFINITY).unwrap(); | ^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants help: use the associated constant instead | 167 | let v = to_value(f64::INFINITY).unwrap(); | ~~~~~~~~~~~~~ warning: usage of a legacy numeric constant --> tests/test.rs:170:23 | 170 | let v = to_value(-::std::f64::INFINITY).unwrap(); | ^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants help: use the associated constant instead | 170 | let v = to_value(-f64::INFINITY).unwrap(); | ~~~~~~~~~~~~~ warning: usage of a legacy numeric constant --> tests/test.rs:173:22 | 173 | let v = to_value(::std::f32::NAN.copysign(1.0)).unwrap(); | ^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants help: use the associated constant instead | 173 | let v = to_value(f32::NAN.copysign(1.0)).unwrap(); | ~~~~~~~~ warning: usage of a legacy numeric constant --> tests/test.rs:176:22 | 176 | let v = to_value(::std::f32::NAN.copysign(-1.0)).unwrap(); | ^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants help: use the associated constant instead | 176 | let v = to_value(f32::NAN.copysign(-1.0)).unwrap(); | ~~~~~~~~ warning: usage of a legacy numeric constant --> tests/test.rs:179:22 | 179 | let v = to_value(::std::f32::INFINITY).unwrap(); | ^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants help: use the associated constant instead | 179 | let v = to_value(f32::INFINITY).unwrap(); | ~~~~~~~~~~~~~ warning: usage of a legacy numeric constant --> tests/test.rs:182:23 | 182 | let v = to_value(-::std::f32::INFINITY).unwrap(); | ^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants help: use the associated constant instead | 182 | let v = to_value(-f32::INFINITY).unwrap(); | ~~~~~~~~~~~~~ warning: usage of a legacy numeric method --> tests/test.rs:2243:26 | 2243 | let signed = &[i128::min_value(), -1, 0, 1, i128::max_value()]; | ^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants help: use the associated constant instead | 2243 | let signed = &[i128::MIN, -1, 0, 1, i128::max_value()]; | ~~~ warning: usage of a legacy numeric method --> tests/test.rs:2243:55 | 2243 | let signed = &[i128::min_value(), -1, 0, 1, i128::max_value()]; | ^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants help: use the associated constant instead | 2243 | let signed = &[i128::min_value(), -1, 0, 1, i128::MAX]; | ~~~ warning: usage of a legacy numeric method --> tests/test.rs:2244:34 | 2244 | let unsigned = &[0, 1, u128::max_value()]; | ^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants help: use the associated constant instead | 2244 | let unsigned = &[0, 1, u128::MAX]; | ~~~ warning: usage of a legacy numeric method --> tests/test.rs:2280:36 | 2280 | let signed = &[i128::from(i64::min_value()), i128::from(u64::max_value())]; | ^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants help: use the associated constant instead | 2280 | let signed = &[i128::from(i64::MIN), i128::from(u64::max_value())]; | ~~~ warning: usage of a legacy numeric method --> tests/test.rs:2280:66 | 2280 | let signed = &[i128::from(i64::min_value()), i128::from(u64::max_value())]; | ^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants help: use the associated constant instead | 2280 | let signed = &[i128::from(i64::min_value()), i128::from(u64::MAX)]; | ~~~ warning: usage of a legacy numeric method --> tests/test.rs:2281:41 | 2281 | let unsigned = &[0, u128::from(u64::max_value())]; | ^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants help: use the associated constant instead | 2281 | let unsigned = &[0, u128::from(u64::MAX)]; | ~~~ warning: usage of a legacy numeric method --> tests/test.rs:2294:44 | 2294 | let err = to_value(u128::from(u64::max_value()) + 1).unwrap_err(); | ^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants help: use the associated constant instead | 2294 | let err = to_value(u128::from(u64::MAX) + 1).unwrap_err(); | ~~~ --- src/de.rs | 8 ++++---- src/lexical/exponent.rs | 4 ++-- src/lexical/rounding.rs | 2 +- src/number.rs | 8 ++++---- tests/lexical/exponent.rs | 34 ++++++++-------------------------- tests/test.rs | 28 +++++++++++++--------------- 6 files changed, 32 insertions(+), 52 deletions(-) diff --git a/src/de.rs b/src/de.rs index 7154f84d2..c7774f687 100644 --- a/src/de.rs +++ b/src/de.rs @@ -481,7 +481,7 @@ impl<'de, R: Read<'de>> Deserializer { // try to keep the number as a `u64` until we grow // too large. At that point, switch to parsing the // value as a `f64`. - if overflow!(significand * 10 + digit, u64::max_value()) { + if overflow!(significand * 10 + digit, u64::MAX) { return Ok(ParserNumber::F64(tri!( self.parse_long_integer(positive, significand), ))); @@ -533,7 +533,7 @@ impl<'de, R: Read<'de>> Deserializer { while let c @ b'0'..=b'9' = tri!(self.peek_or_null()) { let digit = (c - b'0') as u64; - if overflow!(significand * 10 + digit, u64::max_value()) { + if overflow!(significand * 10 + digit, u64::MAX) { let exponent = exponent_before_decimal_point + exponent_after_decimal_point; return self.parse_decimal_overflow(positive, significand, exponent); } @@ -597,7 +597,7 @@ impl<'de, R: Read<'de>> Deserializer { self.eat_char(); let digit = (c - b'0') as i32; - if overflow!(exp * 10 + digit, i32::max_value()) { + if overflow!(exp * 10 + digit, i32::MAX) { let zero_significand = significand == 0; return self.parse_exponent_overflow(positive, zero_significand, positive_exp); } @@ -789,7 +789,7 @@ impl<'de, R: Read<'de>> Deserializer { self.eat_char(); let digit = (c - b'0') as i32; - if overflow!(exp * 10 + digit, i32::max_value()) { + if overflow!(exp * 10 + digit, i32::MAX) { let zero_significand = self.scratch.iter().all(|&digit| digit == b'0'); return self.parse_exponent_overflow(positive, zero_significand, positive_exp); } diff --git a/src/lexical/exponent.rs b/src/lexical/exponent.rs index 6fc51977e..5e27de893 100644 --- a/src/lexical/exponent.rs +++ b/src/lexical/exponent.rs @@ -8,8 +8,8 @@ /// the mantissa we do not overflow for comically-long exponents. #[inline] fn into_i32(value: usize) -> i32 { - if value > i32::max_value() as usize { - i32::max_value() + if value > i32::MAX as usize { + i32::MAX } else { value as i32 } diff --git a/src/lexical/rounding.rs b/src/lexical/rounding.rs index 6ec1292aa..634487522 100644 --- a/src/lexical/rounding.rs +++ b/src/lexical/rounding.rs @@ -25,7 +25,7 @@ pub(crate) fn lower_n_mask(n: u64) -> u64 { debug_assert!(n <= bits, "lower_n_mask() overflow in shl."); if n == bits { - u64::max_value() + u64::MAX } else { (1 << n) - 1 } diff --git a/src/number.rs b/src/number.rs index b0231a87b..878a3dcb2 100644 --- a/src/number.rs +++ b/src/number.rs @@ -82,7 +82,7 @@ impl Number { /// ``` /// # use serde_json::json; /// # - /// let big = i64::max_value() as u64 + 10; + /// let big = i64::MAX as u64 + 10; /// let v = json!({ "a": 64, "b": big, "c": 256.0 }); /// /// assert!(v["a"].is_i64()); @@ -97,7 +97,7 @@ impl Number { pub fn is_i64(&self) -> bool { #[cfg(not(feature = "arbitrary_precision"))] match self.n { - N::PosInt(v) => v <= i64::max_value() as u64, + N::PosInt(v) => v <= i64::MAX as u64, N::NegInt(_) => true, N::Float(_) => false, } @@ -177,7 +177,7 @@ impl Number { /// ``` /// # use serde_json::json; /// # - /// let big = i64::max_value() as u64 + 10; + /// let big = i64::MAX as u64 + 10; /// let v = json!({ "a": 64, "b": big, "c": 256.0 }); /// /// assert_eq!(v["a"].as_i64(), Some(64)); @@ -189,7 +189,7 @@ impl Number { #[cfg(not(feature = "arbitrary_precision"))] match self.n { N::PosInt(n) => { - if n <= i64::max_value() as u64 { + if n <= i64::MAX as u64 { Some(n as i64) } else { None diff --git a/tests/lexical/exponent.rs b/tests/lexical/exponent.rs index f7a847be3..c109ff07d 100644 --- a/tests/lexical/exponent.rs +++ b/tests/lexical/exponent.rs @@ -17,38 +17,20 @@ fn scientific_exponent_test() { assert_eq!(scientific_exponent(-10, 2, 20), -9); // Underflow - assert_eq!( - scientific_exponent(i32::min_value(), 0, 0), - i32::min_value() - ); - assert_eq!( - scientific_exponent(i32::min_value(), 0, 5), - i32::min_value() - ); + assert_eq!(scientific_exponent(i32::MIN, 0, 0), i32::MIN); + assert_eq!(scientific_exponent(i32::MIN, 0, 5), i32::MIN); // Overflow - assert_eq!( - scientific_exponent(i32::max_value(), 0, 0), - i32::max_value() - 1 - ); - assert_eq!( - scientific_exponent(i32::max_value(), 5, 0), - i32::max_value() - ); + assert_eq!(scientific_exponent(i32::MAX, 0, 0), i32::MAX - 1); + assert_eq!(scientific_exponent(i32::MAX, 5, 0), i32::MAX); } #[test] fn mantissa_exponent_test() { assert_eq!(mantissa_exponent(10, 5, 0), 5); assert_eq!(mantissa_exponent(0, 5, 0), -5); - assert_eq!( - mantissa_exponent(i32::max_value(), 5, 0), - i32::max_value() - 5 - ); - assert_eq!(mantissa_exponent(i32::max_value(), 0, 5), i32::max_value()); - assert_eq!(mantissa_exponent(i32::min_value(), 5, 0), i32::min_value()); - assert_eq!( - mantissa_exponent(i32::min_value(), 0, 5), - i32::min_value() + 5 - ); + assert_eq!(mantissa_exponent(i32::MAX, 5, 0), i32::MAX - 5); + assert_eq!(mantissa_exponent(i32::MAX, 0, 5), i32::MAX); + assert_eq!(mantissa_exponent(i32::MIN, 5, 0), i32::MIN); + assert_eq!(mantissa_exponent(i32::MIN, 0, 5), i32::MIN + 5); } diff --git a/tests/test.rs b/tests/test.rs index c227b9066..7e6adad76 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -44,8 +44,6 @@ use std::marker::PhantomData; use std::mem; use std::str::FromStr; use std::{f32, f64}; -use std::{i16, i32, i64, i8}; -use std::{u16, u32, u64, u8}; macro_rules! treemap { () => { @@ -158,28 +156,28 @@ fn test_write_f64() { #[test] fn test_encode_nonfinite_float_yields_null() { - let v = to_value(::std::f64::NAN.copysign(1.0)).unwrap(); + let v = to_value(f64::NAN.copysign(1.0)).unwrap(); assert!(v.is_null()); - let v = to_value(::std::f64::NAN.copysign(-1.0)).unwrap(); + let v = to_value(f64::NAN.copysign(-1.0)).unwrap(); assert!(v.is_null()); - let v = to_value(::std::f64::INFINITY).unwrap(); + let v = to_value(f64::INFINITY).unwrap(); assert!(v.is_null()); - let v = to_value(-::std::f64::INFINITY).unwrap(); + let v = to_value(-f64::INFINITY).unwrap(); assert!(v.is_null()); - let v = to_value(::std::f32::NAN.copysign(1.0)).unwrap(); + let v = to_value(f32::NAN.copysign(1.0)).unwrap(); assert!(v.is_null()); - let v = to_value(::std::f32::NAN.copysign(-1.0)).unwrap(); + let v = to_value(f32::NAN.copysign(-1.0)).unwrap(); assert!(v.is_null()); - let v = to_value(::std::f32::INFINITY).unwrap(); + let v = to_value(f32::INFINITY).unwrap(); assert!(v.is_null()); - let v = to_value(-::std::f32::INFINITY).unwrap(); + let v = to_value(-f32::INFINITY).unwrap(); assert!(v.is_null()); } @@ -2240,8 +2238,8 @@ fn null_invalid_type() { #[test] fn test_integer128() { - let signed = &[i128::min_value(), -1, 0, 1, i128::max_value()]; - let unsigned = &[0, 1, u128::max_value()]; + let signed = &[i128::MIN, -1, 0, 1, i128::MAX]; + let unsigned = &[0, 1, u128::MAX]; for integer128 in signed { let expected = integer128.to_string(); @@ -2277,8 +2275,8 @@ fn test_integer128() { #[test] fn test_integer128_to_value() { - let signed = &[i128::from(i64::min_value()), i128::from(u64::max_value())]; - let unsigned = &[0, u128::from(u64::max_value())]; + let signed = &[i128::from(i64::MIN), i128::from(u64::MAX)]; + let unsigned = &[0, u128::from(u64::MAX)]; for integer128 in signed { let expected = integer128.to_string(); @@ -2291,7 +2289,7 @@ fn test_integer128_to_value() { } if !cfg!(feature = "arbitrary_precision") { - let err = to_value(u128::from(u64::max_value()) + 1).unwrap_err(); + let err = to_value(u128::from(u64::MAX) + 1).unwrap_err(); assert_eq!(err.to_string(), "number out of range"); } } From 2e15e3d7d53a68f78ff559709c57e4fa70584bb7 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Mon, 8 Apr 2024 11:57:46 -0700 Subject: [PATCH 22/30] Revert "Temporarily disable miri on doctests" This reverts commit 3a3f61b1c9a2dce973179fad1650f709f63bdaa5. --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 75cc7bfe6..e55d307dd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -89,8 +89,8 @@ jobs: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@miri - run: cargo miri setup - - run: cargo miri test --all-targets # exclude doctests https://github.com/rust-lang/miri/issues/3404 - - run: cargo miri test --features preserve_order,float_roundtrip,arbitrary_precision,raw_value --all-targets + - run: cargo miri test + - run: cargo miri test --features preserve_order,float_roundtrip,arbitrary_precision,raw_value clippy: name: Clippy From 25dc75050aee18ff42342bdb64c1e97542d17267 Mon Sep 17 00:00:00 2001 From: Michael Leonhard Date: Mon, 15 Apr 2024 13:07:18 -0700 Subject: [PATCH 23/30] Replace `features_check` mod with a call to `std::compile_error!`. Fixes https://github.com/serde-rs/json/issues/1123 . --- src/features_check/error.rs | 1 - src/features_check/mod.rs | 13 ------------- src/lib.rs | 5 +++-- 3 files changed, 3 insertions(+), 16 deletions(-) delete mode 100644 src/features_check/error.rs delete mode 100644 src/features_check/mod.rs diff --git a/src/features_check/error.rs b/src/features_check/error.rs deleted file mode 100644 index 22e58235c..000000000 --- a/src/features_check/error.rs +++ /dev/null @@ -1 +0,0 @@ -"serde_json requires that either `std` (default) or `alloc` feature is enabled" diff --git a/src/features_check/mod.rs b/src/features_check/mod.rs deleted file mode 100644 index d12032cef..000000000 --- a/src/features_check/mod.rs +++ /dev/null @@ -1,13 +0,0 @@ -//! Shows a user-friendly compiler error on incompatible selected features. - -#[allow(unused_macros)] -macro_rules! hide_from_rustfmt { - ($mod:item) => { - $mod - }; -} - -#[cfg(not(any(feature = "std", feature = "alloc")))] -hide_from_rustfmt! { - mod error; -} diff --git a/src/lib.rs b/src/lib.rs index 32c4fc456..b6f183a17 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -363,6 +363,9 @@ #![no_std] #![cfg_attr(docsrs, feature(doc_cfg))] +#[cfg(not(any(feature = "std", feature = "alloc")))] +compile_error!("serde_json requires that either `std` (default) or `alloc` feature is enabled"); + extern crate alloc; #[cfg(feature = "std")] @@ -409,8 +412,6 @@ pub mod ser; mod ser; pub mod value; -mod features_check; - mod io; #[cfg(feature = "std")] mod iter; From 12c8ee0ce6eaca3a809e83d9df768b67322a7f2a Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Mon, 15 Apr 2024 22:08:33 -0700 Subject: [PATCH 24/30] Hide "non-exhaustive patterns" errors when crate fails to compile Fixes #1125. error: expected item, found `"serde_json requires that either `std` (default) or `alloc` feature is enabled"` --> ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/serde_json-1.0.115/src/features_check/error.rs:1:1 | 1 | "serde_json requires that either `std` (default) or `alloc` feature is enabled" | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected item | = note: for a full list of items that can appear in modules, see error[E0004]: non-exhaustive patterns: `Value::String(_)` not covered --> ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/serde_json-1.0.115/src/value/de.rs:216:15 | 216 | match self { | ^^^^ pattern `Value::String(_)` not covered | note: `Value` defined here --> ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/serde_json-1.0.115/src/value/mod.rs:116:10 | 116 | pub enum Value { | ^^^^^ ... 151 | String(String), | ------ not covered = note: the matched value is of type `Value` help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown | 223 ~ Value::Object(v) => visit_object(v, visitor), 224 ~ Value::String(_) => todo!(), | error[E0004]: non-exhaustive patterns: `Cow::Owned(_)` not covered --> ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/serde_json-1.0.115/src/value/de.rs:1338:15 | 1338 | match self.value { | ^^^^^^^^^^ pattern `Cow::Owned(_)` not covered | note: `Cow<'_, str>` defined here --> /rustc/98aa3624be70462d6a25ed5544333e3df62f4c66/library/alloc/src/borrow.rs:180:1 ::: /rustc/98aa3624be70462d6a25ed5544333e3df62f4c66/library/alloc/src/borrow.rs:190:5 | = note: not covered = note: the matched value is of type `Cow<'_, str>` help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown | 1339 ~ Cow::Borrowed(string) => visitor.visit_borrowed_str(string), 1340 ~ Cow::Owned(_) => todo!(), | error[E0004]: non-exhaustive patterns: `&Value::Object(_)` not covered --> ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/serde_json-1.0.115/src/value/ser.rs:17:15 | 17 | match self { | ^^^^ pattern `&Value::Object(_)` not covered | note: `Value` defined here --> ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/serde_json-1.0.115/src/value/mod.rs:116:10 | 116 | pub enum Value { | ^^^^^ ... 175 | Object(Map), | ------ not covered = note: the matched value is of type `&Value` help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown | 22 ~ Value::Array(v) => v.serialize(serializer), 23 ~ &Value::Object(_) => todo!(), | --- src/value/de.rs | 4 ++++ src/value/ser.rs | 2 ++ 2 files changed, 6 insertions(+) diff --git a/src/value/de.rs b/src/value/de.rs index 1e8b5acbb..936725635 100644 --- a/src/value/de.rs +++ b/src/value/de.rs @@ -219,6 +219,8 @@ impl<'de> serde::Deserializer<'de> for Value { Value::Number(n) => n.deserialize_any(visitor), #[cfg(any(feature = "std", feature = "alloc"))] Value::String(v) => visitor.visit_string(v), + #[cfg(not(any(feature = "std", feature = "alloc")))] + Value::String(_) => unreachable!(), Value::Array(v) => visit_array(v, visitor), Value::Object(v) => visit_object(v, visitor), } @@ -1339,6 +1341,8 @@ impl<'de> de::Deserializer<'de> for BorrowedCowStrDeserializer<'de> { Cow::Borrowed(string) => visitor.visit_borrowed_str(string), #[cfg(any(feature = "std", feature = "alloc"))] Cow::Owned(string) => visitor.visit_string(string), + #[cfg(not(any(feature = "std", feature = "alloc")))] + Cow::Owned(_) => unreachable!(), } } diff --git a/src/value/ser.rs b/src/value/ser.rs index 835fa9080..e869ae160 100644 --- a/src/value/ser.rs +++ b/src/value/ser.rs @@ -29,6 +29,8 @@ impl Serialize for Value { } map.end() } + #[cfg(not(any(feature = "std", feature = "alloc")))] + Value::Object(_) => unreachable!(), } } } From a3f62bb10ea870dafe3b49a77dc6c1713ca4b7e4 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Mon, 15 Apr 2024 22:10:38 -0700 Subject: [PATCH 25/30] Release 1.0.116 --- Cargo.toml | 2 +- src/lib.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 38b6d6ec8..61e6335da 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "serde_json" -version = "1.0.115" +version = "1.0.116" authors = ["Erick Tryzelaar ", "David Tolnay "] categories = ["encoding", "parser-implementations", "no-std"] description = "A JSON serialization file format" diff --git a/src/lib.rs b/src/lib.rs index 5d730102b..eabd169f5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -299,7 +299,7 @@ //! [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.115")] +#![doc(html_root_url = "https://docs.rs/serde_json/1.0.116")] // Ignored clippy lints #![allow( clippy::collapsible_else_if, From 98f1a247de77176f605c39e225f81c6e80d93727 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Tue, 7 May 2024 16:38:34 -0700 Subject: [PATCH 26/30] Resolve unexpected_cfgs warning warning: unexpected `cfg` condition name: `limb_width_32` --> src/lexical/mod.rs:31:7 | 31 | #[cfg(limb_width_32)] | ^^^^^^^^^^^^^ | = help: expected names are: `clippy`, `debug_assertions`, `doc`, `docsrs`, `doctest`, `feature`, `miri`, `overflow_checks`, `panic`, `proc_macro`, `relocation_model`, `rustfmt`, `sanitize`, `sanitizer_cfi_generalize_pointers`, `sanitizer_cfi_normalize_integers`, `target_abi`, `target_arch`, `target_endian`, `target_env`, `target_family`, `target_feature`, `target_has_atomic`, `target_has_atomic_equal_alignment`, `target_has_atomic_load_store`, `target_os`, `target_pointer_width`, `target_thread_local`, `target_vendor`, `test`, `ub_checks`, `unix`, `windows` = help: consider using a Cargo feature instead or adding `println!("cargo::rustc-check-cfg=cfg(limb_width_32)");` to the top of the `build.rs` = note: see for more information about checking conditional configuration = note: `#[warn(unexpected_cfgs)]` on by default warning: unexpected `cfg` condition name: `limb_width_64` --> src/lexical/mod.rs:34:7 | 34 | #[cfg(limb_width_64)] | ^^^^^^^^^^^^^ | = help: consider using a Cargo feature instead or adding `println!("cargo::rustc-check-cfg=cfg(limb_width_64)");` to the top of the `build.rs` = note: see for more information about checking conditional configuration warning: unexpected `cfg` condition name: `limb_width_32` --> src/lexical/large_powers.rs:5:7 | 5 | #[cfg(limb_width_32)] | ^^^^^^^^^^^^^ | = help: consider using a Cargo feature instead or adding `println!("cargo::rustc-check-cfg=cfg(limb_width_32)");` to the top of the `build.rs` = note: see for more information about checking conditional configuration warning: unexpected `cfg` condition name: `limb_width_64` --> src/lexical/large_powers.rs:8:7 | 8 | #[cfg(limb_width_64)] | ^^^^^^^^^^^^^ | = help: consider using a Cargo feature instead or adding `println!("cargo::rustc-check-cfg=cfg(limb_width_64)");` to the top of the `build.rs` = note: see for more information about checking conditional configuration warning: unexpected `cfg` condition name: `limb_width_32` --> src/lexical/math.rs:40:7 | 40 | #[cfg(limb_width_32)] | ^^^^^^^^^^^^^ | = help: consider using a Cargo feature instead or adding `println!("cargo::rustc-check-cfg=cfg(limb_width_32)");` to the top of the `build.rs` = note: see for more information about checking conditional configuration warning: unexpected `cfg` condition name: `limb_width_32` --> src/lexical/math.rs:43:7 | 43 | #[cfg(limb_width_32)] | ^^^^^^^^^^^^^ | = help: consider using a Cargo feature instead or adding `println!("cargo::rustc-check-cfg=cfg(limb_width_32)");` to the top of the `build.rs` = note: see for more information about checking conditional configuration warning: unexpected `cfg` condition name: `limb_width_32` --> src/lexical/math.rs:46:7 | 46 | #[cfg(limb_width_32)] | ^^^^^^^^^^^^^ | = help: consider using a Cargo feature instead or adding `println!("cargo::rustc-check-cfg=cfg(limb_width_32)");` to the top of the `build.rs` = note: see for more information about checking conditional configuration warning: unexpected `cfg` condition name: `limb_width_32` --> src/lexical/math.rs:49:7 | 49 | #[cfg(limb_width_32)] | ^^^^^^^^^^^^^ | = help: consider using a Cargo feature instead or adding `println!("cargo::rustc-check-cfg=cfg(limb_width_32)");` to the top of the `build.rs` = note: see for more information about checking conditional configuration warning: unexpected `cfg` condition name: `limb_width_64` --> src/lexical/math.rs:53:7 | 53 | #[cfg(limb_width_64)] | ^^^^^^^^^^^^^ | = help: consider using a Cargo feature instead or adding `println!("cargo::rustc-check-cfg=cfg(limb_width_64)");` to the top of the `build.rs` = note: see for more information about checking conditional configuration warning: unexpected `cfg` condition name: `limb_width_64` --> src/lexical/math.rs:56:7 | 56 | #[cfg(limb_width_64)] | ^^^^^^^^^^^^^ | = help: consider using a Cargo feature instead or adding `println!("cargo::rustc-check-cfg=cfg(limb_width_64)");` to the top of the `build.rs` = note: see for more information about checking conditional configuration warning: unexpected `cfg` condition name: `limb_width_64` --> src/lexical/math.rs:59:7 | 59 | #[cfg(limb_width_64)] | ^^^^^^^^^^^^^ | = help: consider using a Cargo feature instead or adding `println!("cargo::rustc-check-cfg=cfg(limb_width_64)");` to the top of the `build.rs` = note: see for more information about checking conditional configuration warning: unexpected `cfg` condition name: `limb_width_64` --> src/lexical/math.rs:62:7 | 62 | #[cfg(limb_width_64)] | ^^^^^^^^^^^^^ | = help: consider using a Cargo feature instead or adding `println!("cargo::rustc-check-cfg=cfg(limb_width_64)");` to the top of the `build.rs` = note: see for more information about checking conditional configuration warning: unexpected `cfg` condition name: `limb_width_32` --> src/lexical/math.rs:82:7 | 82 | #[cfg(limb_width_32)] | ^^^^^^^^^^^^^ | = help: consider using a Cargo feature instead or adding `println!("cargo::rustc-check-cfg=cfg(limb_width_32)");` to the top of the `build.rs` = note: see for more information about checking conditional configuration warning: unexpected `cfg` condition name: `limb_width_64` --> src/lexical/math.rs:89:7 | 89 | #[cfg(limb_width_64)] | ^^^^^^^^^^^^^ | = help: consider using a Cargo feature instead or adding `println!("cargo::rustc-check-cfg=cfg(limb_width_64)");` to the top of the `build.rs` = note: see for more information about checking conditional configuration warning: unexpected `cfg` condition name: `limb_width_32` --> src/lexical/small_powers.rs:6:7 | 6 | #[cfg(limb_width_32)] | ^^^^^^^^^^^^^ | = help: consider using a Cargo feature instead or adding `println!("cargo::rustc-check-cfg=cfg(limb_width_32)");` to the top of the `build.rs` = note: see for more information about checking conditional configuration warning: unexpected `cfg` condition name: `limb_width_32` --> src/lexical/small_powers.rs:12:7 | 12 | #[cfg(limb_width_32)] | ^^^^^^^^^^^^^ | = help: consider using a Cargo feature instead or adding `println!("cargo::rustc-check-cfg=cfg(limb_width_32)");` to the top of the `build.rs` = note: see for more information about checking conditional configuration warning: unexpected `cfg` condition name: `limb_width_64` --> src/lexical/small_powers.rs:18:7 | 18 | #[cfg(limb_width_64)] | ^^^^^^^^^^^^^ | = help: consider using a Cargo feature instead or adding `println!("cargo::rustc-check-cfg=cfg(limb_width_64)");` to the top of the `build.rs` = note: see for more information about checking conditional configuration warning: unexpected `cfg` condition name: `limb_width_32` --> tests/../src/lexical/mod.rs:31:7 | 31 | #[cfg(limb_width_32)] | ^^^^^^^^^^^^^ | = help: expected names are: `clippy`, `debug_assertions`, `doc`, `docsrs`, `doctest`, `feature`, `miri`, `overflow_checks`, `panic`, `proc_macro`, `relocation_model`, `rustfmt`, `sanitize`, `sanitizer_cfi_generalize_pointers`, `sanitizer_cfi_normalize_integers`, `target_abi`, `target_arch`, `target_endian`, `target_env`, `target_family`, `target_feature`, `target_has_atomic`, `target_has_atomic_equal_alignment`, `target_has_atomic_load_store`, `target_os`, `target_pointer_width`, `target_thread_local`, `target_vendor`, `test`, `ub_checks`, `unix`, `windows` = help: consider using a Cargo feature instead or adding `println!("cargo::rustc-check-cfg=cfg(limb_width_32)");` to the top of the `build.rs` = note: see for more information about checking conditional configuration = note: `#[warn(unexpected_cfgs)]` on by default warning: unexpected `cfg` condition name: `limb_width_64` --> tests/../src/lexical/mod.rs:34:7 | 34 | #[cfg(limb_width_64)] | ^^^^^^^^^^^^^ | = help: consider using a Cargo feature instead or adding `println!("cargo::rustc-check-cfg=cfg(limb_width_64)");` to the top of the `build.rs` = note: see for more information about checking conditional configuration warning: unexpected `cfg` condition name: `limb_width_32` --> tests/../src/lexical/large_powers.rs:5:7 | 5 | #[cfg(limb_width_32)] | ^^^^^^^^^^^^^ | = help: consider using a Cargo feature instead or adding `println!("cargo::rustc-check-cfg=cfg(limb_width_32)");` to the top of the `build.rs` = note: see for more information about checking conditional configuration warning: unexpected `cfg` condition name: `limb_width_64` --> tests/../src/lexical/large_powers.rs:8:7 | 8 | #[cfg(limb_width_64)] | ^^^^^^^^^^^^^ | = help: consider using a Cargo feature instead or adding `println!("cargo::rustc-check-cfg=cfg(limb_width_64)");` to the top of the `build.rs` = note: see for more information about checking conditional configuration warning: unexpected `cfg` condition name: `limb_width_32` --> tests/../src/lexical/math.rs:40:7 | 40 | #[cfg(limb_width_32)] | ^^^^^^^^^^^^^ | = help: consider using a Cargo feature instead or adding `println!("cargo::rustc-check-cfg=cfg(limb_width_32)");` to the top of the `build.rs` = note: see for more information about checking conditional configuration warning: unexpected `cfg` condition name: `limb_width_32` --> tests/../src/lexical/math.rs:43:7 | 43 | #[cfg(limb_width_32)] | ^^^^^^^^^^^^^ | = help: consider using a Cargo feature instead or adding `println!("cargo::rustc-check-cfg=cfg(limb_width_32)");` to the top of the `build.rs` = note: see for more information about checking conditional configuration warning: unexpected `cfg` condition name: `limb_width_32` --> tests/../src/lexical/math.rs:46:7 | 46 | #[cfg(limb_width_32)] | ^^^^^^^^^^^^^ | = help: consider using a Cargo feature instead or adding `println!("cargo::rustc-check-cfg=cfg(limb_width_32)");` to the top of the `build.rs` = note: see for more information about checking conditional configuration warning: unexpected `cfg` condition name: `limb_width_32` --> tests/../src/lexical/math.rs:49:7 | 49 | #[cfg(limb_width_32)] | ^^^^^^^^^^^^^ | = help: consider using a Cargo feature instead or adding `println!("cargo::rustc-check-cfg=cfg(limb_width_32)");` to the top of the `build.rs` = note: see for more information about checking conditional configuration warning: unexpected `cfg` condition name: `limb_width_64` --> tests/../src/lexical/math.rs:53:7 | 53 | #[cfg(limb_width_64)] | ^^^^^^^^^^^^^ | = help: consider using a Cargo feature instead or adding `println!("cargo::rustc-check-cfg=cfg(limb_width_64)");` to the top of the `build.rs` = note: see for more information about checking conditional configuration warning: unexpected `cfg` condition name: `limb_width_64` --> tests/../src/lexical/math.rs:56:7 | 56 | #[cfg(limb_width_64)] | ^^^^^^^^^^^^^ | = help: consider using a Cargo feature instead or adding `println!("cargo::rustc-check-cfg=cfg(limb_width_64)");` to the top of the `build.rs` = note: see for more information about checking conditional configuration warning: unexpected `cfg` condition name: `limb_width_64` --> tests/../src/lexical/math.rs:59:7 | 59 | #[cfg(limb_width_64)] | ^^^^^^^^^^^^^ | = help: consider using a Cargo feature instead or adding `println!("cargo::rustc-check-cfg=cfg(limb_width_64)");` to the top of the `build.rs` = note: see for more information about checking conditional configuration warning: unexpected `cfg` condition name: `limb_width_64` --> tests/../src/lexical/math.rs:62:7 | 62 | #[cfg(limb_width_64)] | ^^^^^^^^^^^^^ | = help: consider using a Cargo feature instead or adding `println!("cargo::rustc-check-cfg=cfg(limb_width_64)");` to the top of the `build.rs` = note: see for more information about checking conditional configuration warning: unexpected `cfg` condition name: `limb_width_32` --> tests/../src/lexical/math.rs:82:7 | 82 | #[cfg(limb_width_32)] | ^^^^^^^^^^^^^ | = help: consider using a Cargo feature instead or adding `println!("cargo::rustc-check-cfg=cfg(limb_width_32)");` to the top of the `build.rs` = note: see for more information about checking conditional configuration warning: unexpected `cfg` condition name: `limb_width_64` --> tests/../src/lexical/math.rs:89:7 | 89 | #[cfg(limb_width_64)] | ^^^^^^^^^^^^^ | = help: consider using a Cargo feature instead or adding `println!("cargo::rustc-check-cfg=cfg(limb_width_64)");` to the top of the `build.rs` = note: see for more information about checking conditional configuration warning: unexpected `cfg` condition name: `limb_width_32` --> tests/../src/lexical/small_powers.rs:6:7 | 6 | #[cfg(limb_width_32)] | ^^^^^^^^^^^^^ | = help: consider using a Cargo feature instead or adding `println!("cargo::rustc-check-cfg=cfg(limb_width_32)");` to the top of the `build.rs` = note: see for more information about checking conditional configuration warning: unexpected `cfg` condition name: `limb_width_32` --> tests/../src/lexical/small_powers.rs:12:7 | 12 | #[cfg(limb_width_32)] | ^^^^^^^^^^^^^ | = help: consider using a Cargo feature instead or adding `println!("cargo::rustc-check-cfg=cfg(limb_width_32)");` to the top of the `build.rs` = note: see for more information about checking conditional configuration warning: unexpected `cfg` condition name: `limb_width_64` --> tests/../src/lexical/small_powers.rs:18:7 | 18 | #[cfg(limb_width_64)] | ^^^^^^^^^^^^^ | = help: consider using a Cargo feature instead or adding `println!("cargo::rustc-check-cfg=cfg(limb_width_64)");` to the top of the `build.rs` = note: see for more information about checking conditional configuration warning: unexpected `cfg` condition name: `limb_width_32` --> tests/lexical/math.rs:21:7 | 21 | #[cfg(limb_width_32)] | ^^^^^^^^^^^^^ | = help: consider using a Cargo feature instead or adding `println!("cargo::rustc-check-cfg=cfg(limb_width_32)");` to the top of the `build.rs` = note: see for more information about checking conditional configuration warning: unexpected `cfg` condition name: `limb_width_64` --> tests/lexical/math.rs:26:7 | 26 | #[cfg(limb_width_64)] | ^^^^^^^^^^^^^ | = help: consider using a Cargo feature instead or adding `println!("cargo::rustc-check-cfg=cfg(limb_width_64)");` to the top of the `build.rs` = note: see for more information about checking conditional configuration --- build.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/build.rs b/build.rs index dd09e62a3..433ce12c1 100644 --- a/build.rs +++ b/build.rs @@ -3,6 +3,10 @@ use std::env; fn main() { println!("cargo:rerun-if-changed=build.rs"); + println!("cargo:rustc-check-cfg=cfg(integer128)"); + println!("cargo:rustc-check-cfg=cfg(limb_width_32)"); + println!("cargo:rustc-check-cfg=cfg(limb_width_64)"); + // Decide ideal limb width for arithmetic in the float parser. Refer to // src/lexical/math.rs for where this has an effect. let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap(); From fdf99c7c38c1ee48554eaea66b701f470544d037 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Tue, 7 May 2024 16:51:35 -0700 Subject: [PATCH 27/30] Combine number PartialEq tests --- build.rs | 1 - tests/test.rs | 32 ++++++++++++++------------------ 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/build.rs b/build.rs index 433ce12c1..f2124b43f 100644 --- a/build.rs +++ b/build.rs @@ -3,7 +3,6 @@ use std::env; fn main() { println!("cargo:rerun-if-changed=build.rs"); - println!("cargo:rustc-check-cfg=cfg(integer128)"); println!("cargo:rustc-check-cfg=cfg(limb_width_32)"); println!("cargo:rustc-check-cfg=cfg(limb_width_64)"); diff --git a/tests/test.rs b/tests/test.rs index 7e6adad76..16840660e 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -2100,20 +2100,20 @@ fn issue_220() { assert_eq!(from_str::(r#"{"V": 0}"#).unwrap(), E::V(0)); } -macro_rules! number_partialeq_ok { - ($($n:expr)*) => { - $( - let value = to_value($n).unwrap(); - let s = $n.to_string(); - assert_eq!(value, $n); - assert_eq!($n, value); - assert_ne!(value, s); - )* - } -} - #[test] fn test_partialeq_number() { + macro_rules! number_partialeq_ok { + ($($n:expr)*) => { + $( + let value = to_value($n).unwrap(); + let s = $n.to_string(); + assert_eq!(value, $n); + assert_eq!($n, value); + assert_ne!(value, s); + )* + }; + } + number_partialeq_ok!(0 1 100 i8::MIN i8::MAX i16::MIN i16::MAX i32::MIN i32::MAX i64::MIN i64::MAX u8::MIN u8::MAX u16::MIN u16::MAX u32::MIN u32::MAX u64::MIN u64::MAX @@ -2122,13 +2122,9 @@ fn test_partialeq_number() { f32::consts::E f32::consts::PI f32::consts::LN_2 f32::consts::LOG2_E f64::consts::E f64::consts::PI f64::consts::LN_2 f64::consts::LOG2_E ); -} -#[test] -#[cfg(integer128)] -#[cfg(feature = "arbitrary_precision")] -fn test_partialeq_integer128() { - number_partialeq_ok!(i128::MIN i128::MAX u128::MIN u128::MAX) + #[cfg(feature = "arbitrary_precision")] + number_partialeq_ok!(i128::MIN i128::MAX u128::MIN u128::MAX); } #[test] From 4517c7a2d983a56aa403c651cabe2caf41136570 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Tue, 7 May 2024 17:00:26 -0700 Subject: [PATCH 28/30] PartialEq is not implemented between Value and 128-bit ints --- tests/test.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/test.rs b/tests/test.rs index 16840660e..8c9af6b32 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -2122,9 +2122,6 @@ fn test_partialeq_number() { f32::consts::E f32::consts::PI f32::consts::LN_2 f32::consts::LOG2_E f64::consts::E f64::consts::PI f64::consts::LN_2 f64::consts::LOG2_E ); - - #[cfg(feature = "arbitrary_precision")] - number_partialeq_ok!(i128::MIN i128::MAX u128::MIN u128::MAX); } #[test] From 0ae247ca63be75e6c7e6e0e9cd8916e618cf8f24 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Tue, 7 May 2024 17:05:54 -0700 Subject: [PATCH 29/30] Release 1.0.117 --- Cargo.toml | 2 +- src/lib.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 61e6335da..4817ac7a1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "serde_json" -version = "1.0.116" +version = "1.0.117" authors = ["Erick Tryzelaar ", "David Tolnay "] categories = ["encoding", "parser-implementations", "no-std"] description = "A JSON serialization file format" diff --git a/src/lib.rs b/src/lib.rs index eabd169f5..475cd4475 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -299,7 +299,7 @@ //! [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.116")] +#![doc(html_root_url = "https://docs.rs/serde_json/1.0.117")] // Ignored clippy lints #![allow( clippy::collapsible_else_if, From 8e475f13c2f8abb80e4b5072e45bf3914f229db5 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sat, 18 May 2024 21:06:37 -0700 Subject: [PATCH 30/30] Rely on docs.rs to define --cfg=docsrs by default --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 4817ac7a1..4863c56d9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -34,7 +34,7 @@ doc-scrape-examples = false [package.metadata.docs.rs] features = ["preserve_order", "raw_value", "unbounded_depth"] targets = ["x86_64-unknown-linux-gnu"] -rustdoc-args = ["--cfg", "docsrs", "--generate-link-to-definition"] +rustdoc-args = ["--generate-link-to-definition"] [package.metadata.playground] features = ["raw_value"]