Skip to content

Commit da0b473

Browse files
authored
Merge pull request #2901 from serde-rs/msrv-and-edition-bump
MSRV (1.56) and edition (2021) bump
2 parents 49d098d + 8b0e95b commit da0b473

File tree

15 files changed

+55
-150
lines changed

15 files changed

+55
-150
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ jobs:
8484
strategy:
8585
fail-fast: false
8686
matrix:
87-
rust: [1.31.0, 1.34.0]
87+
rust: [1.56.0, 1.60.0]
8888
timeout-minutes: 45
8989
steps:
9090
- uses: actions/checkout@v4
@@ -94,6 +94,7 @@ jobs:
9494
- run: sed -i '/"test_suite"/d' Cargo.toml
9595
- run: cd serde && cargo build --features rc
9696
- run: cd serde && cargo build --no-default-features
97+
- run: cd serde && cargo build --no-default-features --features alloc
9798
- run: cd serde && cargo build
9899

99100
derive:
@@ -111,16 +112,6 @@ jobs:
111112
- run: cd serde && cargo check
112113
- run: cd serde_derive && cargo check
113114

114-
alloc:
115-
name: Rust 1.36.0
116-
runs-on: ubuntu-latest
117-
timeout-minutes: 45
118-
steps:
119-
- uses: actions/checkout@v4
120-
- uses: dtolnay/[email protected]
121-
- run: sed -i '/"test_suite"/d' Cargo.toml
122-
- run: cd serde && cargo build --no-default-features --features alloc
123-
124115
minimal:
125116
name: Minimal versions
126117
runs-on: ubuntu-latest

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ members = [
55
"serde_derive_internals",
66
"test_suite",
77
]
8+
resolver = "2"
89

910
[patch.crates-io]
1011
serde = { path = "serde" }

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
# Serde   [![Build Status]][actions] [![Latest Version]][crates.io] [![serde msrv]][Rust 1.31] [![serde_derive msrv]][Rust 1.61]
1+
# Serde   [![Build Status]][actions] [![Latest Version]][crates.io] [![serde msrv]][Rust 1.56] [![serde_derive msrv]][Rust 1.61]
22

33
[Build Status]: https://img.shields.io/github/actions/workflow/status/serde-rs/serde/ci.yml?branch=master
44
[actions]: https://github.com/serde-rs/serde/actions?query=branch%3Amaster
55
[Latest Version]: https://img.shields.io/crates/v/serde.svg
66
[crates.io]: https://crates.io/crates/serde
77
[serde msrv]: https://img.shields.io/crates/msrv/serde.svg?label=serde%20msrv&color=lightgray
88
[serde_derive msrv]: https://img.shields.io/crates/msrv/serde_derive.svg?label=serde_derive%20msrv&color=lightgray
9-
[Rust 1.31]: https://blog.rust-lang.org/2018/12/06/Rust-1.31-and-rust-2018.html
9+
[Rust 1.56]: https://blog.rust-lang.org/2021/10/21/Rust-1.56.0.html
1010
[Rust 1.61]: https://blog.rust-lang.org/2022/05/19/Rust-1.61.0.html
1111

1212
**Serde is a framework for *ser*ializing and *de*serializing Rust data structures efficiently and generically.**

serde/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ build = "build.rs"
66
categories = ["encoding", "no-std", "no-std::no-alloc"]
77
description = "A generic serialization/deserialization framework"
88
documentation = "https://docs.rs/serde"
9-
edition = "2018"
9+
edition = "2021"
1010
homepage = "https://serde.rs"
1111
keywords = ["serde", "serialization", "no_std"]
1212
license = "MIT OR Apache-2.0"
1313
readme = "crates-io.md"
1414
repository = "https://github.com/serde-rs/serde"
15-
rust-version = "1.31"
15+
rust-version = "1.56"
1616

1717
[dependencies]
1818
serde_derive = { version = "1", optional = true, path = "../serde_derive" }

