Compare commits

...

30 Commits

Author SHA1 Message Date
pezkuwichain c0bdb88b70 fix: extern crate alloc when alloc feature active AND (no_std OR wasm32v1-none target) 2026-04-23 03:29:47 +03:00
pezkuwichain 5d546231a1 fix: guard extern crate alloc with not(feature="std") to prevent E0152 in std test builds 2026-04-23 02:04:49 +03:00
pezkuwichain 0a75fdd839 fix: remove duplicate prelude imports causing wasm32v1-none ambiguity
The redundant `use ::core::prelude::rust_2021::*;` was causing
ambiguity errors because `crate::lib::*` already imports `Some`,
`None`, `Option` via `crate_root.rs`.

This fixes cargo clippy/check failures on wasm32 targets.

Files fixed:
- serde_core/src/de/mod.rs
- serde_core/src/de/impls.rs
- serde_core/src/ser/mod.rs
- serde_core/src/ser/impls.rs
- serde_core/src/ser/fmt.rs
- serde_core/src/ser/impossible.rs
- serde_core/src/private/doc.rs
2026-01-24 19:15:40 +03:00
pezkuwichain c03215db8d Add no_std attribute and extern crate core for wasm32v1-none 2026-01-09 16:33:08 +03:00
pezkuwichain 877abfe00e Fix serde crate_root macro for wasm32v1-none target 2026-01-09 16:31:09 +03:00
pezkuwichain a155b33847 Add write macro import to de.rs 2026-01-09 16:24:16 +03:00
pezkuwichain 10dc33548a Add prelude imports to nested content modules 2026-01-09 16:11:14 +03:00
pezkuwichain ee2259c972 Add prelude imports to serde/src/private modules 2026-01-09 15:57:47 +03:00
pezkuwichain 0084743f82 Fix copysign macro for target_os=none 2026-01-09 15:48:30 +03:00
pezkuwichain 679af0fb4b Fix wasm32v1-none target compilation with Cargo feature unification
When building for wasm32v1-none with Cargo, the 'std' feature gets
unified across the dependency graph, meaning serde_core sees
feature="std" even on a no_std target. This caused compilation failures
because the crate tried to use std:: imports.

This commit fixes the issue by checking target_os = "none" in addition
to the std feature flag:
- lib.rs: Force no_std when target_os = "none"
- crate_root.rs: Use core/alloc instead of std on target_os = "none"
- All std-only cfg blocks now include not(target_os = "none")
- Add explicit prelude imports for wasm32v1-none compatibility
2026-01-09 15:36:51 +03:00
pezkuwichain d99c876120 fix: add explicit prelude imports for wasm32v1-none no_std + alloc
When building serde_core for wasm32v1-none target with no_std but with
the alloc feature enabled, the Rust compiler doesn't automatically inject
the prelude. This causes ?Sized bounds to fail with "bound modifier ?
can only be applied to Sized" errors.

This commit adds explicit prelude imports to all modules that:
1. Use `use crate::lib::*;` for serde's internal lib facade
2. Use `?Sized` bounds in their code

The fix adds:
```rust
#[allow(unused_imports)]
#[cfg(not(feature = "std"))]
use ::core::prelude::rust_2021::*;
```

This ensures Sized, Clone, Copy, and other prelude traits are in scope
for the ?Sized syntax to work correctly on wasm32v1-none targets.

Affected files:
- serde_core/src/de/impls.rs
- serde_core/src/de/mod.rs
- serde_core/src/private/doc.rs
- serde_core/src/ser/fmt.rs
- serde_core/src/ser/impls.rs
- serde_core/src/ser/impossible.rs
- serde_core/src/ser/mod.rs

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-09 13:21:34 +03:00
pezkuwichain 7ce49dc38b fix: add explicit prelude exports for wasm32v1-none target
wasm32v1-none target does not automatically inject prelude items like
Sized, Clone, Copy, etc. into scope. This commit:

- Uses fully qualified paths (::core, ::std) to avoid ambiguity with
  internal `mod core` shadowing
- Explicitly re-exports rust_2021 prelude items
- Adds explicit imports for essential prelude traits: Sized, Clone,
  Copy, Send, Sync, Unpin, Default, Eq, Ord, PartialEq, PartialOrd,
  Iterator traits, and Fn traits
- Adds `extern crate core;` for no_std targets in lib.rs

This fixes compilation errors like "relaxing a default bound only does
something for ?Sized" when building for wasm32v1-none target.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-09 12:44:12 +03:00
David Tolnay d17902059e Merge pull request #3019 from xibeiyoumian/master
chore: improve code comments clarity
2025-12-22 03:29:10 -08:00
xibeiyoumian a27948e209 chore: improve code comments clarity
Signed-off-by: xibeiyoumian <xibeiyoumian@outlook.com>
2025-12-22 14:38:55 +08:00
David Tolnay 576e2ef9d8 Update actions/upload-artifact@v5 -> v6 2025-12-19 21:10:59 -08:00
David Tolnay dd0eb0f2ca Update actions/upload-artifact@v4 -> v5 2025-12-18 18:58:13 -08:00
David Tolnay f7fc3e0d67 Update actions/checkout@v5 -> v6 2025-11-20 10:19:51 -08:00
David Tolnay 1c396d223b Update actions/checkout@v4 -> v5 2025-11-20 10:19:04 -08:00
David Tolnay e42684f9a7 Update ui test suite to nightly-2025-11-02 2025-11-01 22:38:40 -07:00
David Tolnay 56c29b3c5d Update name of empty_enum clippy lint
warning: lint `clippy::empty_enum` has been renamed to `clippy::empty_enums`
       --> serde/src/lib.rs:122:5
        |
    122 |     clippy::empty_enum,
        |     ^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::empty_enums`
        |
        = note: `#[warn(renamed_and_removed_lints)]` on by default

    warning: lint `clippy::empty_enum` has been renamed to `clippy::empty_enums`
      --> serde_core/src/lib.rs:57:5
       |
    57 |     clippy::empty_enum,
       |     ^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::empty_enums`
       |
       = note: `#[warn(renamed_and_removed_lints)]` on by default

    warning: lint `clippy::empty_enum` has been renamed to `clippy::empty_enums`
     --> test_suite/tests/test_de.rs:5:5
      |
    5 |     clippy::empty_enum,
      |     ^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::empty_enums`
      |
      = note: `#[warn(renamed_and_removed_lints)]` on by default

    warning: lint `clippy::empty_enum` has been renamed to `clippy::empty_enums`
     --> test_suite/tests/test_de_error.rs:3:5
      |
    3 |     clippy::empty_enum,
      |     ^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::empty_enums`
      |
      = note: `#[warn(renamed_and_removed_lints)]` on by default
