Merge pull request #2901 from serde-rs/msrv-and-edition-bump

MSRV (1.56) and edition (2021) bump
This commit is contained in:
David Tolnay
2025-03-09 15:37:44 -04:00
committed by GitHub
15 changed files with 58 additions and 153 deletions
+2 -11
View File
@@ -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
+1
View File
@@ -5,6 +5,7 @@ members = [
"serde_derive_internals",
"test_suite",
]
resolver = "2"
[patch.crates-io]
serde = { path = "serde" }
+2 -2
View File
@@ -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.**
+2 -2
View File
@@ -6,13 +6,13 @@ build = "build.rs"
categories = ["encoding", "no-std", "no-std::no-alloc"]
description = "A generic serialization/deserialization framework"
documentation = "https://docs.rs/serde"
edition = "2018"
edition = "2021"
homepage = "https://serde.rs"
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" }
-21
View File
@@ -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");
+34 -48
View File
@@ -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<D>(deserializer: D) -> Result<Self, D::Error>
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 };
@@ -250,13 +249,8 @@ macro_rules! int_to_int {
where
E: Error,
{
if Self::Value::min_value() as i64 <= v as i64
&& v as i64 <= Self::Value::max_value() as i64
{
Ok(v as Self::Value)
} else {
Err(Error::invalid_value(Unexpected::Signed(v as i64), &self))
}
Self::Value::try_from(v as i64)
.map_err(|_| Error::invalid_value(Unexpected::Signed(v as i64), &self))
}
};
@@ -265,10 +259,8 @@ macro_rules! int_to_int {
where
E: Error,
{
if $primitive::min_value() as i64 <= v as i64
&& v as i64 <= $primitive::max_value() as i64
{
if let Some(nonzero) = Self::Value::new(v as $primitive) {
if let Ok(v) = $primitive::try_from(v as i64) {
if let Some(nonzero) = Self::Value::new(v) {
return Ok(nonzero);
}
}
@@ -299,11 +291,13 @@ macro_rules! int_to_uint {
where
E: Error,
{
if 0 <= v && v as u64 <= Self::Value::max_value() as u64 {
Ok(v as Self::Value)
} else {
Err(Error::invalid_value(Unexpected::Signed(v as i64), &self))
if 0 <= v {
#[allow(irrefutable_let_patterns)]
if let Ok(v) = Self::Value::try_from(v as u64) {
return Ok(v as Self::Value);
}
}
Err(Error::invalid_value(Unexpected::Signed(v as i64), &self))
}
};
@@ -312,9 +306,12 @@ macro_rules! int_to_uint {
where
E: Error,
{
if 0 < v && v as u64 <= $primitive::max_value() as u64 {
if let Some(nonzero) = Self::Value::new(v as $primitive) {
return Ok(nonzero);
if 0 < v {
#[allow(irrefutable_let_patterns)]
if let Ok(v) = $primitive::try_from(v as u64) {
if let Some(nonzero) = Self::Value::new(v) {
return Ok(nonzero);
}
}
}
Err(Error::invalid_value(Unexpected::Signed(v as i64), &self))
@@ -344,11 +341,8 @@ macro_rules! uint_to_self {
where
E: Error,
{
if v as u64 <= Self::Value::max_value() as u64 {
Ok(v as Self::Value)
} else {
Err(Error::invalid_value(Unexpected::Unsigned(v as u64), &self))
}
Self::Value::try_from(v as u64)
.map_err(|_| Error::invalid_value(Unexpected::Unsigned(v as u64), &self))
}
};
@@ -357,8 +351,8 @@ macro_rules! uint_to_self {
where
E: Error,
{
if v as u64 <= $primitive::max_value() as u64 {
if let Some(nonzero) = Self::Value::new(v as $primitive) {
if let Ok(v) = $primitive::try_from(v as u64) {
if let Some(nonzero) = Self::Value::new(v) {
return Ok(nonzero);
}
}
@@ -371,7 +365,7 @@ macro_rules! uint_to_self {
where
E: Error,
{
if v as u64 <= $primitive::MAX as u64 {
if let Ok(v) = $primitive::try_from(v as u64) {
Ok(Saturating(v as $primitive))
} else {
Ok(Saturating($primitive::MAX))
@@ -381,14 +375,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 +390,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 +398,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);
@@ -476,9 +470,7 @@ macro_rules! num_128 {
where
E: Error,
{
if v as i128 >= Self::Value::min_value() as i128
&& v as u128 <= Self::Value::max_value() as u128
{
if v as i128 >= Self::Value::MIN as i128 && v as u128 <= Self::Value::MAX as u128 {
Ok(v as Self::Value)
} else {
Err(Error::invalid_value(
@@ -494,9 +486,7 @@ macro_rules! num_128 {
where
E: Error,
{
if v as i128 >= $primitive::min_value() as i128
&& v as u128 <= $primitive::max_value() as u128
{
if v as i128 >= $primitive::MIN as i128 && v as u128 <= $primitive::MAX as u128 {
if let Some(nonzero) = Self::Value::new(v as $primitive) {
Ok(nonzero)
} else {
@@ -528,7 +518,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 +2405,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"))
}
}
+4 -4
View File
@@ -206,7 +206,7 @@ macro_rules! declare_error_trait {
/// containing an integer, the unexpected type is the integer and the
/// expected type is the string.
#[cold]
fn invalid_type(unexp: Unexpected, exp: &Expected) -> Self {
fn invalid_type(unexp: Unexpected, exp: &dyn Expected) -> Self {
Error::custom(format_args!("invalid type: {}, expected {}", unexp, exp))
}
@@ -224,7 +224,7 @@ macro_rules! declare_error_trait {
/// that is not valid UTF-8, the unexpected value is the bytes and the
/// expected value is a string.
#[cold]
fn invalid_value(unexp: Unexpected, exp: &Expected) -> Self {
fn invalid_value(unexp: Unexpected, exp: &dyn Expected) -> Self {
Error::custom(format_args!("invalid value: {}, expected {}", unexp, exp))
}
@@ -238,7 +238,7 @@ macro_rules! declare_error_trait {
/// expected. For example `exp` might say that a tuple of size 6 was
/// expected.
#[cold]
fn invalid_length(len: usize, exp: &Expected) -> Self {
fn invalid_length(len: usize, exp: &dyn Expected) -> Self {
Error::custom(format_args!("invalid length {}, expected {}", len, exp))
}
@@ -492,7 +492,7 @@ impl Expected for &str {
}
}
impl Display for Expected + '_ {
impl Display for dyn Expected + '_ {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
Expected::fmt(self, formatter)
}
+1
View File
@@ -1,3 +1,4 @@
#[cfg(any(feature = "std", feature = "alloc"))]
use crate::lib::*;
pub fn from_bounds<I>(iter: &I) -> Option<usize>
-2
View File
@@ -175,9 +175,7 @@ mod lib {
}
pub use self::core::{f32, f64};
pub use self::core::{i16, i32, i64, i8, isize};
pub use self::core::{iter, num, ptr, str};
pub use self::core::{u16, u32, u64, u8, usize};
#[cfg(any(feature = "std", feature = "alloc"))]
pub use self::core::{cmp, mem, slice};
+2 -2
View File
@@ -1065,7 +1065,7 @@ mod content {
E: de::Error,
{
#[cold]
fn invalid_type(self, exp: &Expected) -> E {
fn invalid_type(self, exp: &dyn Expected) -> E {
de::Error::invalid_type(self.content.unexpected(), exp)
}
@@ -1654,7 +1654,7 @@ mod content {
E: de::Error,
{
#[cold]
fn invalid_type(self, exp: &Expected) -> E {
fn invalid_type(self, exp: &dyn Expected) -> E {
de::Error::invalid_type(self.content.unexpected(), exp)
}
-1
View File
@@ -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 {
+7 -57
View File
@@ -185,11 +185,10 @@ where
}
}
#[cfg(not(no_relaxed_trait_bounds))]
macro_rules! seq_impl {
(
$(#[$attr:meta])*
$ty:ident <T $(: $tbound1:ident $(+ $tbound2:ident)*)* $(, $typaram:ident : $bound:ident)*>
$ty:ident <T $(, $typaram:ident : $bound:ident)*>
) => {
$(#[$attr])*
impl<T $(, $typaram)*> Serialize for $ty<T $(, $typaram)*>
@@ -207,45 +206,22 @@ macro_rules! seq_impl {
}
}
#[cfg(no_relaxed_trait_bounds)]
macro_rules! seq_impl {
(
$(#[$attr:meta])*
$ty:ident <T $(: $tbound1:ident $(+ $tbound2:ident)*)* $(, $typaram:ident : $bound:ident)*>
) => {
$(#[$attr])*
impl<T $(, $typaram)*> Serialize for $ty<T $(, $typaram)*>
where
T: Serialize $(+ $tbound1 $(+ $tbound2)*)*,
$($typaram: $bound,)*
{
#[inline]
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
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<T>
}
seq_impl! {
#[cfg(any(feature = "std", feature = "alloc"))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
BinaryHeap<T: Ord>
}
seq_impl! {
#[cfg(any(feature = "std", feature = "alloc"))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
BTreeSet<T: Ord>
BTreeSet<T>
}
seq_impl! {
#[cfg(feature = "std")]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
HashSet<T: Eq + Hash, H: BuildHasher>
HashSet<T, H: BuildHasher>
}
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 <K $(: $kbound1:ident $(+ $kbound2:ident)*)*, V $(, $typaram:ident : $bound:ident)*>
) => {
$(#[$attr])*
impl<K, V $(, $typaram)*> Serialize for $ty<K, V $(, $typaram)*>
where
K: Serialize $(+ $kbound1 $(+ $kbound2)*)*,
V: Serialize,
$($typaram: $bound,)*
{
#[inline]
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
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,
+1 -1
View File
@@ -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
}
}
+1 -1
View File
@@ -5,7 +5,7 @@ authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay
categories = ["no-std", "no-std::no-alloc"]
description = "Macros 1.1 implementation of #[derive(Serialize, Deserialize)]"
documentation = "https://serde.rs/derive.html"
edition = "2015"
edition = "2021"
exclude = ["build.rs"]
homepage = "https://serde.rs"
keywords = ["serde", "serialization", "no_std", "derive"]
+1 -1
View File
@@ -4,7 +4,7 @@ version = "0.29.1"
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"]
description = "AST representation used by Serde derive macros. Unstable."
documentation = "https://docs.rs/serde_derive_internals"
edition = "2015"
edition = "2021"
exclude = ["build.rs"]
homepage = "https://serde.rs"
keywords = ["serde", "serialization"]