Commit Graph

38 Commits

Author SHA1 Message Date
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 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 a866b336f1 Release 1.0.228 2025-09-27 09:51:07 -07:00
David Tolnay ab581789f4 Workaround for RUSTDOCFLAGS='--cfg=docsrs' 2025-09-27 09:46:14 -07:00
David Tolnay 415d9fc560 Release 1.0.227 2025-09-25 16:42:33 -07:00
David Tolnay 7c58427e12 Merge pull request #2991 from dtolnay/inlinecoredoc
Inline serde_core into serde in docsrs mode
2025-09-25 16:41:35 -07:00
David Tolnay 2fb6748bf1 Remove InPlaceSeed public re-export 2025-09-25 16:26:14 -07:00
David Tolnay f8137c79a2 Inline serde_core into serde in docsrs mode 2025-09-25 13:22:15 -07:00
David Tolnay 1799547846 Release 1.0.226 2025-09-20 16:34:44 -07:00
David Tolnay 1d7899d671 Release 1.0.225 2025-09-15 20:43:08 -07:00
David Tolnay cbe98a9888 Use differently named __private module per patch release 2025-09-15 09:53:14 -07:00
David Tolnay 169988206a Release 1.0.224 2025-09-15 08:46:21 -07:00
David Tolnay bf9ebea392 Mark every trait impl for a private type with do_not_recommend 2025-09-14 19:47:36 -07:00
David Tolnay 6c316d7cb5 Release 1.0.223 2025-09-14 13:20:31 -07:00
David Tolnay ed76364f87 Change serde_core's html_root_url to docs.rs/serde_core 2025-09-14 12:54:38 -07:00
David Tolnay 57e21a1afa Release 1.0.222 2025-09-14 11:09:08 -07:00
David Tolnay 00b1b6b2b5 Move Content's Deserialize impl from serde_core to serde 2025-09-14 08:35:53 -07:00
David Tolnay cf141aa8c7 Move Content's Clone impl from serde_core to serde 2025-09-14 08:35:32 -07:00
David Tolnay ff3aee490a Release 1.0.221 2025-09-13 17:25:20 -07:00
David Tolnay 3bea3b6989 Move serde_if_integer128 macro to serde 2025-09-13 17:12:58 -07:00
David Tolnay 900c922f41 Illustrate build timings in serde_core readme 2025-09-13 17:09:47 -07:00
David Tolnay be255d62c8 Release 1.0.220 2025-09-13 14:45:43 -07:00
David Tolnay 6bea2e04e4 Move doc helper macros to serde_core 2025-09-13 14:32:21 -07:00
David Tolnay a9150aad74 Make serde_core::Result private 2025-09-13 14:29:23 -07:00
David Tolnay 5ac3d84d99 Make InPlaceSeed private 2025-09-13 14:29:23 -07:00
David Tolnay f916ec6baa Make size_hint private 2025-09-13 14:29:22 -07:00
David Tolnay 7f831225a9 Make from_utf8_lossy private 2025-09-13 14:29:01 -07:00
David Tolnay a16893429b Make module for Content-related private code 2025-09-13 14:26:58 -07:00
David Tolnay f669f16127 Restore __deserialize_content optimization 2025-09-13 14:22:33 -07:00
David Tolnay 8909fc0c60 Enforce derive cannot be used against serde_core
Even for a simple data structure that would ordinarily expand to an impl
that only refers to the public Serde traits without serde::__private, we
still disallow a (renamed) serde_core dependency. This leaves the
liberty to new usage of private helpers in such impls over time. For
example, similar to the optimization of the standard library's
derive(Debug) that introduced debug_struct_field1_finish to improve
compile time of derived impls.
2025-09-13 14:15:44 -07:00
David Tolnay 51f8b0c52d Rewrite serde_core readme 2025-09-13 14:07:53 -07:00
David Tolnay 6c4cae6b09 Point API documentation to docs.rs/serde 2025-09-13 14:07:53 -07:00
David Tolnay 4bddf1b953 Override diagnostic::on_unimplemented message of all serde_core traits
This prevents diagnostics being rendered like `serde_core::ser::Serialize`
and `serde_core::de::Deserialize` in projects that have no direct
dependency on serde_core.

The attributes make error messages arguably sometimes worse than
pre-serde_core by always rendering `serde::Serialize` and never
`Serialize` when `use serde::Serialize` is in scope, which rustc's
default message construction knows to recognize. But this is probably
negligible.

I explored the alternative of setting `[lib] name = "serde"` in
serde_core/Cargo.toml which also prevents `serde_core::ser::Serialize`
in messages, but has the unwanted effect of also inserting the following
noise into every such error:

    note: there are multiple different versions of crate `serde` in the dependency graph
        --> $WORKSPACE/serde_core/src/ser/mod.rs:225:1
         |
     225 | pub trait Serialize {
         | ^^^^^^^^^^^^^^^^^^^ this is the required trait
         |
        ::: src/main.rs:1:1
         |
       1 | struct MyStruct;
         | --------------- this type doesn't implement the required trait
    ...
       4 |     let _ = serde_json::to_string(&MyStruct);
         |             ----------
         |             |
         |             one version of crate `serde` used here, as a dependency of crate `serde`
         |             one version of crate `serde` used here, as a dependency of crate `serde_json`
         |
        ::: $WORKSPACE/serde/src/private/de.rs:2347:1
         |
    2347 | pub trait IdentifierDeserializer<'de, E: Error> {
         | ----------------------------------------------- this is the found trait
         = help: you can use `cargo tree` to explore your dependency tree

The "this is the found trait" pointing to `IdentifierDeserializer` seems
like a compiler bug...
2025-09-13 13:59:52 -07:00
Piotr Osiewicz 3deb08946e review: Gate Result impls behind a feature gate 2025-06-06 11:57:32 +02:00
Piotr Osiewicz 43f5eb5c69 review: Bring back old doc comment for serde_core 2025-06-06 11:57:32 +02:00
Piotr Osiewicz f3869307cc feat: extract serde_core out of serde 2025-06-06 11:57:32 +02:00