2025-11-01 22:37:05 -07:00
David Tolnay 5a44519a9a Raise required compiler for serde_derive to Rust 1.68 2025-10-19 15:02:17 -07:00
David Tolnay fae23fea97 Resolve manual_let_else pedantic clippy lint
warning: this could be rewritten as `let...else`
        --> serde_derive/src/internals/attr.rs:1460:5
         |
    1460 | /     let string = match get_lit_str(cx, attr_name, meta)? {
    1461 | |         Some(string) => string,
    1462 | |         None => return Ok(None),
    1463 | |     };
         | |______^ help: consider writing: `let Some(string) = get_lit_str(cx, attr_name, meta)? else { return Ok(None) };`
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_let_else
         = note: `-W clippy::manual-let-else` implied by `-W clippy::pedantic`
         = help: to override `-W clippy::pedantic` add `#[allow(clippy::manual_let_else)]`

    warning: this could be rewritten as `let...else`
        --> serde_derive/src/internals/attr.rs:1482:5
         |
    1482 | /     let string = match get_lit_str(cx, attr_name, meta)? {
    1483 | |         Some(string) => string,
    1484 | |         None => return Ok(None),
    1485 | |     };
         | |______^ help: consider writing: `let Some(string) = get_lit_str(cx, attr_name, meta)? else { return Ok(None) };`
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_let_else

    warning: this could be rewritten as `let...else`
        --> serde_derive/src/internals/attr.rs:1505:5
         |
    1505 | /     let string = match get_lit_str2(cx, attr_name, meta_item_name, meta)? {
    1506 | |         Some(string) => string,
    1507 | |         None => return Ok(Vec::new()),
    1508 | |     };
         | |______^ help: consider writing: `let Some(string) = get_lit_str2(cx, attr_name, meta_item_name, meta)? else { return Ok(Vec::new()) };`
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_let_else

    warning: this could be rewritten as `let...else`
        --> serde_derive/src/internals/attr.rs:1526:5
         |
    1526 | /     let string = match get_lit_str(cx, attr_name, meta)? {
    1527 | |         Some(string) => string,
    1528 | |         None => return Ok(None),
    1529 | |     };
         | |______^ help: consider writing: `let Some(string) = get_lit_str(cx, attr_name, meta)? else { return Ok(None) };`
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_let_else

    warning: this could be rewritten as `let...else`
        --> serde_derive/src/internals/attr.rs:1549:5
         |
    1549 | /     let string = match get_lit_str(cx, BORROW, meta)? {
    1550 | |         Some(string) => string,
    1551 | |         None => return Ok(BTreeSet::new()),
    1552 | |     };
         | |______^ help: consider writing: `let Some(string) = get_lit_str(cx, BORROW, meta)? else { return Ok(BTreeSet::new()) };`
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_let_else

    warning: this could be rewritten as `let...else`
        --> serde_derive/src/internals/attr.rs:1621:5
         |
    1621 | /     let seg = match path.segments.last() {
    1622 | |         Some(seg) => seg,
    1623 | |         None => {
    1624 | |             return false;
    1625 | |         }
    1626 | |     };
         | |______^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_let_else
    help: consider writing
         |
    1621 ~     let Some(seg) = path.segments.last() else {
    1622 +             return false;
    1623 +         };
         |

    warning: this could be rewritten as `let...else`
        --> serde_derive/src/internals/attr.rs:1648:5
         |
    1648 | /     let seg = match path.segments.last() {
    1649 | |         Some(seg) => seg,
    1650 | |         None => {
    1651 | |             return false;
    1652 | |         }
    1653 | |     };
         | |______^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_let_else
    help: consider writing
         |
    1648 ~     let Some(seg) = path.segments.last() else {
    1649 +             return false;
    1650 +         };
         |

    warning: this could be rewritten as `let...else`
      --> serde_derive/src/internals/ctxt.rs:49:9
       |
    49 | /         let mut combined = match errors.next() {
    50 | |             Some(first) => first,
    51 | |             None => return Ok(()),
    52 | |         };
       | |__________^ help: consider writing: `let Some(mut combined) = errors.next() else { return Ok(()) };`
       |
       = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_let_else

    warning: this could be rewritten as `let...else`
      --> serde_derive/src/de.rs:29:5
       |
    29 | /     let cont = match Container::from_ast(&ctxt, input, Derive::Deserialize, &private...
    30 | |         Some(cont) => cont,
    31 | |         None => return Err(ctxt.check().unwrap_err()),
    32 | |     };
       | |______^ help: consider writing: `let Some(cont) = Container::from_ast(&ctxt, input, Derive::Deserialize, &private.ident()) else { return Err(ctxt.check().unwrap_err()) };`
       |
       = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_let_else

    warning: this could be rewritten as `let...else`
      --> serde_derive/src/ser.rs:16:5
       |
    16 | /     let cont = match Container::from_ast(&ctxt, input, Derive::Serialize, &private.i...
    17 | |         Some(cont) => cont,
    18 | |         None => return Err(ctxt.check().unwrap_err()),
    19 | |     };
       | |______^ help: consider writing: `let Some(cont) = Container::from_ast(&ctxt, input, Derive::Serialize, &private.ident()) else { return Err(ctxt.check().unwrap_err()) };`
       |
       = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_let_else
