From 13a33b3c338c0dbce2b93f6fe654f68fa6389d02 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Wed, 5 Mar 2025 09:23:29 +0000 Subject: [PATCH] Bump MSRV to 1.56 This is the first cargo version that actually enforces the rust-version field in Cargo.toml --- .github/workflows/ci.yml | 13 ++------ README.md | 4 +-- serde/Cargo.toml | 2 +- serde/build.rs | 21 ------------- serde/src/de/impls.rs | 27 +++++++---------- serde/src/private/mod.rs | 1 - serde/src/ser/impls.rs | 64 +++++----------------------------------- serde/src/std_error.rs | 2 +- 8 files changed, 24 insertions(+), 110 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 50139b6d..446d46b9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -84,7 +84,7 @@ jobs: strategy: fail-fast: false matrix: - rust: [1.31.0, 1.34.0] + rust: [1.56.0, 1.60.0] timeout-minutes: 45 steps: - uses: actions/checkout@v4 @@ -94,6 +94,7 @@ jobs: - run: sed -i '/"test_suite"/d' Cargo.toml - run: cd serde && cargo build --features rc - run: cd serde && cargo build --no-default-features + - run: cd serde && cargo build --no-default-features --features alloc - run: cd serde && cargo build derive: @@ -111,16 +112,6 @@ jobs: - run: cd serde && cargo check - run: cd serde_derive && cargo check - alloc: - name: Rust 1.36.0 - runs-on: ubuntu-latest - timeout-minutes: 45 - steps: - - uses: actions/checkout@v4 - - uses: dtolnay/rust-toolchain@1.36.0 - - run: sed -i '/"test_suite"/d' Cargo.toml - - run: cd serde && cargo build --no-default-features --features alloc - minimal: name: Minimal versions runs-on: ubuntu-latest diff --git a/README.md b/README.md index e3da0cbc..e62820e7 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Serde   [![Build Status]][actions] [![Latest Version]][crates.io] [![serde msrv]][Rust 1.31] [![serde_derive msrv]][Rust 1.61] +# Serde   [![Build Status]][actions] [![Latest Version]][crates.io] [![serde msrv]][Rust 1.56] [![serde_derive msrv]][Rust 1.61] [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 @@ -6,7 +6,7 @@ [crates.io]: https://crates.io/crates/serde [serde msrv]: https://img.shields.io/crates/msrv/serde.svg?label=serde%20msrv&color=lightgray [serde_derive msrv]: https://img.shields.io/crates/msrv/serde_derive.svg?label=serde_derive%20msrv&color=lightgray -[Rust 1.31]: https://blog.rust-lang.org/2018/12/06/Rust-1.31-and-rust-2018.html +[Rust 1.56]: https://blog.rust-lang.org/2021/10/21/Rust-1.56.0.html [Rust 1.61]: https://blog.rust-lang.org/2022/05/19/Rust-1.61.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 2a865cfb..8c81e0f1 100644 --- a/serde/Cargo.toml +++ b/serde/Cargo.toml @@ -12,7 +12,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.31" +rust-version = "1.56" [dependencies] serde_derive = { version = "1", optional = true, path = "../serde_derive" } diff --git a/serde/build.rs b/serde/build.rs index 24aa0e6d..69fa327e 100644 --- a/serde/build.rs +++ b/serde/build.rs @@ -18,38 +18,17 @@ fn main() { println!("cargo:rustc-check-cfg=cfg(no_core_error)"); println!("cargo:rustc-check-cfg=cfg(no_core_net)"); println!("cargo:rustc-check-cfg=cfg(no_core_num_saturating)"); - println!("cargo:rustc-check-cfg=cfg(no_core_try_from)"); println!("cargo:rustc-check-cfg=cfg(no_diagnostic_namespace)"); println!("cargo:rustc-check-cfg=cfg(no_float_copysign)"); - println!("cargo:rustc-check-cfg=cfg(no_num_nonzero_signed)"); - println!("cargo:rustc-check-cfg=cfg(no_relaxed_trait_bounds)"); println!("cargo:rustc-check-cfg=cfg(no_serde_derive)"); println!("cargo:rustc-check-cfg=cfg(no_std_atomic)"); println!("cargo:rustc-check-cfg=cfg(no_std_atomic64)"); - println!("cargo:rustc-check-cfg=cfg(no_systemtime_checked_add)"); println!("cargo:rustc-check-cfg=cfg(no_target_has_atomic)"); } let target = env::var("TARGET").unwrap(); let emscripten = target == "asmjs-unknown-emscripten" || target == "wasm32-unknown-emscripten"; - // 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 - // https://blog.rust-lang.org/2019/04/11/Rust-1.34.0.html#library-stabilizations - if minor < 34 { - println!("cargo:rustc-cfg=no_core_try_from"); - println!("cargo:rustc-cfg=no_num_nonzero_signed"); - println!("cargo:rustc-cfg=no_systemtime_checked_add"); - println!("cargo:rustc-cfg=no_relaxed_trait_bounds"); - } - - // f32::copysign and f64::copysign stabilized in Rust 1.35. - // https://blog.rust-lang.org/2019/05/23/Rust-1.35.0.html#copy-the-sign-of-a-floating-point-number-onto-another - if minor < 35 { - println!("cargo:rustc-cfg=no_float_copysign"); - } - // Support for #[cfg(target_has_atomic = "...")] stabilized in Rust 1.60. if minor < 60 { println!("cargo:rustc-cfg=no_target_has_atomic"); diff --git a/serde/src/de/impls.rs b/serde/src/de/impls.rs index 2d8c9903..037f0d61 100644 --- a/serde/src/de/impls.rs +++ b/serde/src/de/impls.rs @@ -80,10 +80,9 @@ impl<'de> Deserialize<'de> for bool { //////////////////////////////////////////////////////////////////////////////// macro_rules! impl_deserialize_num { - ($primitive:ident, $nonzero:ident $(cfg($($cfg:tt)*))*, $deserialize:ident $($method:ident!($($val:ident : $visit:ident)*);)*) => { + ($primitive:ident, $nonzero:ident, $deserialize:ident $($method:ident!($($val:ident : $visit:ident)*);)*) => { impl_deserialize_num!($primitive, $deserialize $($method!($($val : $visit)*);)*); - $(#[cfg($($cfg)*)])* impl<'de> Deserialize<'de> for num::$nonzero { fn deserialize(deserializer: D) -> Result where @@ -228,12 +227,12 @@ macro_rules! num_as_copysign_self { where E: Error, { - #[cfg(any(no_float_copysign, not(feature = "std")))] + #[cfg(not(feature = "std"))] { Ok(v as Self::Value) } - #[cfg(all(not(no_float_copysign), feature = "std"))] + #[cfg(feature = "std")] { // Preserve sign of NaN. The `as` produces a nondeterministic sign. let sign = if v.is_sign_positive() { 1.0 } else { -1.0 }; @@ -381,14 +380,14 @@ macro_rules! uint_to_self { } impl_deserialize_num! { - i8, NonZeroI8 cfg(not(no_num_nonzero_signed)), deserialize_i8 + i8, NonZeroI8, deserialize_i8 num_self!(i8:visit_i8); int_to_int!(i16:visit_i16 i32:visit_i32 i64:visit_i64); uint_to_self!(u8:visit_u8 u16:visit_u16 u32:visit_u32 u64:visit_u64); } impl_deserialize_num! { - i16, NonZeroI16 cfg(not(no_num_nonzero_signed)), deserialize_i16 + i16, NonZeroI16, deserialize_i16 num_self!(i16:visit_i16); num_as_self!(i8:visit_i8); int_to_int!(i32:visit_i32 i64:visit_i64); @@ -396,7 +395,7 @@ impl_deserialize_num! { } impl_deserialize_num! { - i32, NonZeroI32 cfg(not(no_num_nonzero_signed)), deserialize_i32 + i32, NonZeroI32, deserialize_i32 num_self!(i32:visit_i32); num_as_self!(i8:visit_i8 i16:visit_i16); int_to_int!(i64:visit_i64); @@ -404,14 +403,14 @@ impl_deserialize_num! { } impl_deserialize_num! { - i64, NonZeroI64 cfg(not(no_num_nonzero_signed)), deserialize_i64 + i64, NonZeroI64, deserialize_i64 num_self!(i64:visit_i64); num_as_self!(i8:visit_i8 i16:visit_i16 i32:visit_i32); uint_to_self!(u8:visit_u8 u16:visit_u16 u32:visit_u32 u64:visit_u64); } impl_deserialize_num! { - isize, NonZeroIsize cfg(not(no_num_nonzero_signed)), deserialize_i64 + isize, NonZeroIsize, deserialize_i64 num_as_self!(i8:visit_i8 i16:visit_i16); int_to_int!(i32:visit_i32 i64:visit_i64); uint_to_self!(u8:visit_u8 u16:visit_u16 u32:visit_u32 u64:visit_u64); @@ -528,7 +527,7 @@ macro_rules! num_128 { } impl_deserialize_num! { - i128, NonZeroI128 cfg(not(no_num_nonzero_signed)), deserialize_i128 + i128, NonZeroI128, deserialize_i128 num_self!(i128:visit_i128); num_as_self!(i8:visit_i8 i16:visit_i16 i32:visit_i32 i64:visit_i64); num_as_self!(u8:visit_u8 u16:visit_u16 u32:visit_u32 u64:visit_u64); @@ -2415,13 +2414,9 @@ impl<'de> Deserialize<'de> for SystemTime { const FIELDS: &[&str] = &["secs_since_epoch", "nanos_since_epoch"]; let duration = tri!(deserializer.deserialize_struct("SystemTime", FIELDS, DurationVisitor)); - #[cfg(not(no_systemtime_checked_add))] - let ret = UNIX_EPOCH + UNIX_EPOCH .checked_add(duration) - .ok_or_else(|| D::Error::custom("overflow deserializing SystemTime")); - #[cfg(no_systemtime_checked_add)] - let ret = Ok(UNIX_EPOCH + duration); - ret + .ok_or_else(|| D::Error::custom("overflow deserializing SystemTime")) } } diff --git a/serde/src/private/mod.rs b/serde/src/private/mod.rs index 177f8501..f1207c8a 100644 --- a/serde/src/private/mod.rs +++ b/serde/src/private/mod.rs @@ -20,7 +20,6 @@ pub use self::string::from_utf8_lossy; #[cfg(any(feature = "alloc", feature = "std"))] pub use crate::lib::{ToString, Vec}; -#[cfg(not(no_core_try_from))] pub use crate::lib::convert::TryFrom; mod string { diff --git a/serde/src/ser/impls.rs b/serde/src/ser/impls.rs index fb574eae..8bbb244a 100644 --- a/serde/src/ser/impls.rs +++ b/serde/src/ser/impls.rs @@ -185,11 +185,10 @@ where } } -#[cfg(not(no_relaxed_trait_bounds))] macro_rules! seq_impl { ( $(#[$attr:meta])* - $ty:ident + $ty:ident ) => { $(#[$attr])* impl Serialize for $ty @@ -207,45 +206,22 @@ macro_rules! seq_impl { } } -#[cfg(no_relaxed_trait_bounds)] -macro_rules! seq_impl { - ( - $(#[$attr:meta])* - $ty:ident - ) => { - $(#[$attr])* - impl Serialize for $ty - where - T: Serialize $(+ $tbound1 $(+ $tbound2)*)*, - $($typaram: $bound,)* - { - #[inline] - fn serialize(&self, serializer: S) -> Result - where - S: Serializer, - { - serializer.collect_seq(self) - } - } - } +seq_impl! { + #[cfg(any(feature = "std", feature = "alloc"))] + #[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))] + BinaryHeap } seq_impl! { #[cfg(any(feature = "std", feature = "alloc"))] #[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))] - BinaryHeap -} - -seq_impl! { - #[cfg(any(feature = "std", feature = "alloc"))] - #[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))] - BTreeSet + BTreeSet } seq_impl! { #[cfg(feature = "std")] #[cfg_attr(docsrs, doc(cfg(feature = "std")))] - HashSet + HashSet } seq_impl! { @@ -445,7 +421,6 @@ tuple_impls! { //////////////////////////////////////////////////////////////////////////////// -#[cfg(not(no_relaxed_trait_bounds))] macro_rules! map_impl { ( $(#[$attr:meta])* @@ -468,30 +443,6 @@ macro_rules! map_impl { } } -#[cfg(no_relaxed_trait_bounds)] -macro_rules! map_impl { - ( - $(#[$attr:meta])* - $ty:ident - ) => { - $(#[$attr])* - impl Serialize for $ty - where - K: Serialize $(+ $kbound1 $(+ $kbound2)*)*, - V: Serialize, - $($typaram: $bound,)* - { - #[inline] - fn serialize(&self, serializer: S) -> Result - where - S: Serializer, - { - serializer.collect_map(self) - } - } - } -} - map_impl! { #[cfg(any(feature = "std", feature = "alloc"))] #[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))] @@ -640,7 +591,6 @@ nonzero_integers! { NonZeroUsize, } -#[cfg(not(no_num_nonzero_signed))] nonzero_integers! { NonZeroI8, NonZeroI16, diff --git a/serde/src/std_error.rs b/serde/src/std_error.rs index f15a4d74..e026ace1 100644 --- a/serde/src/std_error.rs +++ b/serde/src/std_error.rs @@ -42,7 +42,7 @@ use crate::lib::{Debug, Display}; /// ``` pub trait Error: Debug + Display { /// The underlying cause of this error, if any. - fn source(&self) -> Option<&(Error + 'static)> { + fn source(&self) -> Option<&(dyn Error + 'static)> { None } }