serde/build.rs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,38 +18,17 @@ fn main() {
1818
println!("cargo:rustc-check-cfg=cfg(no_core_error)");
1919
println!("cargo:rustc-check-cfg=cfg(no_core_net)");
2020
println!("cargo:rustc-check-cfg=cfg(no_core_num_saturating)");
21-
println!("cargo:rustc-check-cfg=cfg(no_core_try_from)");
2221
println!("cargo:rustc-check-cfg=cfg(no_diagnostic_namespace)");
2322
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)");
2623
println!("cargo:rustc-check-cfg=cfg(no_serde_derive)");
2724
println!("cargo:rustc-check-cfg=cfg(no_std_atomic)");
2825
println!("cargo:rustc-check-cfg=cfg(no_std_atomic64)");
29-
println!("cargo:rustc-check-cfg=cfg(no_systemtime_checked_add)");
3026
println!("cargo:rustc-check-cfg=cfg(no_target_has_atomic)");
3127
}
3228

3329
let target = env::var("TARGET").unwrap();
3430
let emscripten = target == "asmjs-unknown-emscripten" || target == "wasm32-unknown-emscripten";
3531

36-
// TryFrom, Atomic types, non-zero signed integers, and SystemTime::checked_add
37-
// stabilized in Rust 1.34:
38-
// https://blog.rust-lang.org/2019/04/11/Rust-1.34.0.html#tryfrom-and-tryinto
39-
// https://blog.rust-lang.org/2019/04/11/Rust-1.34.0.html#library-stabilizations
40-
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-
}
46-
47-
// 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-another
49-
if minor < 35 {
50-
println!("cargo:rustc-cfg=no_float_copysign");
51-
}
52-
5332
// Support for #[cfg(target_has_atomic = "...")] stabilized in Rust 1.60.
5433
if minor < 60 {
5534
println!("cargo:rustc-cfg=no_target_has_atomic");

serde/src/de/impls.rs

Lines changed: 34 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,9 @@ impl<'de> Deserialize<'de> for bool {
8080
////////////////////////////////////////////////////////////////////////////////
8181

8282
macro_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)*);)*) => {
8484
impl_deserialize_num!($primitive, $deserialize $($method!($($val : $visit)*);)*);
8585

86-
$(#[cfg($($cfg)*)])*
8786
impl<'de> Deserialize<'de> for num::$nonzero {
8887
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
8988
where
@@ -228,12 +227,12 @@ macro_rules! num_as_copysign_self {
228227
where
229228
E: Error,
230229
{
231-
#[cfg(any(no_float_copysign, not(feature = "std")))]
230+
#[cfg(not(feature = "std"))]
232231
{
233232
Ok(v as Self::Value)
234233
}
235234

236-
#[cfg(all(not(no_float_copysign), feature = "std"))]
235+
#[cfg(feature = "std")]
237236
{
238237
// Preserve sign of NaN. The `as` produces a nondeterministic sign.
239238
let sign = if v.is_sign_positive() { 1.0 } else { -1.0 };
@@ -250,13 +249,8 @@ macro_rules! int_to_int {
250249
where
251250
E: Error,
252251
{
253-
if Self::Value::min_value() as i64 <= v as i64
254-
&& v as i64 <= Self::Value::max_value() as i64
255-
{
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))
260254
}
261255
};
262256

@@ -265,10 +259,8 @@ macro_rules! int_to_int {
265259
where
266260
E: Error,
267261
{
268-
if $primitive::min_value() as i64 <= v as i64
269-
&& v as i64 <= $primitive::max_value() as i64
270-
{
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) {
272264
return Ok(nonzero);
273265
}
274266
}
@@ -299,11 +291,13 @@ macro_rules! int_to_uint {
299291
where
300292
E: Error,
301293
{
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+
}
306299
}
300+
Err(Error::invalid_value(Unexpected::Signed(v as i64), &self))
307301
}
308302
};
309303

@@ -312,9 +306,12 @@ macro_rules! int_to_uint {
312306
where
313307
E: Error,
314308
{
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);
309+
if 0 < v {
310+
#[allow(irrefutable_let_patterns)]
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+
}
318315
}
319316
}
320317
Err(Error::invalid_value(Unexpected::Signed(v as i64), &self))
@@ -344,11 +341,8 @@ macro_rules! uint_to_self {
344341
where
345342
E: Error,
346343
{
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))
352346
}
353347
};
354348

@@ -357,8 +351,8 @@ macro_rules! uint_to_self {
357351
where
358352
E: Error,
359353
{
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) {
362356
return Ok(nonzero);
363357
}
364358
}
@@ -371,7 +365,7 @@ macro_rules! uint_to_self {
371365
where
372366
E: Error,
373367
{
374-
if v as u64 <= $primitive::MAX as u64 {
368+
if let Ok(v) = $primitive::try_from(v as u64) {
375369
Ok(Saturating(v as $primitive))
376370
} else {
377371
Ok(Saturating($primitive::MAX))
@@ -381,37 +375,37 @@ macro_rules! uint_to_self {
381375
}
382376

383377
impl_deserialize_num! {
384-
i8, NonZeroI8 cfg(not(no_num_nonzero_signed)), deserialize_i8
378+
i8, NonZeroI8, deserialize_i8
385379
num_self!(i8:visit_i8);
386380
int_to_int!(i16:visit_i16 i32:visit_i32 i64:visit_i64);
387381
uint_to_self!(u8:visit_u8 u16:visit_u16 u32:visit_u32 u64:visit_u64);
388382
}
389383

390384
impl_deserialize_num! {
391-
i16, NonZeroI16 cfg(not(no_num_nonzero_signed)), deserialize_i16
385+
i16, NonZeroI16, deserialize_i16
392386
num_self!(i16:visit_i16);
393387
num_as_self!(i8:visit_i8);
394388
int_to_int!(i32:visit_i32 i64:visit_i64);
395389
uint_to_self!(u8:visit_u8 u16:visit_u16 u32:visit_u32 u64:visit_u64);
396390
}
397391

398392
impl_deserialize_num! {
399-
i32, NonZeroI32 cfg(not(no_num_nonzero_signed)), deserialize_i32
393+
i32, NonZeroI32, deserialize_i32
400394
num_self!(i32:visit_i32);
401395
num_as_self!(i8:visit_i8 i16:visit_i16);
402396
int_to_int!(i64:visit_i64);
403397
uint_to_self!(u8:visit_u8 u16:visit_u16 u32:visit_u32 u64:visit_u64);
404398
}
405399

406400
impl_deserialize_num! {
407-
i64, NonZeroI64 cfg(not(no_num_nonzero_signed)), deserialize_i64
401+
i64, NonZeroI64, deserialize_i64
408402
num_self!(i64:visit_i64);
409403
num_as_self!(i8:visit_i8 i16:visit_i16 i32:visit_i32);
410404
uint_to_self!(u8:visit_u8 u16:visit_u16 u32:visit_u32 u64:visit_u64);
411405
}
412406

413407
impl_deserialize_num! {
414-
isize, NonZeroIsize cfg(not(no_num_nonzero_signed)), deserialize_i64
408+
isize, NonZeroIsize, deserialize_i64
415409
num_as_self!(i8:visit_i8 i16:visit_i16);
416410
int_to_int!(i32:visit_i32 i64:visit_i64);
417411
uint_to_self!(u8:visit_u8 u16:visit_u16 u32:visit_u32 u64:visit_u64);
@@ -476,9 +470,7 @@ macro_rules! num_128 {
476470
where
477471
E: Error,
478472
{
479-
if v as i128 >= Self::Value::min_value() as i128
480-
&& v as u128 <= Self::Value::max_value() as u128
481-
{
473+
if v as i128 >= Self::Value::MIN as i128 && v as u128 <= Self::Value::MAX as u128 {
482474
Ok(v as Self::Value)
483475
} else {
484476
Err(Error::invalid_value(
@@ -494,9 +486,7 @@ macro_rules! num_128 {
494486
where
495487
E: Error,
496488
{
497-
if v as i128 >= $primitive::min_value() as i128
498-
&& v as u128 <= $primitive::max_value() as u128
499-
{
489+
if v as i128 >= $primitive::MIN as i128 && v as u128 <= $primitive::MAX as u128 {
500490
if let Some(nonzero) = Self::Value::new(v as $primitive) {
501491
Ok(nonzero)
502492
} else {
@@ -528,7 +518,7 @@ macro_rules! num_128 {
528518
}
529519

530520
impl_deserialize_num! {
531-
i128, NonZeroI128 cfg(not(no_num_nonzero_signed)), deserialize_i128
521+
i128, NonZeroI128, deserialize_i128
532522
num_self!(i128:visit_i128);
533523
num_as_self!(i8:visit_i8 i16:visit_i16 i32:visit_i32 i64:visit_i64);
534524
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 {
24152405

24162406
const FIELDS: &[&str] = &["secs_since_epoch", "nanos_since_epoch"];
24172407
let duration = tri!(deserializer.deserialize_struct("SystemTime", FIELDS, DurationVisitor));
2418-
#[cfg(not(no_systemtime_checked_add))]
2419-
let ret = UNIX_EPOCH
2408+
UNIX_EPOCH
24202409
.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-
ret
2410+
.ok_or_else(|| D::Error::custom("overflow deserializing SystemTime"))
24252411
}
24262412
}
24272413

serde/src/de/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ macro_rules! declare_error_trait {
206206
/// containing an integer, the unexpected type is the integer and the
207207
/// expected type is the string.
208208
#[cold]
209-
fn invalid_type(unexp: Unexpected, exp: &Expected) -> Self {
209+
fn invalid_type(unexp: Unexpected, exp: &dyn Expected) -> Self {
210210
Error::custom(format_args!("invalid type: {}, expected {}", unexp, exp))
211211
}
212212

@@ -224,7 +224,7 @@ macro_rules! declare_error_trait {
224224
/// that is not valid UTF-8, the unexpected value is the bytes and the
225225
/// expected value is a string.
226226
#[cold]
227-
fn invalid_value(unexp: Unexpected, exp: &Expected) -> Self {
227+
fn invalid_value(unexp: Unexpected, exp: &dyn Expected) -> Self {
228228
Error::custom(format_args!("invalid value: {}, expected {}", unexp, exp))
229229
}
230230

@@ -238,7 +238,7 @@ macro_rules! declare_error_trait {
238238
/// expected. For example `exp` might say that a tuple of size 6 was
239239
/// expected.
240240
#[cold]
241-
fn invalid_length(len: usize, exp: &Expected) -> Self {
241+
fn invalid_length(len: usize, exp: &dyn Expected) -> Self {
242242
Error::custom(format_args!("invalid length {}, expected {}", len, exp))
243243
}
244244

@@ -492,7 +492,7 @@ impl Expected for &str {
492492
}
493493
}
494494

495-
impl Display for Expected + '_ {
495+
impl Display for dyn Expected + '_ {
496496
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
497497
Expected::fmt(self, formatter)
498498
}

serde/src/de/size_hint.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#[cfg(any(feature = "std", feature = "alloc"))]
12
use crate::lib::*;
23

34
pub fn from_bounds<I>(iter: &I) -> Option<usize>

serde/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,7 @@ mod lib {
175175
}
176176

177177
pub use self::core::{f32, f64};
178-
pub use self::core::{i16, i32, i64, i8, isize};
179178
pub use self::core::{iter, num, ptr, str};
180-
pub use self::core::{u16, u32, u64, u8, usize};
181179

182180
#[cfg(any(feature = "std", feature = "alloc"))]
183181
pub use self::core::{cmp, mem, slice};

serde/src/private/de.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,7 +1065,7 @@ mod content {
10651065
E: de::Error,
10661066
{
10671067
#[cold]
1068-
fn invalid_type(self, exp: &Expected) -> E {
1068+
fn invalid_type(self, exp: &dyn Expected) -> E {
10691069
de::Error::invalid_type(self.content.unexpected(), exp)
10701070
}
10711071

@@ -1654,7 +1654,7 @@ mod content {
16541654
E: de::Error,
16551655
{
16561656
#[cold]
1657-
fn invalid_type(self, exp: &Expected) -> E {
1657+
fn invalid_type(self, exp: &dyn Expected) -> E {
16581658
de::Error::invalid_type(self.content.unexpected(), exp)
16591659
}
16601660

0 commit comments

Comments
 (0)