2025-10-19 15:02:16 -07:00
David Tolnay d656b4dd6a Raise required compiler for serde_derive to Rust 1.65 2025-10-19 15:02:12 -07:00
David Tolnay b517ec9fd7 Merge pull request #3001 from nik-contrib/refactor
refactor: remove 1 level of nesting
2025-10-17 10:35:18 -07:00
Nik Revenco 086353c581 refactor: remove 1 level of nesting 2025-10-17 18:29:26 +01:00
David Tolnay 4e278703c6 Merge pull request #2936 from Mingun/remove-fixme
Remove some ? from generated code
2025-09-28 11:34:47 -07:00
Mingun 9f9a1ea35e Do not use ? operator in the generated code where possible
This may slightly improve compilation time and costs nothing
2025-09-28 23:21:26 +05:00
David Tolnay a866b336f1 Release 1.0.228 2025-09-27 09:51:07 -07:00
David Tolnay 5adc9e816c Merge pull request #2995 from dtolnay/rustdocflags
Workaround for RUSTDOCFLAGS='--cfg=docsrs'
2025-09-27 09:50:33 -07:00
David Tolnay ab581789f4 Workaround for RUSTDOCFLAGS='--cfg=docsrs' 2025-09-27 09:46:14 -07:00
32 changed files with 307 additions and 209 deletions
+14 -14
View File
@@ -18,10 +18,10 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 45
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6
- uses: dtolnay/rust-toolchain@nightly
- run: cd test_suite && cargo test --features unstable
- uses: actions/upload-artifact@v4
- uses: actions/upload-artifact@v6
if: always()
with:
name: Cargo.lock
@@ -33,7 +33,7 @@ jobs:
runs-on: windows-latest
timeout-minutes: 45
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6
- uses: dtolnay/rust-toolchain@nightly
- run: cd test_suite && cargo test --features unstable -- --skip ui --exact
@@ -46,7 +46,7 @@ jobs:
rust: [stable, beta]
timeout-minutes: 45
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{matrix.rust}}
@@ -63,7 +63,7 @@ jobs:
os: [ubuntu, windows]
timeout-minutes: 45
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6
- uses: dtolnay/rust-toolchain@nightly
- run: cd serde && cargo build
- run: cd serde && cargo build --no-default-features
@@ -87,7 +87,7 @@ jobs:
rust: [1.56.0, 1.60.0]
timeout-minutes: 45
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{matrix.rust}}
@@ -98,12 +98,12 @@ jobs:
- run: cd serde && cargo build
derive:
name: Rust 1.61.0
name: Rust 1.68.0
runs-on: ubuntu-latest
timeout-minutes: 45
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@1.61.0
- uses: actions/checkout@v6
- uses: dtolnay/rust-toolchain@1.68.0
- run: |
sed -i 's/proc-macro2 = { workspace = true/proc-macro2 = { version = "1"/' serde_derive*/Cargo.toml
sed -i 's/quote = { workspace = true/quote = { version = "1"/' serde_derive*/Cargo.toml
@@ -117,7 +117,7 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 45
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6
- uses: dtolnay/rust-toolchain@nightly
- run: cargo generate-lockfile -Z minimal-versions
- run: cargo check --locked --workspace
@@ -129,7 +129,7 @@ jobs:
env:
RUSTDOCFLAGS: -Dwarnings
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6
- uses: dtolnay/rust-toolchain@nightly
- uses: dtolnay/install@cargo-docs-rs
- run: cargo docs-rs -p serde
@@ -143,7 +143,7 @@ jobs:
if: github.event_name != 'pull_request'
timeout-minutes: 45
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6
- uses: dtolnay/rust-toolchain@clippy
- run: cd serde && cargo clippy --features rc,unstable -- -Dclippy::all -Dclippy::pedantic
- run: cd serde_core && cargo clippy --features rc,unstable -- -Dclippy::all -Dclippy::pedantic
@@ -157,7 +157,7 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 45
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6
- uses: dtolnay/rust-toolchain@miri
with:
toolchain: nightly-2025-05-16 # https://github.com/rust-lang/miri/issues/4323
@@ -175,7 +175,7 @@ jobs:
if: github.event_name != 'pull_request'
timeout-minutes: 45
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6
- uses: dtolnay/rust-toolchain@stable
- uses: dtolnay/install@cargo-outdated
- run: cargo outdated --workspace --exit-code 1
+3 -3
View File
@@ -1,4 +1,4 @@
# Serde &emsp; [![Build Status]][actions] [![Latest Version]][crates.io] [![serde msrv]][Rust 1.56] [![serde_derive msrv]][Rust 1.61]
# Serde &emsp; [![Build Status]][actions] [![Latest Version]][crates.io] [![serde msrv]][Rust 1.56] [![serde_derive msrv]][Rust 1.68]
[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,8 +6,8 @@
[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.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
[Rust 1.56]: https://blog.rust-lang.org/2021/10/21/Rust-1.56.0/
[Rust 1.68]: https://blog.rust-lang.org/2023/03/09/Rust-1.68.0/
**Serde is a framework for *ser*ializing and *de*serializing Rust data structures efficiently and generically.**
+2 -2
View File
@@ -1,6 +1,6 @@
[package]
name = "serde"
version = "1.0.227"
version = "1.0.228"
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"]
build = "build.rs"
categories = ["encoding", "no-std", "no-std::no-alloc"]
@@ -15,7 +15,7 @@ repository = "https://github.com/serde-rs/serde"
rust-version = "1.56"
[dependencies]
serde_core = { version = "=1.0.227", path = "../serde_core", default-features = false, features = ["result"] }
serde_core = { version = "=1.0.228", path = "../serde_core", default-features = false, features = ["result"] }
serde_derive = { version = "1", optional = true, path = "../serde_derive" }
[package.metadata.playground]
+4 -6
View File
@@ -19,9 +19,7 @@ use serde_core::__private$$ as serde_core_private;
fn main() {
println!("cargo:rerun-if-changed=build.rs");
if env::var_os("DOCS_RS").is_some() {
println!("cargo:rustc-cfg=no_serde_core");
}
println!("cargo:rustc-cfg=if_docsrs_then_no_serde_core");
let out_dir = PathBuf::from(env::var_os("OUT_DIR").unwrap());
let patch_version = env::var("CARGO_PKG_VERSION_PATCH").unwrap();
@@ -35,20 +33,20 @@ fn main() {
if minor >= 77 {
println!("cargo:rustc-check-cfg=cfg(feature, values(\"result\"))");
println!("cargo:rustc-check-cfg=cfg(if_docsrs_then_no_serde_core)");
println!("cargo:rustc-check-cfg=cfg(no_core_cstr)");
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_diagnostic_namespace)");
println!("cargo:rustc-check-cfg=cfg(no_serde_core)");
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_target_has_atomic)");
}
// Current minimum supported version of serde_derive crate is Rust 1.61.
if minor < 61 {
// Current minimum supported version of serde_derive crate is Rust 1.68.
if minor < 68 {
println!("cargo:rustc-cfg=no_serde_derive");
}
+41 -15
View File
@@ -95,9 +95,11 @@
////////////////////////////////////////////////////////////////////////////////
// Serde types in rustdoc of other crates get linked to here.
#![doc(html_root_url = "https://docs.rs/serde/1.0.227")]
#![doc(html_root_url = "https://docs.rs/serde/1.0.228")]
// Support using Serde without the standard library!
#![cfg_attr(not(feature = "std"), no_std)]
// Also force no_std on target_os = "none" (wasm32v1-none) even if std feature is enabled
// This handles Cargo feature unification where std gets enabled for no_std targets
#![cfg_attr(any(not(feature = "std"), target_os = "none"), no_std)]
// Show which crate feature enables conditionally compiled APIs in documentation.
#![cfg_attr(docsrs, feature(doc_cfg, rustdoc_internals))]
#![cfg_attr(docsrs, allow(internal_features))]
@@ -119,7 +121,7 @@
// clippy bug: https://github.com/rust-lang/rust-clippy/issues/7768
clippy::semicolon_if_nothing_returned,
// not available in our oldest supported compiler
clippy::empty_enum,
clippy::empty_enums,
clippy::type_repetition_in_bounds, // https://github.com/rust-lang/rust-clippy/issues/8772
// integer and float ser/de requires these sorts of casts
clippy::cast_possible_truncation,
@@ -168,6 +170,10 @@
#[cfg(feature = "alloc")]
extern crate alloc;
// Explicitly import core crate for no_std targets (especially wasm32v1-none)
#[cfg(any(not(feature = "std"), target_os = "none"))]
extern crate core;
// Rustdoc has a lot of shortcomings related to cross-crate re-exports that make
// the rendered documentation of serde_core traits in serde more challenging to
// understand than the equivalent documentation of the same items in serde_core.
@@ -190,14 +196,34 @@ macro_rules! crate_root {
/// A facade around all the types we need from the `std`, `core`, and `alloc`
/// crates. This avoids elaborate import wrangling having to happen in every
/// module.
///
/// NOTE: On targets where std is not available (target_os = "none", e.g. wasm32v1-none),
/// we always use core/alloc even if the "std" feature is enabled due to Cargo feature
/// unification.
mod lib {
mod core {
#[cfg(not(feature = "std"))]
pub use core::*;
#[cfg(feature = "std")]
pub use std::*;
#[cfg(any(not(feature = "std"), target_os = "none"))]
pub use ::core::*;
#[cfg(all(feature = "std", not(target_os = "none")))]
pub use ::std::*;
}
// Re-export the full prelude for wasm32v1-none and other no_std targets
#[cfg(any(not(feature = "std"), target_os = "none"))]
pub use ::core::prelude::rust_2021::*;
#[cfg(all(feature = "std", not(target_os = "none")))]
pub use ::std::prelude::rust_2021::*;
// Prelude items that may not be re-exported by glob import
#[cfg(any(not(feature = "std"), target_os = "none"))]
pub use ::core::option::Option::{self, None, Some};
#[cfg(any(not(feature = "std"), target_os = "none"))]
pub use ::core::result::Result::{self, Err, Ok};
#[cfg(all(feature = "std", not(target_os = "none")))]
pub use ::std::option::Option::{self, None, Some};
#[cfg(all(feature = "std", not(target_os = "none")))]
pub use ::std::result::Result::{self, Err, Ok};
pub use self::core::{f32, f64};
pub use self::core::{ptr, str};
@@ -212,24 +238,24 @@ macro_rules! crate_root {
pub use self::core::option;
pub use self::core::result;
#[cfg(all(feature = "alloc", not(feature = "std")))]
#[cfg(all(feature = "alloc", any(not(feature = "std"), target_os = "none")))]
pub use alloc::borrow::{Cow, ToOwned};
#[cfg(feature = "std")]
#[cfg(all(feature = "std", not(target_os = "none")))]
pub use std::borrow::{Cow, ToOwned};
#[cfg(all(feature = "alloc", not(feature = "std")))]
#[cfg(all(feature = "alloc", any(not(feature = "std"), target_os = "none")))]
pub use alloc::string::{String, ToString};
#[cfg(feature = "std")]
#[cfg(all(feature = "std", not(target_os = "none")))]
pub use std::string::{String, ToString};
#[cfg(all(feature = "alloc", not(feature = "std")))]
#[cfg(all(feature = "alloc", any(not(feature = "std"), target_os = "none")))]
pub use alloc::vec::Vec;
#[cfg(feature = "std")]
#[cfg(all(feature = "std", not(target_os = "none")))]
pub use std::vec::Vec;
#[cfg(all(feature = "alloc", not(feature = "std")))]
#[cfg(all(feature = "alloc", any(not(feature = "std"), target_os = "none")))]
pub use alloc::boxed::Box;
#[cfg(feature = "std")]
#[cfg(all(feature = "std", not(target_os = "none")))]
pub use std::boxed::Box;
}
+12
View File
@@ -1,5 +1,11 @@
use crate::lib::*;
// Explicit prelude import for wasm32v1-none and other no_std targets
#[allow(unused_imports)]
use ::core::prelude::rust_2021::*;
#[allow(unused_imports)]
use ::core::write;
use crate::de::value::{BorrowedBytesDeserializer, BytesDeserializer};
use crate::de::{
Deserialize, DeserializeSeed, Deserializer, EnumAccess, Error, IntoDeserializer, VariantAccess,
@@ -212,6 +218,12 @@ mod content {
use crate::lib::*;
// Explicit prelude import for wasm32v1-none and other no_std targets
#[allow(unused_imports)]
use ::core::prelude::rust_2021::*;
#[allow(unused_imports)]
use ::core::write;
use crate::de::{
self, Deserialize, DeserializeSeed, Deserializer, EnumAccess, Expected, IgnoredAny,
MapAccess, SeqAccess, Unexpected, Visitor,
+10
View File
@@ -1,5 +1,11 @@
use crate::lib::*;
// Explicit prelude import for wasm32v1-none and other no_std targets
#[allow(unused_imports)]
use ::core::prelude::rust_2021::*;
#[allow(unused_imports)]
use ::core::write;
use crate::ser::{self, Impossible, Serialize, SerializeMap, SerializeStruct, Serializer};
#[cfg(any(feature = "std", feature = "alloc"))]
@@ -339,6 +345,10 @@ where
mod content {
use crate::lib::*;
// Explicit prelude import for wasm32v1-none and other no_std targets
#[allow(unused_imports)]
use ::core::prelude::rust_2021::*;
use crate::ser::{self, Serialize, Serializer};
pub struct SerializeTupleVariantAsMapValue<M> {
+2 -2
View File
@@ -1,6 +1,6 @@
[package]
name = "serde_core"
version = "1.0.227"
version = "1.0.228"
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"]
build = "build.rs"
categories = ["encoding", "no-std", "no-std::no-alloc"]
@@ -37,7 +37,7 @@ rustdoc-args = [
# is compatible with exactly one serde release because the generated code
# involves nonpublic APIs which are not bound by semver.
[target.'cfg(any())'.dependencies]
serde_derive = { version = "=1.0.227", path = "../serde_derive" }
serde_derive = { version = "=1.0.228", path = "../serde_derive" }
### FEATURES #################################################################
+6 -6
View File
@@ -29,12 +29,12 @@ fn main() {
};
if minor >= 77 {
println!("cargo:rustc-check-cfg=cfg(if_docsrs_then_no_serde_core)");
println!("cargo:rustc-check-cfg=cfg(no_core_cstr)");
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_diagnostic_namespace)");
println!("cargo:rustc-check-cfg=cfg(no_serde_core)");
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)");
@@ -65,17 +65,17 @@ fn main() {
}
}
// Current minimum supported version of serde_derive crate is Rust 1.61.
if minor < 61 {
println!("cargo:rustc-cfg=no_serde_derive");
}
// Support for core::ffi::CStr and alloc::ffi::CString stabilized in Rust 1.64.
// https://blog.rust-lang.org/2022/09/22/Rust-1.64.0.html#c-compatible-ffi-types-in-core-and-alloc
if minor < 64 {
println!("cargo:rustc-cfg=no_core_cstr");
}
// Current minimum supported version of serde_derive crate is Rust 1.68.
if minor < 68 {
println!("cargo:rustc-cfg=no_serde_derive");
}
// Support for core::num::Saturating and std::num::Saturating stabilized in Rust 1.74
// https://blog.rust-lang.org/2023/11/16/Rust-1.74.0.html#stabilized-apis
if minor < 74 {
+84 -47
View File
@@ -3,14 +3,37 @@ macro_rules! crate_root {
/// A facade around all the types we need from the `std`, `core`, and `alloc`
/// crates. This avoids elaborate import wrangling having to happen in every
/// module.
///
/// NOTE: On targets where std is not available (target_os = "none", e.g. wasm32v1-none),
/// we always use core/alloc even if the "std" feature is enabled due to Cargo feature
/// unification. This is handled by checking `target_os = "none"` in all cfg conditions.
mod lib {
mod core {
#[cfg(not(feature = "std"))]
pub use core::*;
#[cfg(feature = "std")]
pub use std::*;
// On wasm32v1-none (target_os = "none"), always use ::core even if std feature is enabled
// This handles Cargo feature unification where std gets enabled for no_std targets
#[cfg(any(not(feature = "std"), target_os = "none"))]
pub use ::core::*;
#[cfg(all(feature = "std", not(target_os = "none")))]
pub use ::std::*;
}
// Re-export the full prelude for wasm32v1-none and other no_std targets
// On target_os = "none", always use ::core::prelude even with std feature
#[cfg(any(not(feature = "std"), target_os = "none"))]
pub use ::core::prelude::rust_2021::*;
#[cfg(all(feature = "std", not(target_os = "none")))]
pub use ::std::prelude::rust_2021::*;
// Prelude items that may not be re-exported by glob import
#[cfg(any(not(feature = "std"), target_os = "none"))]
pub use ::core::option::Option::{self, None, Some};
#[cfg(any(not(feature = "std"), target_os = "none"))]
pub use ::core::result::Result::{self, Err, Ok};
#[cfg(all(feature = "std", not(target_os = "none")))]
pub use ::std::option::Option::{self, None, Some};
#[cfg(all(feature = "std", not(target_os = "none")))]
pub use ::std::result::Result::{self, Err, Ok};
pub use self::core::{f32, f64};
pub use self::core::{iter, num, str};
@@ -20,99 +43,110 @@ macro_rules! crate_root {
pub use self::core::cell::{Cell, RefCell};
pub use self::core::cmp::Reverse;
pub use self::core::fmt::{self, Debug, Display, Write as FmtWrite};
pub use self::core::marker::PhantomData;
pub use self::core::marker::{PhantomData, Sized};
pub use self::core::clone::Clone;
pub use self::core::marker::{Copy, Send, Sync, Unpin};
pub use self::core::default::Default;
pub use self::core::cmp::{Eq, Ord, PartialEq, PartialOrd};
pub use self::core::convert::{AsMut, AsRef, From, Into};
pub use self::core::iter::{
DoubleEndedIterator, ExactSizeIterator, Extend, IntoIterator, Iterator,
};
pub use self::core::ops::{Drop, Fn, FnMut, FnOnce};
pub use self::core::num::Wrapping;
pub use self::core::ops::{Bound, Range, RangeFrom, RangeInclusive, RangeTo};
pub use self::core::result;
pub use self::core::time::Duration;
#[cfg(all(feature = "alloc", not(feature = "std")))]
// For alloc types: use alloc when std is not available OR on target_os = "none"
#[cfg(all(feature = "alloc", any(not(feature = "std"), target_os = "none")))]
pub use alloc::borrow::{Cow, ToOwned};
#[cfg(feature = "std")]
#[cfg(all(feature = "std", not(target_os = "none")))]
pub use std::borrow::{Cow, ToOwned};
#[cfg(all(feature = "alloc", not(feature = "std")))]
#[cfg(all(feature = "alloc", any(not(feature = "std"), target_os = "none")))]
pub use alloc::string::{String, ToString};
#[cfg(feature = "std")]
#[cfg(all(feature = "std", not(target_os = "none")))]
pub use std::string::{String, ToString};
#[cfg(all(feature = "alloc", not(feature = "std")))]
#[cfg(all(feature = "alloc", any(not(feature = "std"), target_os = "none")))]
pub use alloc::vec::Vec;
#[cfg(feature = "std")]
#[cfg(all(feature = "std", not(target_os = "none")))]
pub use std::vec::Vec;
#[cfg(all(feature = "alloc", not(feature = "std")))]
#[cfg(all(feature = "alloc", any(not(feature = "std"), target_os = "none")))]
pub use alloc::boxed::Box;
#[cfg(feature = "std")]
#[cfg(all(feature = "std", not(target_os = "none")))]
pub use std::boxed::Box;
#[cfg(all(feature = "rc", feature = "alloc", not(feature = "std")))]
#[cfg(all(feature = "rc", feature = "alloc", any(not(feature = "std"), target_os = "none")))]
pub use alloc::rc::{Rc, Weak as RcWeak};
#[cfg(all(feature = "rc", feature = "std"))]
#[cfg(all(feature = "rc", feature = "std", not(target_os = "none")))]
pub use std::rc::{Rc, Weak as RcWeak};
#[cfg(all(feature = "rc", feature = "alloc", not(feature = "std")))]
#[cfg(all(feature = "rc", feature = "alloc", any(not(feature = "std"), target_os = "none")))]
pub use alloc::sync::{Arc, Weak as ArcWeak};
#[cfg(all(feature = "rc", feature = "std"))]
#[cfg(all(feature = "rc", feature = "std", not(target_os = "none")))]
pub use std::sync::{Arc, Weak as ArcWeak};
#[cfg(all(feature = "alloc", not(feature = "std")))]
#[cfg(all(feature = "alloc", any(not(feature = "std"), target_os = "none")))]
pub use alloc::collections::{BTreeMap, BTreeSet, BinaryHeap, LinkedList, VecDeque};
#[cfg(feature = "std")]
#[cfg(all(feature = "std", not(target_os = "none")))]
pub use std::collections::{BTreeMap, BTreeSet, BinaryHeap, LinkedList, VecDeque};
#[cfg(all(not(no_core_cstr), not(feature = "std")))]
#[cfg(all(not(no_core_cstr), any(not(feature = "std"), target_os = "none")))]
pub use self::core::ffi::CStr;
#[cfg(feature = "std")]
#[cfg(all(feature = "std", not(target_os = "none")))]
pub use std::ffi::CStr;
#[cfg(all(not(no_core_cstr), feature = "alloc", not(feature = "std")))]
#[cfg(all(not(no_core_cstr), feature = "alloc", any(not(feature = "std"), target_os = "none")))]
pub use alloc::ffi::CString;
#[cfg(feature = "std")]
#[cfg(all(feature = "std", not(target_os = "none")))]
pub use std::ffi::CString;
#[cfg(all(not(no_core_net), not(feature = "std")))]
#[cfg(all(not(no_core_net), any(not(feature = "std"), target_os = "none")))]
pub use self::core::net;
#[cfg(feature = "std")]
#[cfg(all(feature = "std", not(target_os = "none")))]
pub use std::net;
#[cfg(feature = "std")]
// std-only types - not available on target_os = "none"
#[cfg(all(feature = "std", not(target_os = "none")))]
pub use std::error;
#[cfg(feature = "std")]
#[cfg(all(feature = "std", not(target_os = "none")))]
pub use std::collections::{HashMap, HashSet};
#[cfg(feature = "std")]
#[cfg(all(feature = "std", not(target_os = "none")))]
pub use std::ffi::{OsStr, OsString};
#[cfg(feature = "std")]
#[cfg(all(feature = "std", not(target_os = "none")))]
pub use std::hash::{BuildHasher, Hash};
#[cfg(feature = "std")]
#[cfg(all(feature = "std", not(target_os = "none")))]
pub use std::io::Write;
#[cfg(feature = "std")]
#[cfg(all(feature = "std", not(target_os = "none")))]
pub use std::path::{Path, PathBuf};
#[cfg(feature = "std")]
#[cfg(all(feature = "std", not(target_os = "none")))]
pub use std::sync::{Mutex, RwLock};
#[cfg(feature = "std")]
#[cfg(all(feature = "std", not(target_os = "none")))]
pub use std::time::{SystemTime, UNIX_EPOCH};
#[cfg(all(feature = "std", no_target_has_atomic, not(no_std_atomic)))]
#[cfg(all(feature = "std", not(target_os = "none"), no_target_has_atomic, not(no_std_atomic)))]
pub use std::sync::atomic::{
AtomicBool, AtomicI16, AtomicI32, AtomicI8, AtomicIsize, AtomicU16, AtomicU32,
AtomicU8, AtomicUsize, Ordering,
};
#[cfg(all(feature = "std", no_target_has_atomic, not(no_std_atomic64)))]
#[cfg(all(feature = "std", not(target_os = "none"), no_target_has_atomic, not(no_std_atomic64)))]
pub use std::sync::atomic::{AtomicI64, AtomicU64};
#[cfg(all(feature = "std", not(no_target_has_atomic)))]
#[cfg(all(feature = "std", not(target_os = "none"), not(no_target_has_atomic)))]
pub use std::sync::atomic::Ordering;
#[cfg(all(feature = "std", not(no_target_has_atomic), target_has_atomic = "8"))]
#[cfg(all(feature = "std", not(target_os = "none"), not(no_target_has_atomic), target_has_atomic = "8"))]
pub use std::sync::atomic::{AtomicBool, AtomicI8, AtomicU8};
#[cfg(all(feature = "std", not(no_target_has_atomic), target_has_atomic = "16"))]
#[cfg(all(feature = "std", not(target_os = "none"), not(no_target_has_atomic), target_has_atomic = "16"))]
pub use std::sync::atomic::{AtomicI16, AtomicU16};
#[cfg(all(feature = "std", not(no_target_has_atomic), target_has_atomic = "32"))]
#[cfg(all(feature = "std", not(target_os = "none"), not(no_target_has_atomic), target_has_atomic = "32"))]
pub use std::sync::atomic::{AtomicI32, AtomicU32};
#[cfg(all(feature = "std", not(no_target_has_atomic), target_has_atomic = "64"))]
#[cfg(all(feature = "std", not(target_os = "none"), not(no_target_has_atomic), target_has_atomic = "64"))]
pub use std::sync::atomic::{AtomicI64, AtomicU64};
#[cfg(all(feature = "std", not(no_target_has_atomic), target_has_atomic = "ptr"))]
#[cfg(all(feature = "std", not(target_os = "none"), not(no_target_has_atomic), target_has_atomic = "ptr"))]
pub use std::sync::atomic::{AtomicIsize, AtomicUsize};
#[cfg(not(no_core_num_saturating))]
@@ -132,12 +166,12 @@ macro_rules! crate_root {
};
}
#[cfg_attr(no_serde_core, path = "core/de/mod.rs")]
#[cfg_attr(all(docsrs, if_docsrs_then_no_serde_core), path = "core/de/mod.rs")]
pub mod de;
#[cfg_attr(no_serde_core, path = "core/ser/mod.rs")]
#[cfg_attr(all(docsrs, if_docsrs_then_no_serde_core), path = "core/ser/mod.rs")]
pub mod ser;
#[cfg_attr(no_serde_core, path = "core/format.rs")]
#[cfg_attr(all(docsrs, if_docsrs_then_no_serde_core), path = "core/format.rs")]
mod format;
#[doc(inline)]
@@ -147,7 +181,10 @@ macro_rules! crate_root {
// Used by generated code. Not public API.
#[doc(hidden)]
#[cfg_attr(no_serde_core, path = "core/private/mod.rs")]
#[cfg_attr(
all(docsrs, if_docsrs_then_no_serde_core),
path = "core/private/mod.rs"
)]
mod private;
// Used by declarative macro generated code. Not public API.
@@ -161,8 +198,8 @@ macro_rules! crate_root {
include!(concat!(env!("OUT_DIR"), "/private.rs"));
#[cfg(all(not(feature = "std"), no_core_error))]
#[cfg_attr(no_serde_core, path = "core/std_error.rs")]
#[cfg(all(any(not(feature = "std"), target_os = "none"), no_core_error))]
#[cfg_attr(all(docsrs, if_docsrs_then_no_serde_core), path = "core/std_error.rs")]
mod std_error;
};
}
+23 -22
View File
@@ -226,12 +226,13 @@ macro_rules! num_as_copysign_self {
where
E: Error,
{
#[cfg(not(feature = "std"))]
// On no_std or wasm32v1-none (target_os = "none"), use simple cast
#[cfg(any(not(feature = "std"), target_os = "none"))]
{
Ok(v as Self::Value)
}
#[cfg(feature = "std")]
#[cfg(all(feature = "std", not(target_os = "none")))]
{
// Preserve sign of NaN. The `as` produces a nondeterministic sign.
let sign = if v.is_sign_positive() { 1.0 } else { -1.0 };
@@ -1107,7 +1108,7 @@ seq_impl!(
);
seq_impl!(
#[cfg(feature = "std")]
#[cfg(all(feature = "std", not(target_os = "none")))]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
HashSet<T: Eq + Hash, S: BuildHasher + Default>,
seq,
@@ -1563,7 +1564,7 @@ map_impl! {
}
map_impl! {
#[cfg(feature = "std")]
#[cfg(all(feature = "std", not(target_os = "none")))]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
HashMap<K: Eq + Hash, V, S: BuildHasher + Default>,
map,
@@ -1781,10 +1782,10 @@ parse_socket_impl! {
////////////////////////////////////////////////////////////////////////////////
#[cfg(feature = "std")]
#[cfg(all(feature = "std", not(target_os = "none")))]
struct PathVisitor;
#[cfg(feature = "std")]
#[cfg(all(feature = "std", not(target_os = "none")))]
impl<'a> Visitor<'a> for PathVisitor {
type Value = &'a Path;
@@ -1809,7 +1810,7 @@ impl<'a> Visitor<'a> for PathVisitor {
}
}
#[cfg(feature = "std")]
#[cfg(all(feature = "std", not(target_os = "none")))]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
impl<'de: 'a, 'a> Deserialize<'de> for &'a Path {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
@@ -1820,10 +1821,10 @@ impl<'de: 'a, 'a> Deserialize<'de> for &'a Path {
}
}
#[cfg(feature = "std")]
#[cfg(all(feature = "std", not(target_os = "none")))]
struct PathBufVisitor;
#[cfg(feature = "std")]
#[cfg(all(feature = "std", not(target_os = "none")))]
impl<'de> Visitor<'de> for PathBufVisitor {
type Value = PathBuf;
@@ -1864,7 +1865,7 @@ impl<'de> Visitor<'de> for PathBufVisitor {
}
}
#[cfg(feature = "std")]
#[cfg(all(feature = "std", not(target_os = "none")))]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
impl<'de> Deserialize<'de> for PathBuf {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
@@ -1876,7 +1877,7 @@ impl<'de> Deserialize<'de> for PathBuf {
}
forwarded_impl! {
#[cfg(feature = "std")]
#[cfg(all(feature = "std", not(target_os = "none")))]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
(), Box<Path>, PathBuf::into_boxed_path
}
@@ -1887,17 +1888,17 @@ forwarded_impl! {
//
// #[derive(Deserialize)]
// #[serde(variant_identifier)]
#[cfg(all(feature = "std", any(unix, windows)))]
#[cfg(all(feature = "std", not(target_os = "none"), any(unix, windows)))]
variant_identifier! {
OsStringKind (Unix; b"Unix"; 0, Windows; b"Windows"; 1)
"`Unix` or `Windows`",
OSSTR_VARIANTS
}
#[cfg(all(feature = "std", any(unix, windows)))]
#[cfg(all(feature = "std", not(target_os = "none"), any(unix, windows)))]
struct OsStringVisitor;
#[cfg(all(feature = "std", any(unix, windows)))]
#[cfg(all(feature = "std", not(target_os = "none"), any(unix, windows)))]
impl<'de> Visitor<'de> for OsStringVisitor {
type Value = OsString;
@@ -1938,7 +1939,7 @@ impl<'de> Visitor<'de> for OsStringVisitor {
}
}
#[cfg(all(feature = "std", any(unix, windows)))]
#[cfg(all(feature = "std", not(target_os = "none"), any(unix, windows)))]
#[cfg_attr(docsrs, doc(cfg(all(feature = "std", any(unix, windows)))))]
impl<'de> Deserialize<'de> for OsString {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
@@ -1970,7 +1971,7 @@ forwarded_impl! {
}
forwarded_impl! {
#[cfg(all(feature = "std", any(unix, windows)))]
#[cfg(all(feature = "std", not(target_os = "none"), any(unix, windows)))]
#[cfg_attr(docsrs, doc(cfg(all(feature = "std", any(unix, windows)))))]
(), Box<OsStr>, OsString::into_boxed_os_str
}
@@ -2105,13 +2106,13 @@ forwarded_impl! {
}
forwarded_impl! {
#[cfg(feature = "std")]
#[cfg(all(feature = "std", not(target_os = "none")))]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
(T), Mutex<T>, Mutex::new
}
forwarded_impl! {
#[cfg(feature = "std")]
#[cfg(all(feature = "std", not(target_os = "none")))]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
(T), RwLock<T>, RwLock::new
}
@@ -2266,7 +2267,7 @@ impl<'de> Deserialize<'de> for Duration {
////////////////////////////////////////////////////////////////////////////////
#[cfg(feature = "std")]
#[cfg(all(feature = "std", not(target_os = "none")))]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
impl<'de> Deserialize<'de> for SystemTime {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
@@ -3099,7 +3100,7 @@ where
}
}
#[cfg(all(feature = "std", not(no_std_atomic)))]
#[cfg(all(feature = "std", not(target_os = "none"), not(no_std_atomic)))]
macro_rules! atomic_impl {
($($ty:ident $size:expr)*) => {
$(
@@ -3117,7 +3118,7 @@ macro_rules! atomic_impl {
};
}
#[cfg(all(feature = "std", not(no_std_atomic)))]
#[cfg(all(feature = "std", not(target_os = "none"), not(no_std_atomic)))]
atomic_impl! {
AtomicBool "8"
AtomicI8 "8"
@@ -3130,7 +3131,7 @@ atomic_impl! {
AtomicUsize "ptr"
}
#[cfg(all(feature = "std", not(no_std_atomic64)))]
#[cfg(all(feature = "std", not(target_os = "none"), not(no_std_atomic64)))]
atomic_impl! {
AtomicI64 "64"
AtomicU64 "64"
+5 -5
View File
@@ -122,13 +122,13 @@ mod ignored_any;
mod impls;
pub use self::ignored_any::IgnoredAny;
#[cfg(all(not(feature = "std"), no_core_error))]
#[cfg(all(any(not(feature = "std"), target_os = "none"), no_core_error))]
#[doc(no_inline)]
pub use crate::std_error::Error as StdError;
#[cfg(not(any(feature = "std", no_core_error)))]
#[cfg(all(any(not(feature = "std"), target_os = "none"), not(no_core_error)))]
#[doc(no_inline)]
pub use core::error::Error as StdError;
#[cfg(feature = "std")]
#[cfg(all(feature = "std", not(target_os = "none")))]
#[doc(no_inline)]
pub use std::error::Error as StdError;
@@ -300,10 +300,10 @@ macro_rules! declare_error_trait {
}
}
#[cfg(feature = "std")]
#[cfg(all(feature = "std", not(target_os = "none")))]
declare_error_trait!(Error: Sized + StdError);
#[cfg(not(feature = "std"))]
#[cfg(any(not(feature = "std"), target_os = "none"))]
declare_error_trait!(Error: Sized + Debug + Display);
/// `Unexpected` represents an unexpected invocation of any one of the `Visitor`
+3 -3
View File
@@ -112,7 +112,7 @@ impl Debug for Error {
}
}
#[cfg(feature = "std")]
#[cfg(all(feature = "std", not(target_os = "none")))]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
impl error::Error for Error {
fn description(&self) -> &str {
@@ -1160,7 +1160,7 @@ where
}
}
#[cfg(feature = "std")]
#[cfg(all(feature = "std", not(target_os = "none")))]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
impl<'de, T, S, E> IntoDeserializer<'de, E> for HashSet<T, S>
where
@@ -1588,7 +1588,7 @@ where
}
}
#[cfg(feature = "std")]
#[cfg(all(feature = "std", not(target_os = "none")))]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
impl<'de, K, V, S, E> IntoDeserializer<'de, E> for HashMap<K, V, S>
where
+10 -4
View File
@@ -35,9 +35,11 @@
////////////////////////////////////////////////////////////////////////////////
// Serde types in rustdoc of other crates get linked to here.
#![doc(html_root_url = "https://docs.rs/serde_core/1.0.227")]
#![doc(html_root_url = "https://docs.rs/serde_core/1.0.228")]
// Support using Serde without the standard library!
#![cfg_attr(not(feature = "std"), no_std)]
// Also force no_std on target_os = "none" (wasm32v1-none) even if std feature is enabled
// This handles Cargo feature unification where std gets enabled for no_std targets
#![cfg_attr(any(not(feature = "std"), target_os = "none"), no_std)]
// Show which crate feature enables conditionally compiled APIs in documentation.
#![cfg_attr(docsrs, feature(doc_cfg, rustdoc_internals))]
#![cfg_attr(docsrs, allow(internal_features))]
@@ -54,7 +56,7 @@
// clippy bug: https://github.com/rust-lang/rust-clippy/issues/7768
clippy::semicolon_if_nothing_returned,
// not available in our oldest supported compiler
clippy::empty_enum,
clippy::empty_enums,
clippy::type_repetition_in_bounds, // https://github.com/rust-lang/rust-clippy/issues/8772
// integer and float ser/de requires these sorts of casts
clippy::cast_possible_truncation,
@@ -100,9 +102,13 @@
////////////////////////////////////////////////////////////////////////////////
#[cfg(feature = "alloc")]
#[cfg(all(feature = "alloc", any(not(feature = "std"), target_os = "none")))]
extern crate alloc;
// Explicitly import core crate for no_std targets (especially wasm32v1-none)
#[cfg(not(feature = "std"))]
extern crate core;
#[macro_use]
mod crate_root;
#[macro_use]
+1 -1
View File
@@ -18,7 +18,7 @@ impl ser::Error for Error {
}
}
#[cfg(feature = "std")]
#[cfg(all(feature = "std", not(target_os = "none")))]
#[cfg_attr(not(no_diagnostic_namespace), diagnostic::do_not_recommend)]
impl error::Error for Error {
fn description(&self) -> &str {
+1
View File
@@ -1,4 +1,5 @@
use crate::lib::*;
use crate::ser::{Error, Impossible, Serialize, Serializer};
impl Error for fmt::Error {
+12 -12
View File
@@ -219,7 +219,7 @@ seq_impl! {
}
seq_impl! {
#[cfg(feature = "std")]
#[cfg(all(feature = "std", not(target_os = "none")))]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
HashSet<T, H: BuildHasher>
}
@@ -450,7 +450,7 @@ map_impl! {
}
map_impl! {
#[cfg(feature = "std")]
#[cfg(all(feature = "std", not(target_os = "none")))]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
HashMap<K: Eq + Hash, V, H: BuildHasher>
}
@@ -624,7 +624,7 @@ where
}
}
#[cfg(feature = "std")]
#[cfg(all(feature = "std", not(target_os = "none")))]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
impl<T> Serialize for Mutex<T>
where
@@ -641,7 +641,7 @@ where
}
}
#[cfg(feature = "std")]
#[cfg(all(feature = "std", not(target_os = "none")))]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
impl<T> Serialize for RwLock<T>
where
@@ -697,7 +697,7 @@ impl Serialize for Duration {
////////////////////////////////////////////////////////////////////////////////
#[cfg(feature = "std")]
#[cfg(all(feature = "std", not(target_os = "none")))]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
impl Serialize for SystemTime {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
@@ -903,7 +903,7 @@ impl Serialize for net::SocketAddrV6 {
////////////////////////////////////////////////////////////////////////////////
#[cfg(feature = "std")]
#[cfg(all(feature = "std", not(target_os = "none")))]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
impl Serialize for Path {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
@@ -917,7 +917,7 @@ impl Serialize for Path {
}
}
#[cfg(feature = "std")]
#[cfg(all(feature = "std", not(target_os = "none")))]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
impl Serialize for PathBuf {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
@@ -928,7 +928,7 @@ impl Serialize for PathBuf {
}
}
#[cfg(all(feature = "std", any(unix, windows)))]
#[cfg(all(feature = "std", not(target_os = "none"), any(unix, windows)))]
#[cfg_attr(docsrs, doc(cfg(all(feature = "std", any(unix, windows)))))]
impl Serialize for OsStr {
#[cfg(unix)]
@@ -951,7 +951,7 @@ impl Serialize for OsStr {
}
}
#[cfg(all(feature = "std", any(unix, windows)))]
#[cfg(all(feature = "std", not(target_os = "none"), any(unix, windows)))]
#[cfg_attr(docsrs, doc(cfg(all(feature = "std", any(unix, windows)))))]
impl Serialize for OsString {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
@@ -1006,7 +1006,7 @@ where
////////////////////////////////////////////////////////////////////////////////
#[cfg(all(feature = "std", not(no_std_atomic)))]
#[cfg(all(feature = "std", not(target_os = "none"), not(no_std_atomic)))]
macro_rules! atomic_impl {
($($ty:ident $size:expr)*) => {
$(
@@ -1025,7 +1025,7 @@ macro_rules! atomic_impl {
}
}
#[cfg(all(feature = "std", not(no_std_atomic)))]
#[cfg(all(feature = "std", not(target_os = "none"), not(no_std_atomic)))]
atomic_impl! {
AtomicBool "8"
AtomicI8 "8"
@@ -1038,7 +1038,7 @@ atomic_impl! {
AtomicUsize "ptr"
}
#[cfg(all(feature = "std", not(no_std_atomic64)))]
#[cfg(all(feature = "std", not(target_os = "none"), not(no_std_atomic64)))]
atomic_impl! {
AtomicI64 "64"
AtomicU64 "64"
+5 -5
View File
@@ -115,13 +115,13 @@ mod impossible;
pub use self::impossible::Impossible;
#[cfg(all(not(feature = "std"), no_core_error))]
#[cfg(all(any(not(feature = "std"), target_os = "none"), no_core_error))]
#[doc(no_inline)]
pub use crate::std_error::Error as StdError;
#[cfg(not(any(feature = "std", no_core_error)))]
#[cfg(all(any(not(feature = "std"), target_os = "none"), not(no_core_error)))]
#[doc(no_inline)]
pub use core::error::Error as StdError;
#[cfg(feature = "std")]
#[cfg(all(feature = "std", not(target_os = "none")))]
#[doc(no_inline)]
pub use std::error::Error as StdError;
@@ -188,10 +188,10 @@ macro_rules! declare_error_trait {
}
}
#[cfg(feature = "std")]
#[cfg(all(feature = "std", not(target_os = "none")))]
declare_error_trait!(Error: Sized + StdError);
#[cfg(not(feature = "std"))]
#[cfg(any(not(feature = "std"), target_os = "none"))]
declare_error_trait!(Error: Sized + Debug + Display);
////////////////////////////////////////////////////////////////////////////////
+2 -2
View File
@@ -1,6 +1,6 @@
[package]
name = "serde_derive"
version = "1.0.227"
version = "1.0.228"
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"]
categories = ["no-std", "no-std::no-alloc"]
description = "Macros 1.1 implementation of #[derive(Serialize, Deserialize)]"
@@ -12,7 +12,7 @@ keywords = ["serde", "serialization", "no_std", "derive"]
license = "MIT OR Apache-2.0"
readme = "crates-io.md"
repository = "https://github.com/serde-rs/serde"
rust-version = "1.61"
rust-version = "1.68"
[features]
default = []
+9 -6
View File
@@ -26,9 +26,9 @@ pub fn expand_derive_deserialize(input: &mut syn::DeriveInput) -> syn::Result<To
replace_receiver(input);
let ctxt = Ctxt::new();
let cont = match Container::from_ast(&ctxt, input, Derive::Deserialize, &private.ident()) {
Some(cont) => cont,
None => return Err(ctxt.check().unwrap_err()),
let Some(cont) = Container::from_ast(&ctxt, input, Derive::Deserialize, &private.ident())
else {
return Err(ctxt.check().unwrap_err());
};
precondition(&ctxt, &cont);
ctxt.check()?;
@@ -594,13 +594,16 @@ fn deserialize_seq_in_place(
let (wrapper, wrapper_ty) = wrap_deserialize_field_with(params, field.ty, path);
quote!({
#wrapper
match _serde::de::SeqAccess::next_element::<#wrapper_ty>(&mut __seq)? {
_serde::#private::Some(__wrap) => {
match _serde::de::SeqAccess::next_element::<#wrapper_ty>(&mut __seq) {
_serde::#private::Ok(_serde::#private::Some(__wrap)) => {
self.place.#member = __wrap.value;
}
_serde::#private::None => {
_serde::#private::Ok(_serde::#private::None) => {
#value_if_none;
}
_serde::#private::Err(__err) => {
return _serde::#private::Err(__err);
}
}
})
}
+8 -6
View File
@@ -282,8 +282,8 @@ pub(super) fn deserialize(
__A: _serde::de::SeqAccess<#delife>,
{
// Visit the first element - the tag.
match _serde::de::SeqAccess::next_element(&mut __seq)? {
_serde::#private::Some(__variant) => {
match _serde::de::SeqAccess::next_element(&mut __seq) {
_serde::#private::Ok(_serde::#private::Some(__variant)) => {
// Visit the second element - the content.
match _serde::de::SeqAccess::next_element_seed(
&mut __seq,
@@ -292,18 +292,20 @@ pub(super) fn deserialize(
marker: _serde::#private::PhantomData,
lifetime: _serde::#private::PhantomData,
},
)? {
_serde::#private::Some(__ret) => _serde::#private::Ok(__ret),
) {
_serde::#private::Ok(_serde::#private::Some(__ret)) => _serde::#private::Ok(__ret),
// There is no second element.
_serde::#private::None => {
_serde::#private::Ok(_serde::#private::None) => {
_serde::#private::Err(_serde::de::Error::invalid_length(1, &self))
}
_serde::#private::Err(__err) => _serde::#private::Err(__err),
}
}
// There is no first element.
_serde::#private::None => {
_serde::#private::Ok(_serde::#private::None) => {
_serde::#private::Err(_serde::de::Error::invalid_length(0, &self))
}
_serde::#private::Err(__err) => _serde::#private::Err(__err),
}
}
}
+3 -2
View File
@@ -49,7 +49,7 @@ pub(super) fn deserialize(
));
quote! {
(__Field::#variant_name, __variant) => #block
_serde::#private::Ok((__Field::#variant_name, __variant)) => #block
}
});
@@ -69,8 +69,9 @@ pub(super) fn deserialize(
}
} else {
quote! {
match _serde::de::EnumAccess::variant(__data)? {
match _serde::de::EnumAccess::variant(__data) {
#(#variant_arms)*
_serde::#private::Err(__err) => _serde::#private::Err(__err),
}
}
};
+17 -30
View File
@@ -1185,13 +1185,11 @@ impl Field {
}
}
// Is skip_deserializing, initialize the field to Default::default() unless a
// If skip_deserializing, initialize the field to Default::default() unless a
// different default is specified by `#[serde(default = "...")]` on
// ourselves or our container (e.g. the struct we are in).
if let Default::None = *container_default {
if skip_deserializing.0.value.is_some() {
default.set_if_none(Default::Default);
}
if container_default.is_none() && skip_deserializing.0.value.is_some() {
default.set_if_none(Default::Default);
}
let mut borrowed_lifetimes = borrowed_lifetimes.get().unwrap_or_default();
@@ -1459,9 +1457,8 @@ fn parse_lit_into_path(
attr_name: Symbol,
meta: &ParseNestedMeta,
) -> syn::Result<Option<syn::Path>> {
let string = match get_lit_str(cx, attr_name, meta)? {
Some(string) => string,
None => return Ok(None),
let Some(string) = get_lit_str(cx, attr_name, meta)? else {
return Ok(None);
};
Ok(match string.parse() {
@@ -1481,9 +1478,8 @@ fn parse_lit_into_expr_path(
attr_name: Symbol,
meta: &ParseNestedMeta,
) -> syn::Result<Option<syn::ExprPath>> {
let string = match get_lit_str(cx, attr_name, meta)? {
Some(string) => string,
None => return Ok(None),
let Some(string) = get_lit_str(cx, attr_name, meta)? else {
return Ok(None);
};
Ok(match string.parse() {
@@ -1504,9 +1500,8 @@ fn parse_lit_into_where(
meta_item_name: Symbol,
meta: &ParseNestedMeta,
) -> syn::Result<Vec<syn::WherePredicate>> {
let string = match get_lit_str2(cx, attr_name, meta_item_name, meta)? {
Some(string) => string,
None => return Ok(Vec::new()),
let Some(string) = get_lit_str2(cx, attr_name, meta_item_name, meta)? else {
return Ok(Vec::new());
};
Ok(
@@ -1525,9 +1520,8 @@ fn parse_lit_into_ty(
attr_name: Symbol,
meta: &ParseNestedMeta,
) -> syn::Result<Option<syn::Type>> {
let string = match get_lit_str(cx, attr_name, meta)? {
Some(string) => string,
None => return Ok(None),
let Some(string) = get_lit_str(cx, attr_name, meta)? else {
return Ok(None);
};
Ok(match string.parse() {
@@ -1548,9 +1542,8 @@ fn parse_lit_into_lifetimes(
cx: &Ctxt,
meta: &ParseNestedMeta,
) -> syn::Result<BTreeSet<syn::Lifetime>> {
let string = match get_lit_str(cx, BORROW, meta)? {
Some(string) => string,
None => return Ok(BTreeSet::new()),
let Some(string) = get_lit_str(cx, BORROW, meta)? else {
return Ok(BTreeSet::new());
};
if let Ok(lifetimes) = string.parse_with(|input: ParseStream| {
@@ -1620,11 +1613,8 @@ fn is_cow(ty: &syn::Type, elem: fn(&syn::Type) -> bool) -> bool {
return false;
}
};
let seg = match path.segments.last() {
Some(seg) => seg,
None => {
return false;
}
let Some(seg) = path.segments.last() else {
return false;
};
let args = match &seg.arguments {
syn::PathArguments::AngleBracketed(bracketed) => &bracketed.args,
@@ -1647,11 +1637,8 @@ fn is_option(ty: &syn::Type, elem: fn(&syn::Type) -> bool) -> bool {
return false;
}
};
let seg = match path.segments.last() {
Some(seg) => seg,
None => {
return false;
}
let Some(seg) = path.segments.last() else {
return false;
};
let args = match &seg.arguments {
syn::PathArguments::AngleBracketed(bracketed) => &bracketed.args,
+2 -3
View File
@@ -46,9 +46,8 @@ impl Ctxt {
pub fn check(self) -> syn::Result<()> {
let mut errors = self.errors.borrow_mut().take().unwrap().into_iter();
let mut combined = match errors.next() {
Some(first) => first,
None => return Ok(()),
let Some(mut combined) = errors.next() else {
return Ok(());
};
for rest in errors {
+1 -1
View File
@@ -13,7 +13,7 @@
//!
//! [https://serde.rs/derive.html]: https://serde.rs/derive.html
#![doc(html_root_url = "https://docs.rs/serde_derive/1.0.227")]
#![doc(html_root_url = "https://docs.rs/serde_derive/1.0.228")]
#![cfg_attr(not(check_cfg), allow(unexpected_cfgs))]
// Ignored clippy lints
#![allow(
+2 -3
View File
@@ -13,9 +13,8 @@ pub fn expand_derive_serialize(input: &mut syn::DeriveInput) -> syn::Result<Toke
replace_receiver(input);
let ctxt = Ctxt::new();
let cont = match Container::from_ast(&ctxt, input, Derive::Serialize, &private.ident()) {
Some(cont) => cont,
None => return Err(ctxt.check().unwrap_err()),
let Some(cont) = Container::from_ast(&ctxt, input, Derive::Serialize, &private.ident()) else {
return Err(ctxt.check().unwrap_err());
};
precondition(&ctxt, &cont);
ctxt.check()?;
+1 -1
View File
@@ -10,7 +10,7 @@ homepage = "https://serde.rs"
keywords = ["serde", "serialization"]
license = "MIT OR Apache-2.0"
repository = "https://github.com/serde-rs/serde"
rust-version = "1.61"
rust-version = "1.68"
[lib]
path = "lib.rs"
+1 -1
View File
@@ -2,7 +2,7 @@
clippy::cast_lossless,
clippy::decimal_literal_representation,
clippy::derive_partial_eq_without_eq,
clippy::empty_enum,
clippy::empty_enums,
clippy::manual_assert,
clippy::needless_pass_by_value,
clippy::uninlined_format_args,
+1 -1
View File
@@ -1,6 +1,6 @@
#![allow(
clippy::derive_partial_eq_without_eq,
clippy::empty_enum,
clippy::empty_enums,
clippy::unreadable_literal
)]
#![cfg_attr(feature = "unstable", feature(never_type))]
@@ -11,7 +11,7 @@ struct T0(u8, u8);
struct T1(u8, #[serde(default)] u8);
// ERROR: The first field can get default value only if sequence is empty, but
// that mean that all other fields cannot be deserialized without errors.
// that means that all other fields cannot be deserialized without errors.
#[derive(Deserialize)]
struct T2(#[serde(default)] u8, u8, u8);
@@ -11,7 +11,7 @@ fn d<T>() -> T {
struct T1(u8, #[serde(default = "d")] u8);
// ERROR: The first field can get default value only if sequence is empty, but
// that mean that all other fields cannot be deserialized without errors.
// that means that all other fields cannot be deserialized without errors.
#[derive(Deserialize)]
struct T2(#[serde(default = "d")] u8, u8, u8);
+20 -4
View File
@@ -6,7 +6,11 @@ error[E0277]: the trait bound `&u8: serde::Serializer` is not satisfied
15 | struct W(#[serde(with = "w")] u8, u8);
| --- required by a bound introduced by this call
|
= help: the trait `Serializer` is implemented for `&mut Formatter<'a>`
help: the trait `Serializer` is implemented for `&mut Formatter<'a>`
--> $WORKSPACE/serde_core/src/ser/fmt.rs
|
| impl<'a> Serializer for &mut fmt::Formatter<'a> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: required by a bound in `w::serialize`
--> tests/ui/with/incorrect_type.rs:9:28
|
@@ -33,7 +37,11 @@ error[E0277]: the trait bound `&u8: serde::Serializer` is not satisfied
15 | struct W(#[serde(with = "w")] u8, u8);
| ^^^ the trait `Serializer` is not implemented for `&u8`
|
= help: the trait `Serializer` is implemented for `&mut Formatter<'a>`
help: the trait `Serializer` is implemented for `&mut Formatter<'a>`
--> $WORKSPACE/serde_core/src/ser/fmt.rs
|
| impl<'a> Serializer for &mut fmt::Formatter<'a> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0308]: `?` operator has incompatible types
--> tests/ui/with/incorrect_type.rs:15:25
@@ -51,7 +59,11 @@ error[E0277]: the trait bound `&u8: serde::Serializer` is not satisfied
18 | struct S(#[serde(serialize_with = "w::serialize")] u8, u8);
| -------------- required by a bound introduced by this call
|
= help: the trait `Serializer` is implemented for `&mut Formatter<'a>`
help: the trait `Serializer` is implemented for `&mut Formatter<'a>`
--> $WORKSPACE/serde_core/src/ser/fmt.rs
|
| impl<'a> Serializer for &mut fmt::Formatter<'a> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: required by a bound in `w::serialize`
--> tests/ui/with/incorrect_type.rs:9:28
|
@@ -78,7 +90,11 @@ error[E0277]: the trait bound `&u8: serde::Serializer` is not satisfied
18 | struct S(#[serde(serialize_with = "w::serialize")] u8, u8);
| ^^^^^^^^^^^^^^ the trait `Serializer` is not implemented for `&u8`
|
= help: the trait `Serializer` is implemented for `&mut Formatter<'a>`
help: the trait `Serializer` is implemented for `&mut Formatter<'a>`
--> $WORKSPACE/serde_core/src/ser/fmt.rs
|
| impl<'a> Serializer for &mut fmt::Formatter<'a> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0308]: `?` operator has incompatible types
--> tests/ui/with/incorrect_type.rs:21:37