diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3450b7705..568b4d641 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -72,35 +72,23 @@ jobs: if: matrix.os != 'windows' build: - name: Rust ${{matrix.rust}} + name: Rust 1.34.0 runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - rust: [1.19.0, 1.20.0, 1.21.0, 1.25.0, 1.26.0, 1.34.0] timeout-minutes: 45 steps: - uses: actions/checkout@v3 - - uses: dtolnay/rust-toolchain@master - with: - toolchain: ${{matrix.rust}} + - uses: dtolnay/rust-toolchain@1.34.0 - run: cd serde && cargo build --features rc - run: cd serde && cargo build --no-default-features - run: cd serde && cargo build more: - name: Rust ${{matrix.rust}} + name: Rust 1.28.0 runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - rust: [1.27.0, 1.28.0] timeout-minutes: 45 steps: - uses: actions/checkout@v3 - - uses: dtolnay/rust-toolchain@master - with: - toolchain: ${{matrix.rust}} + - uses: dtolnay/rust-toolchain@1.28.0 # Work around failing to parse manifest because editions are unstable. - run: sed -i /test_suite/d Cargo.toml - run: cd serde && cargo build --no-default-features diff --git a/README.md b/README.md index a049250b6..19f0d3c43 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@ -# Serde   [![Build Status]][actions] [![Latest Version]][crates.io] [![serde: rustc 1.19+]][Rust 1.19] [![serde_derive: rustc 1.56+]][Rust 1.56] +# Serde   [![Build Status]][actions] [![Latest Version]][crates.io] [![serde: rustc 1.28+]][Rust 1.28] [![serde_derive: rustc 1.56+]][Rust 1.56] [Build Status]: https://img.shields.io/github/actions/workflow/status/serde-rs/serde/ci.yml?branch=master [actions]: https://github.com/serde-rs/serde/actions?query=branch%3Amaster [Latest Version]: https://img.shields.io/crates/v/serde.svg [crates.io]: https://crates.io/crates/serde -[serde: rustc 1.19+]: https://img.shields.io/badge/serde-rustc_1.19+-lightgray.svg +[serde: rustc 1.28+]: https://img.shields.io/badge/serde-rustc_1.28+-lightgray.svg [serde_derive: rustc 1.56+]: https://img.shields.io/badge/serde_derive-rustc_1.56+-lightgray.svg -[Rust 1.19]: https://blog.rust-lang.org/2017/07/20/Rust-1.19.html +[Rust 1.28]: https://blog.rust-lang.org/2018/08/02/Rust-1.28.html [Rust 1.56]: https://blog.rust-lang.org/2021/10/21/Rust-1.56.0.html **Serde is a framework for *ser*ializing and *de*serializing Rust data structures efficiently and generically.** diff --git a/serde/Cargo.toml b/serde/Cargo.toml index b9959cf02..eba6c5b74 100644 --- a/serde/Cargo.toml +++ b/serde/Cargo.toml @@ -11,7 +11,7 @@ keywords = ["serde", "serialization", "no_std"] license = "MIT OR Apache-2.0" readme = "crates-io.md" repository = "https://github.com/serde-rs/serde" -rust-version = "1.19" +rust-version = "1.28" [dependencies] serde_derive = { version = "=1.0.179", optional = true, path = "../serde_derive" } diff --git a/serde/build.rs b/serde/build.rs index 929d8e172..fb1cfa6d1 100644 --- a/serde/build.rs +++ b/serde/build.rs @@ -16,68 +16,6 @@ fn main() { let target = env::var("TARGET").unwrap(); let emscripten = target == "asmjs-unknown-emscripten" || target == "wasm32-unknown-emscripten"; - // std::collections::Bound was stabilized in Rust 1.17 - // but it was moved to core::ops later in Rust 1.26: - // https://doc.rust-lang.org/core/ops/enum.Bound.html - if minor < 26 { - println!("cargo:rustc-cfg=no_ops_bound"); - if minor < 17 { - println!("cargo:rustc-cfg=no_collections_bound"); - } - } - - // core::cmp::Reverse stabilized in Rust 1.19: - // https://doc.rust-lang.org/stable/core/cmp/struct.Reverse.html - if minor < 19 { - println!("cargo:rustc-cfg=no_core_reverse"); - } - - // CString::into_boxed_c_str and PathBuf::into_boxed_path stabilized in Rust 1.20: - // https://doc.rust-lang.org/std/ffi/struct.CString.html#method.into_boxed_c_str - // https://doc.rust-lang.org/std/path/struct.PathBuf.html#method.into_boxed_path - if minor < 20 { - println!("cargo:rustc-cfg=no_de_boxed_c_str"); - println!("cargo:rustc-cfg=no_de_boxed_path"); - } - - // From> for Rc / Arc stabilized in Rust 1.21: - // https://doc.rust-lang.org/std/rc/struct.Rc.html#impl-From> - // https://doc.rust-lang.org/std/sync/struct.Arc.html#impl-From> - if minor < 21 { - println!("cargo:rustc-cfg=no_de_rc_dst"); - } - - // Duration available in core since Rust 1.25: - // https://blog.rust-lang.org/2018/03/29/Rust-1.25.html#library-stabilizations - if minor < 25 { - println!("cargo:rustc-cfg=no_core_duration"); - } - - // 128-bit integers stabilized in Rust 1.26: - // https://blog.rust-lang.org/2018/05/10/Rust-1.26.html - // - // Disabled on Emscripten targets before Rust 1.40 since - // Emscripten did not support 128-bit integers until Rust 1.40 - // (https://github.com/rust-lang/rust/pull/65251) - if minor < 26 || emscripten && minor < 40 { - println!("cargo:rustc-cfg=no_integer128"); - } - - // Inclusive ranges methods stabilized in Rust 1.27: - // https://github.com/rust-lang/rust/pull/50758 - // Also Iterator::try_for_each: - // https://blog.rust-lang.org/2018/06/21/Rust-1.27.html#library-stabilizations - if minor < 27 { - println!("cargo:rustc-cfg=no_range_inclusive"); - println!("cargo:rustc-cfg=no_iterator_try_fold"); - } - - // Non-zero integers stabilized in Rust 1.28: - // https://blog.rust-lang.org/2018/08/02/Rust-1.28.html#library-stabilizations - if minor < 28 { - println!("cargo:rustc-cfg=no_num_nonzero"); - } - // TryFrom, Atomic types, non-zero signed integers, and SystemTime::checked_add // stabilized in Rust 1.34: // https://blog.rust-lang.org/2019/04/11/Rust-1.34.0.html#tryfrom-and-tryinto @@ -89,6 +27,13 @@ fn main() { println!("cargo:rustc-cfg=no_relaxed_trait_bounds"); } + // Disabled on Emscripten targets before Rust 1.40 since + // Emscripten did not support 128-bit integers until Rust 1.40 + // (https://github.com/rust-lang/rust/pull/65251) + if emscripten && minor < 40 { + println!("cargo:rustc-cfg=no_integer128"); + } + // Current minimum supported version of serde_derive crate is Rust 1.56. if minor < 56 { println!("cargo:rustc-cfg=no_serde_derive"); diff --git a/serde/src/de/impls.rs b/serde/src/de/impls.rs index 12fbdfdb3..0dd039b3c 100644 --- a/serde/src/de/impls.rs +++ b/serde/src/de/impls.rs @@ -1,12 +1,10 @@ use lib::*; use de::{ - Deserialize, Deserializer, EnumAccess, Error, SeqAccess, Unexpected, VariantAccess, Visitor, + Deserialize, Deserializer, EnumAccess, Error, MapAccess, SeqAccess, Unexpected, VariantAccess, + Visitor, }; -#[cfg(any(feature = "std", feature = "alloc", not(no_core_duration)))] -use de::MapAccess; - use seed::InPlaceSeed; #[cfg(any(feature = "std", feature = "alloc"))] @@ -84,7 +82,7 @@ macro_rules! impl_deserialize_num { ($primitive:ident, $nonzero:ident $(cfg($($cfg:tt)*))*, $deserialize:ident $($method:ident!($($val:ident : $visit:ident)*);)*) => { impl_deserialize_num!($primitive, $deserialize $($method!($($val : $visit)*);)*); - #[cfg(all(not(no_num_nonzero), $($($cfg)*)*))] + $(#[cfg($($cfg)*)])* impl<'de> Deserialize<'de> for num::$nonzero { fn deserialize(deserializer: D) -> Result where @@ -747,13 +745,9 @@ macro_rules! forwarded_impl { } } -#[cfg(all( - any(feature = "std", all(not(no_core_cstr), feature = "alloc")), - not(no_de_boxed_c_str) -))] +#[cfg(any(feature = "std", all(not(no_core_cstr), feature = "alloc")))] forwarded_impl!((), Box, CString::into_boxed_c_str); -#[cfg(not(no_core_reverse))] forwarded_impl!((T), Reverse, Reverse); //////////////////////////////////////////////////////////////////////////////// @@ -1714,7 +1708,7 @@ impl<'de> Deserialize<'de> for PathBuf { } } -#[cfg(all(feature = "std", not(no_de_boxed_path)))] +#[cfg(feature = "std")] forwarded_impl!((), Box, PathBuf::into_boxed_path); //////////////////////////////////////////////////////////////////////////////// @@ -1795,30 +1789,6 @@ forwarded_impl!((T), Box<[T]>, Vec::into_boxed_slice); #[cfg(any(feature = "std", feature = "alloc"))] forwarded_impl!((), Box, String::into_boxed_str); -#[cfg(all(no_de_rc_dst, feature = "rc", any(feature = "std", feature = "alloc")))] -forwarded_impl! { - /// This impl requires the [`"rc"`] Cargo feature of Serde. - /// - /// Deserializing a data structure containing `Arc` will not attempt to - /// deduplicate `Arc` references to the same data. Every deserialized `Arc` - /// will end up with a strong count of 1. - /// - /// [`"rc"`]: https://serde.rs/feature-flags.html#-features-rc - (T), Arc, Arc::new -} - -#[cfg(all(no_de_rc_dst, feature = "rc", any(feature = "std", feature = "alloc")))] -forwarded_impl! { - /// This impl requires the [`"rc"`] Cargo feature of Serde. - /// - /// Deserializing a data structure containing `Rc` will not attempt to - /// deduplicate `Rc` references to the same data. Every deserialized `Rc` - /// will end up with a strong count of 1. - /// - /// [`"rc"`]: https://serde.rs/feature-flags.html#-features-rc - (T), Rc, Rc::new -} - #[cfg(any(feature = "std", feature = "alloc"))] impl<'de, 'a, T: ?Sized> Deserialize<'de> for Cow<'a, T> where @@ -1874,11 +1844,7 @@ where //////////////////////////////////////////////////////////////////////////////// -#[cfg(all( - not(no_de_rc_dst), - feature = "rc", - any(feature = "std", feature = "alloc") -))] +#[cfg(all(feature = "rc", any(feature = "std", feature = "alloc")))] macro_rules! box_forwarded_impl { ( $(#[doc = $doc:tt])* @@ -1899,11 +1865,7 @@ macro_rules! box_forwarded_impl { }; } -#[cfg(all( - not(no_de_rc_dst), - feature = "rc", - any(feature = "std", feature = "alloc") -))] +#[cfg(all(feature = "rc", any(feature = "std", feature = "alloc")))] box_forwarded_impl! { /// This impl requires the [`"rc"`] Cargo feature of Serde. /// @@ -1915,11 +1877,7 @@ box_forwarded_impl! { Rc } -#[cfg(all( - not(no_de_rc_dst), - feature = "rc", - any(feature = "std", feature = "alloc") -))] +#[cfg(all(feature = "rc", any(feature = "std", feature = "alloc")))] box_forwarded_impl! { /// This impl requires the [`"rc"`] Cargo feature of Serde. /// @@ -1963,7 +1921,6 @@ forwarded_impl!((T), RwLock, RwLock::new); // secs: u64, // nanos: u32, // } -#[cfg(any(feature = "std", not(no_core_duration)))] impl<'de> Deserialize<'de> for Duration { fn deserialize(deserializer: D) -> Result where @@ -2281,7 +2238,6 @@ where } } -#[cfg(not(no_range_inclusive))] impl<'de, Idx> Deserialize<'de> for RangeInclusive where Idx: Deserialize<'de>, @@ -2709,7 +2665,6 @@ mod range_to { //////////////////////////////////////////////////////////////////////////////// -#[cfg(any(not(no_ops_bound), all(feature = "std", not(no_collections_bound))))] impl<'de, T> Deserialize<'de> for Bound where T: Deserialize<'de>, diff --git a/serde/src/lib.rs b/serde/src/lib.rs index 30c5e4d60..ea0fa4726 100644 --- a/serde/src/lib.rs +++ b/serde/src/lib.rs @@ -177,14 +177,16 @@ mod lib { pub use self::core::cell::{Cell, RefCell}; pub use self::core::clone::{self, Clone}; + pub use self::core::cmp::Reverse; pub use self::core::convert::{self, From, Into}; pub use self::core::default::{self, Default}; pub use self::core::fmt::{self, Debug, Display}; pub use self::core::marker::{self, PhantomData}; pub use self::core::num::Wrapping; - pub use self::core::ops::{Range, RangeFrom, RangeTo}; + pub use self::core::ops::{Bound, Range, RangeFrom, RangeInclusive, RangeTo}; pub use self::core::option::{self, Option}; pub use self::core::result::{self, Result}; + pub use self::core::time::Duration; #[cfg(all(feature = "alloc", not(feature = "std")))] pub use alloc::borrow::{Cow, ToOwned}; @@ -249,18 +251,6 @@ mod lib { #[cfg(feature = "std")] pub use std::time::{SystemTime, UNIX_EPOCH}; - #[cfg(all(feature = "std", not(no_collections_bound), no_ops_bound))] - pub use std::collections::Bound; - - #[cfg(not(no_core_reverse))] - pub use self::core::cmp::Reverse; - - #[cfg(not(no_ops_bound))] - pub use self::core::ops::Bound; - - #[cfg(not(no_range_inclusive))] - pub use self::core::ops::RangeInclusive; - #[cfg(all(feature = "std", no_target_has_atomic, not(no_std_atomic)))] pub use std::sync::atomic::{ AtomicBool, AtomicI16, AtomicI32, AtomicI8, AtomicIsize, AtomicU16, AtomicU32, AtomicU8, @@ -281,9 +271,6 @@ mod lib { pub use std::sync::atomic::{AtomicI64, AtomicU64}; #[cfg(all(feature = "std", not(no_target_has_atomic), target_has_atomic = "ptr"))] pub use std::sync::atomic::{AtomicIsize, AtomicUsize}; - - #[cfg(any(feature = "std", not(no_core_duration)))] - pub use self::core::time::Duration; } // None of this crate's error handling needs the `From::from` error conversion diff --git a/serde/src/ser/impls.rs b/serde/src/ser/impls.rs index 9cafb3264..72933909f 100644 --- a/serde/src/ser/impls.rs +++ b/serde/src/ser/impls.rs @@ -274,7 +274,6 @@ where //////////////////////////////////////////////////////////////////////////////// -#[cfg(not(no_range_inclusive))] impl Serialize for RangeInclusive where Idx: Serialize, @@ -310,7 +309,6 @@ where //////////////////////////////////////////////////////////////////////////////// -#[cfg(any(not(no_ops_bound), all(feature = "std", not(no_collections_bound))))] impl Serialize for Bound where T: Serialize, @@ -538,7 +536,6 @@ where macro_rules! nonzero_integers { ($($T:ident,)+) => { $( - #[cfg(not(no_num_nonzero))] impl Serialize for num::$T { fn serialize(&self, serializer: S) -> Result where @@ -662,7 +659,6 @@ where //////////////////////////////////////////////////////////////////////////////// -#[cfg(any(feature = "std", not(no_core_duration)))] impl Serialize for Duration { fn serialize(&self, serializer: S) -> Result where @@ -963,7 +959,6 @@ where } } -#[cfg(not(no_core_reverse))] impl Serialize for Reverse where T: Serialize, diff --git a/serde/src/ser/mod.rs b/serde/src/ser/mod.rs index 1aaa7570f..d1a70ddb0 100644 --- a/serde/src/ser/mod.rs +++ b/serde/src/ser/mod.rs @@ -1279,22 +1279,9 @@ pub trait Serializer: Sized { I: IntoIterator, ::Item: Serialize, { - let iter = iter.into_iter(); + let mut iter = iter.into_iter(); let mut serializer = try!(self.serialize_seq(iterator_len_hint(&iter))); - - #[cfg(not(no_iterator_try_fold))] - { - let mut iter = iter; - try!(iter.try_for_each(|item| serializer.serialize_element(&item))); - } - - #[cfg(no_iterator_try_fold)] - { - for item in iter { - try!(serializer.serialize_element(&item)); - } - } - + try!(iter.try_for_each(|item| serializer.serialize_element(&item))); serializer.end() } @@ -1330,22 +1317,9 @@ pub trait Serializer: Sized { V: Serialize, I: IntoIterator, { - let iter = iter.into_iter(); + let mut iter = iter.into_iter(); let mut serializer = try!(self.serialize_map(iterator_len_hint(&iter))); - - #[cfg(not(no_iterator_try_fold))] - { - let mut iter = iter; - try!(iter.try_for_each(|(key, value)| serializer.serialize_entry(&key, &value))); - } - - #[cfg(no_iterator_try_fold)] - { - for (key, value) in iter { - try!(serializer.serialize_entry(&key, &value)); - } - } - + try!(iter.try_for_each(|(key, value)| serializer.serialize_entry(&key, &value))); serializer.end() }