Skip to content
Myr

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

Before adoption: this commit came in with the history the project adopted, so no landing records it.

MSRV (1.56) and edition (2021) bump

authored by David Tolnay · committed by GitHub · parents 49d098d, 8b0e95b · Browse files · 15 files+55 added−150 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

15 files+55 added−150 removed

  • other:+55 added−150 removed

15 files+55 added−150 removed

modified:.github/workflows/ci.yml+2 added-11 removed
modified:serde/src/de/impls.rs+34 added-48 removed
78 unmodified lines
7980////////////////////////////////////////////////////////////////////////////////8182macro_rules! impl_deserialize_num {83 ($primitive:ident, $nonzero:ident $(cfg($($cfg:tt)*))*, $deserialize:ident $($method:ident!($($val:ident : $visit:ident)*);)*) => {83 ($primitive:ident, $nonzero:ident, $deserialize:ident $($method:ident!($($val:ident : $visit:ident)*);)*) => {84 impl_deserialize_num!($primitive, $deserialize $($method!($($val : $visit)*);)*);8586 $(#[cfg($($cfg)*)])*86 impl<'de> Deserialize<'de> for num::$nonzero {87 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>88 where89 D: Deserializer<'de>,
136 unmodified lines
226 fn $visit<E>(self, v: $ty) -> Result<Self::Value, E>227 where228 E: Error,229 {231 #[cfg(any(no_float_copysign, not(feature = "std")))]230 #[cfg(not(feature = "std"))]231 {232 Ok(v as Self::Value)233 }234236 #[cfg(all(not(no_float_copysign), feature = "std"))]235 #[cfg(feature = "std")]236 {237 // Preserve sign of NaN. The `as` produces a nondeterministic sign.238 let sign = if v.is_sign_positive() { 1.0 } else { -1.0 };239 Ok((v as Self::Value).copysign(sign))
8 unmodified lines
248 fn $visit<E>(self, v: $ty) -> Result<Self::Value, E>249 where250 E: Error,251 {253 if Self::Value::min_value() as i64 <= v as i64254 && v as i64 <= Self::Value::max_value() as i64255 {256 Ok(v as Self::Value)257 } else {258 Err(Error::invalid_value(Unexpected::Signed(v as i64), &self))259 }252 Self::Value::try_from(v as i64)253 .map_err(|_| Error::invalid_value(Unexpected::Signed(v as i64), &self))254 }255 };256257 (nonzero $primitive:ident $ty:ident : $visit:ident) => {258 fn $visit<E>(self, v: $ty) -> Result<Self::Value, E>259 where260 E: Error,261 {268 if $primitive::min_value() as i64 <= v as i64269 && v as i64 <= $primitive::max_value() as i64270 {271 if let Some(nonzero) = Self::Value::new(v as $primitive) {262 if let Ok(v) = $primitive::try_from(v as i64) {263 if let Some(nonzero) = Self::Value::new(v) {264 return Ok(nonzero);265 }266 }267 Err(Error::invalid_value(Unexpected::Signed(v as i64), &self))
22 unmodified lines
290 fn $visit<E>(self, v: $ty) -> Result<Self::Value, E>291 where292 E: Error,293 {302 if 0 <= v && v as u64 <= Self::Value::max_value() as u64 {303 Ok(v as Self::Value)304 } else {305 Err(Error::invalid_value(Unexpected::Signed(v as i64), &self))294 if 0 <= v {295 #[allow(irrefutable_let_patterns)]296 if let Ok(v) = Self::Value::try_from(v as u64) {297 return Ok(v as Self::Value);298 }299 }300 Err(Error::invalid_value(Unexpected::Signed(v as i64), &self))301 }302 };303304 (nonzero $primitive:ident $ty:ident : $visit:ident) => {305 fn $visit<E>(self, v: $ty) -> Result<Self::Value, E>306 where307 E: Error,308 {309 if 0 < v {310 #[allow(irrefutable_let_patterns)]315 if 0 < v && v as u64 <= $primitive::max_value() as u64 {316 if let Some(nonzero) = Self::Value::new(v as $primitive) {317 return Ok(nonzero);311 if let Ok(v) = $primitive::try_from(v as u64) {312 if let Some(nonzero) = Self::Value::new(v) {313 return Ok(nonzero);314 }315 }316 }317 Err(Error::invalid_value(Unexpected::Signed(v as i64), &self))318 }
21 unmodified lines
340 fn $visit<E>(self, v: $ty) -> Result<Self::Value, E>341 where342 E: Error,343 {347 if v as u64 <= Self::Value::max_value() as u64 {348 Ok(v as Self::Value)349 } else {350 Err(Error::invalid_value(Unexpected::Unsigned(v as u64), &self))351 }344 Self::Value::try_from(v as u64)345 .map_err(|_| Error::invalid_value(Unexpected::Unsigned(v as u64), &self))346 }347 };348349 (nonzero $primitive:ident $ty:ident : $visit:ident) => {350 fn $visit<E>(self, v: $ty) -> Result<Self::Value, E>351 where352 E: Error,353 {360 if v as u64 <= $primitive::max_value() as u64 {361 if let Some(nonzero) = Self::Value::new(v as $primitive) {354 if let Ok(v) = $primitive::try_from(v as u64) {355 if let Some(nonzero) = Self::Value::new(v) {356 return Ok(nonzero);357 }358 }359 Err(Error::invalid_value(Unexpected::Unsigned(v as u64), &self))
4 unmodified lines
364 fn $visit<E>(self, v: $ty) -> Result<Self::Value, E>365 where366 E: Error,367 {374 if v as u64 <= $primitive::MAX as u64 {368 if let Ok(v) = $primitive::try_from(v as u64) {369 Ok(Saturating(v as $primitive))370 } else {371 Ok(Saturating($primitive::MAX))372 }
1 unmodified line
374 };375}376377impl_deserialize_num! {384 i8, NonZeroI8 cfg(not(no_num_nonzero_signed)), deserialize_i8378 i8, NonZeroI8, deserialize_i8379 num_self!(i8:visit_i8);380 int_to_int!(i16:visit_i16 i32:visit_i32 i64:visit_i64);381 uint_to_self!(u8:visit_u8 u16:visit_u16 u32:visit_u32 u64:visit_u64);382}383384impl_deserialize_num! {391 i16, NonZeroI16 cfg(not(no_num_nonzero_signed)), deserialize_i16385 i16, NonZeroI16, deserialize_i16386 num_self!(i16:visit_i16);387 num_as_self!(i8:visit_i8);388 int_to_int!(i32:visit_i32 i64:visit_i64);389 uint_to_self!(u8:visit_u8 u16:visit_u16 u32:visit_u32 u64:visit_u64);390}391392impl_deserialize_num! {399 i32, NonZeroI32 cfg(not(no_num_nonzero_signed)), deserialize_i32393 i32, NonZeroI32, deserialize_i32394 num_self!(i32:visit_i32);395 num_as_self!(i8:visit_i8 i16:visit_i16);396 int_to_int!(i64:visit_i64);397 uint_to_self!(u8:visit_u8 u16:visit_u16 u32:visit_u32 u64:visit_u64);398}399400impl_deserialize_num! {407 i64, NonZeroI64 cfg(not(no_num_nonzero_signed)), deserialize_i64401 i64, NonZeroI64, deserialize_i64402 num_self!(i64:visit_i64);403 num_as_self!(i8:visit_i8 i16:visit_i16 i32:visit_i32);404 uint_to_self!(u8:visit_u8 u16:visit_u16 u32:visit_u32 u64:visit_u64);405}406407impl_deserialize_num! {414 isize, NonZeroIsize cfg(not(no_num_nonzero_signed)), deserialize_i64408 isize, NonZeroIsize, deserialize_i64409 num_as_self!(i8:visit_i8 i16:visit_i16);410 int_to_int!(i32:visit_i32 i64:visit_i64);411 uint_to_self!(u8:visit_u8 u16:visit_u16 u32:visit_u32 u64:visit_u64);412}
56 unmodified lines
469 fn $visit<E>(self, v: $ty) -> Result<Self::Value, E>470 where471 E: Error,472 {479 if v as i128 >= Self::Value::min_value() as i128480 && v as u128 <= Self::Value::max_value() as u128481 {473 if v as i128 >= Self::Value::MIN as i128 && v as u128 <= Self::Value::MAX as u128 {474 Ok(v as Self::Value)475 } else {476 Err(Error::invalid_value(477 Unexpected::Other(stringify!($ty)),
7 unmodified lines
485 fn $visit<E>(self, v: $ty) -> Result<Self::Value, E>486 where487 E: Error,488 {497 if v as i128 >= $primitive::min_value() as i128498 && v as u128 <= $primitive::max_value() as u128499 {489 if v as i128 >= $primitive::MIN as i128 && v as u128 <= $primitive::MAX as u128 {490 if let Some(nonzero) = Self::Value::new(v as $primitive) {491 Ok(nonzero)492 } else {493 Err(Error::invalid_value(Unexpected::Unsigned(0), &self))
23 unmodified lines
517 };518}519520impl_deserialize_num! {531 i128, NonZeroI128 cfg(not(no_num_nonzero_signed)), deserialize_i128521 i128, NonZeroI128, deserialize_i128522 num_self!(i128:visit_i128);523 num_as_self!(i8:visit_i8 i16:visit_i16 i32:visit_i32 i64:visit_i64);524 num_as_self!(u8:visit_u8 u16:visit_u16 u32:visit_u32 u64:visit_u64);525 num_128!(u128:visit_u128);
1878 unmodified lines
2404 }24052406 const FIELDS: &[&str] = &["secs_since_epoch", "nanos_since_epoch"];2407 let duration = tri!(deserializer.deserialize_struct("SystemTime", FIELDS, DurationVisitor));2418 #[cfg(not(no_systemtime_checked_add))]2419 let ret = UNIX_EPOCH2408 UNIX_EPOCH2409 .checked_add(duration)2421 .ok_or_else(|| D::Error::custom("overflow deserializing SystemTime"));2422 #[cfg(no_systemtime_checked_add)]2423 let ret = Ok(UNIX_EPOCH + duration);2424 ret2410 .ok_or_else(|| D::Error::custom("overflow deserializing SystemTime"))2411 }2412}24132414////////////////////////////////////////////////////////////////////////////////
755 unmodified lines
modified:serde/src/de/mod.rs+4 added-4 removed
204 unmodified lines
205 /// For example if we try to deserialize a String out of a JSON file206 /// containing an integer, the unexpected type is the integer and the207 /// expected type is the string.208 #[cold]209 fn invalid_type(unexp: Unexpected, exp: &Expected) -> Self {209 fn invalid_type(unexp: Unexpected, exp: &dyn Expected) -> Self {210 Error::custom(format_args!("invalid type: {}, expected {}", unexp, exp))211 }212213 /// Raised when a `Deserialize` receives a value of the right type but that
9 unmodified lines
223 /// For example if we try to deserialize a String out of some binary data224 /// that is not valid UTF-8, the unexpected value is the bytes and the225 /// expected value is a string.226 #[cold]227 fn invalid_value(unexp: Unexpected, exp: &Expected) -> Self {227 fn invalid_value(unexp: Unexpected, exp: &dyn Expected) -> Self {228 Error::custom(format_args!("invalid value: {}, expected {}", unexp, exp))229 }230231 /// Raised when deserializing a sequence or map and the input data contains
5 unmodified lines
237 /// The `exp` argument provides information about what data was being238 /// expected. For example `exp` might say that a tuple of size 6 was239 /// expected.240 #[cold]241 fn invalid_length(len: usize, exp: &Expected) -> Self {241 fn invalid_length(len: usize, exp: &dyn Expected) -> Self {242 Error::custom(format_args!("invalid length {}, expected {}", len, exp))243 }244245 /// Raised when a `Deserialize` enum type received a variant with an
245 unmodified lines
491 formatter.write_str(self)492 }493}494495impl Display for Expected + '_ {495impl Display for dyn Expected + '_ {496 fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {497 Expected::fmt(self, formatter)498 }499}
1836 unmodified lines
modified:serde/src/de/size_hint.rs+1 added
1#[cfg(any(feature = "std", feature = "alloc"))]2use crate::lib::*;34pub fn from_bounds<I>(iter: &I) -> Option<usize>5where
25 unmodified lines
modified:serde/src/private/de.rs+2 added-2 removed
1063 unmodified lines
1064 where1065 E: de::Error,1066 {1067 #[cold]1068 fn invalid_type(self, exp: &Expected) -> E {1068 fn invalid_type(self, exp: &dyn Expected) -> E {1069 de::Error::invalid_type(self.content.unexpected(), exp)1070 }10711072 fn deserialize_integer<V>(self, visitor: V) -> Result<V::Value, E>
580 unmodified lines
1653 where1654 E: de::Error,1655 {1656 #[cold]1657 fn invalid_type(self, exp: &Expected) -> E {1657 fn invalid_type(self, exp: &dyn Expected) -> E {1658 de::Error::invalid_type(self.content.unexpected(), exp)1659 }16601661 fn deserialize_integer<V>(self, visitor: V) -> Result<V::Value, E>
1143 unmodified lines
modified:serde/src/private/mod.rs-1 removed
18 unmodified lines
1920#[cfg(any(feature = "alloc", feature = "std"))]21pub use crate::lib::{ToString, Vec};2223#[cfg(not(no_core_try_from))]23pub use crate::lib::convert::TryFrom;2425mod string {26 use crate::lib::*;
21 unmodified lines
modified:serde/src/ser/impls.rs+4 added-54 removed
183 unmodified lines
184 serializer.collect_seq(self)185 }186}187188#[cfg(not(no_relaxed_trait_bounds))]188macro_rules! seq_impl {189 (190 $(#[$attr:meta])*192 $ty:ident <T $(: $tbound1:ident $(+ $tbound2:ident)*)* $(, $typaram:ident : $bound:ident)*>191 $ty:ident <T $(, $typaram:ident : $bound:ident)*>192 ) => {193 $(#[$attr])*194 impl<T $(, $typaram)*> Serialize for $ty<T $(, $typaram)*>195 where
9 unmodified lines
205 }206 }207}208210#[cfg(no_relaxed_trait_bounds)]211macro_rules! seq_impl {212 (213 $(#[$attr:meta])*214 $ty:ident <T $(: $tbound1:ident $(+ $tbound2:ident)*)* $(, $typaram:ident : $bound:ident)*>215 ) => {216 $(#[$attr])*217 impl<T $(, $typaram)*> Serialize for $ty<T $(, $typaram)*>218 where219 T: Serialize $(+ $tbound1 $(+ $tbound2)*)*,220 $($typaram: $bound,)*221 {222 #[inline]223 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>224 where225 S: Serializer,226 {227 serializer.collect_seq(self)228 }229 }230 }231}232209seq_impl! {210 #[cfg(any(feature = "std", feature = "alloc"))]211 #[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]236 BinaryHeap<T: Ord>212 BinaryHeap<T>213}214215seq_impl! {216 #[cfg(any(feature = "std", feature = "alloc"))]217 #[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]242 BTreeSet<T: Ord>218 BTreeSet<T>219}220221seq_impl! {222 #[cfg(feature = "std")]223 #[cfg_attr(docsrs, doc(cfg(feature = "std")))]248 HashSet<T: Eq + Hash, H: BuildHasher>224 HashSet<T, H: BuildHasher>225}226227seq_impl! {228 #[cfg(any(feature = "std", feature = "alloc"))]
191 unmodified lines
420}421422////////////////////////////////////////////////////////////////////////////////423448#[cfg(not(no_relaxed_trait_bounds))]424macro_rules! map_impl {425 (426 $(#[$attr:meta])*427 $ty:ident <K $(: $kbound1:ident $(+ $kbound2:ident)*)*, V $(, $typaram:ident : $bound:ident)*>
14 unmodified lines
442 }443 }444}445471#[cfg(no_relaxed_trait_bounds)]472macro_rules! map_impl {473 (474 $(#[$attr:meta])*475 $ty:ident <K $(: $kbound1:ident $(+ $kbound2:ident)*)*, V $(, $typaram:ident : $bound:ident)*>476 ) => {477 $(#[$attr])*478 impl<K, V $(, $typaram)*> Serialize for $ty<K, V $(, $typaram)*>479 where480 K: Serialize $(+ $kbound1 $(+ $kbound2)*)*,481 V: Serialize,482 $($typaram: $bound,)*483 {484 #[inline]485 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>486 where487 S: Serializer,488 {489 serializer.collect_map(self)490 }491 }492 }493}494446map_impl! {447 #[cfg(any(feature = "std", feature = "alloc"))]448 #[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]449 BTreeMap<K: Ord, V>
140 unmodified lines
590 NonZeroU128,591 NonZeroUsize,592}593643#[cfg(not(no_num_nonzero_signed))]594nonzero_integers! {595 NonZeroI8,596 NonZeroI16,597 NonZeroI32,
449 unmodified lines
modified:serde/src/lib.rs-2 removed
173 unmodified lines
174 pub use std::*;175 }176177 pub use self::core::{f32, f64};178 pub use self::core::{i16, i32, i64, i8, isize};178 pub use self::core::{iter, num, ptr, str};180 pub use self::core::{u16, u32, u64, u8, usize};179180 #[cfg(any(feature = "std", feature = "alloc"))]181 pub use self::core::{cmp, mem, slice};182
165 unmodified lines
modified:serde/src/std_error.rs+1 added-1 removed
40 unmodified lines
41/// impl serde::ser::StdError for MySerError {}42/// ```43pub trait Error: Debug + Display {44 /// The underlying cause of this error, if any.45 fn source(&self) -> Option<&(Error + 'static)> {45 fn source(&self) -> Option<&(dyn Error + 'static)> {46 None47 }48}
modified:serde/build.rs-21 removed
16 unmodified lines
17 println!("cargo:rustc-check-cfg=cfg(no_core_cstr)");18 println!("cargo:rustc-check-cfg=cfg(no_core_error)");19 println!("cargo:rustc-check-cfg=cfg(no_core_net)");20 println!("cargo:rustc-check-cfg=cfg(no_core_num_saturating)");21 println!("cargo:rustc-check-cfg=cfg(no_core_try_from)");21 println!("cargo:rustc-check-cfg=cfg(no_diagnostic_namespace)");22 println!("cargo:rustc-check-cfg=cfg(no_float_copysign)");24 println!("cargo:rustc-check-cfg=cfg(no_num_nonzero_signed)");25 println!("cargo:rustc-check-cfg=cfg(no_relaxed_trait_bounds)");23 println!("cargo:rustc-check-cfg=cfg(no_serde_derive)");24 println!("cargo:rustc-check-cfg=cfg(no_std_atomic)");25 println!("cargo:rustc-check-cfg=cfg(no_std_atomic64)");29 println!("cargo:rustc-check-cfg=cfg(no_systemtime_checked_add)");26 println!("cargo:rustc-check-cfg=cfg(no_target_has_atomic)");27 }2829 let target = env::var("TARGET").unwrap();30 let emscripten = target == "asmjs-unknown-emscripten" || target == "wasm32-unknown-emscripten";3136 // TryFrom, Atomic types, non-zero signed integers, and SystemTime::checked_add37 // stabilized in Rust 1.34:38 // https://blog.rust-lang.org/2019/04/11/Rust-1.34.0.html#tryfrom-and-tryinto39 // https://blog.rust-lang.org/2019/04/11/Rust-1.34.0.html#library-stabilizations40 if minor < 34 {41 println!("cargo:rustc-cfg=no_core_try_from");42 println!("cargo:rustc-cfg=no_num_nonzero_signed");43 println!("cargo:rustc-cfg=no_systemtime_checked_add");44 println!("cargo:rustc-cfg=no_relaxed_trait_bounds");45 }4647 // f32::copysign and f64::copysign stabilized in Rust 1.35.48 // https://blog.rust-lang.org/2019/05/23/Rust-1.35.0.html#copy-the-sign-of-a-floating-point-number-onto-another49 if minor < 35 {50 println!("cargo:rustc-cfg=no_float_copysign");51 }5232 // Support for #[cfg(target_has_atomic = "...")] stabilized in Rust 1.60.33 if minor < 60 {34 println!("cargo:rustc-cfg=no_target_has_atomic");35 // Allowlist of archs that support std::sync::atomic module. This is
63 unmodified lines
modified:serde/Cargo.toml+2 added-2 removed
4 unmodified lines
5build = "build.rs"6categories = ["encoding", "no-std", "no-std::no-alloc"]7description = "A generic serialization/deserialization framework"8documentation = "https://docs.rs/serde"9edition = "2018"9edition = "2021"10homepage = "https://serde.rs"11keywords = ["serde", "serialization", "no_std"]12license = "MIT OR Apache-2.0"13readme = "crates-io.md"14repository = "https://github.com/serde-rs/serde"15rust-version = "1.31"15rust-version = "1.56"1617[dependencies]18serde_derive = { version = "1", optional = true, path = "../serde_derive" }19
52 unmodified lines
modified:serde_derive/Cargo.toml+1 added-1 removed
3 unmodified lines
4authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"]5categories = ["no-std", "no-std::no-alloc"]6description = "Macros 1.1 implementation of #[derive(Serialize, Deserialize)]"7documentation = "https://serde.rs/derive.html"8edition = "2015"8edition = "2021"9exclude = ["build.rs"]10homepage = "https://serde.rs"11keywords = ["serde", "serialization", "no_std", "derive"]12license = "MIT OR Apache-2.0"
29 unmodified lines
modified:serde_derive_internals/Cargo.toml+1 added-1 removed
2 unmodified lines
3version = "0.29.1"4authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"]5description = "AST representation used by Serde derive macros. Unstable."6documentation = "https://docs.rs/serde_derive_internals"7edition = "2015"7edition = "2021"8exclude = ["build.rs"]9homepage = "https://serde.rs"10keywords = ["serde", "serialization"]11license = "MIT OR Apache-2.0"
20 unmodified lines
modified:Cargo.toml+1 added
3 unmodified lines
4 "serde_derive",5 "serde_derive_internals",6 "test_suite",7]8resolver = "2"910[patch.crates-io]11serde = { path = "serde" }12
4 unmodified lines
modified:README.md+2 added-2 removed
1# Serde &emsp; [![Build Status]][actions] [![Latest Version]][crates.io] [![serde msrv]][Rust 1.31] [![serde_derive msrv]][Rust 1.61]1# Serde &emsp; [![Build Status]][actions] [![Latest Version]][crates.io] [![serde msrv]][Rust 1.56] [![serde_derive msrv]][Rust 1.61]23[Build Status]: https://img.shields.io/github/actions/workflow/status/serde-rs/serde/ci.yml?branch=master4[actions]: https://github.com/serde-rs/serde/actions?query=branch%3Amaster5[Latest Version]: https://img.shields.io/crates/v/serde.svg6[crates.io]: https://crates.io/crates/serde7[serde msrv]: https://img.shields.io/crates/msrv/serde.svg?label=serde%20msrv&color=lightgray8[serde_derive msrv]: https://img.shields.io/crates/msrv/serde_derive.svg?label=serde_derive%20msrv&color=lightgray9[Rust 1.31]: https://blog.rust-lang.org/2018/12/06/Rust-1.31-and-rust-2018.html9[Rust 1.56]: https://blog.rust-lang.org/2021/10/21/Rust-1.56.0.html10[Rust 1.61]: https://blog.rust-lang.org/2022/05/19/Rust-1.61.0.html1112**Serde is a framework for *ser*ializing and *de*serializing Rust data structures efficiently and generically.**13
101 unmodified lines