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>
This commit is contained in:
2026-01-09 13:21:34 +03:00
parent 7ce49dc38b
commit d99c876120
7 changed files with 38 additions and 0 deletions
+6
View File
@@ -1,5 +1,11 @@
use crate::lib::*;
// Explicit prelude import for wasm32v1-none target compatibility
// These may appear unused but are required for ?Sized bounds on wasm32v1-none
#[allow(unused_imports)]
#[cfg(not(feature = "std"))]
use ::core::prelude::rust_2021::*;
use crate::de::{
Deserialize, Deserializer, EnumAccess, Error, MapAccess, SeqAccess, Unexpected, VariantAccess,
Visitor,
+5
View File
@@ -114,6 +114,11 @@
use crate::lib::*;
// Explicit prelude import for wasm32v1-none target compatibility
#[allow(unused_imports)]
#[cfg(not(feature = "std"))]
use ::core::prelude::rust_2021::*;
////////////////////////////////////////////////////////////////////////////////
pub mod value;
+5
View File
@@ -2,6 +2,11 @@
use crate::lib::*;
// Explicit prelude import for wasm32v1-none target compatibility
#[allow(unused_imports)]
#[cfg(not(feature = "std"))]
use ::core::prelude::rust_2021::*;
use crate::ser;
#[doc(hidden)]
+6
View File
@@ -1,4 +1,10 @@
use crate::lib::*;
// Explicit prelude import for wasm32v1-none target compatibility
#[allow(unused_imports)]
#[cfg(not(feature = "std"))]
use ::core::prelude::rust_2021::*;
use crate::ser::{Error, Impossible, Serialize, Serializer};
impl Error for fmt::Error {
+6
View File
@@ -1,5 +1,11 @@
use crate::lib::*;
// Explicit prelude import for wasm32v1-none target compatibility
// These may appear unused but are required for ?Sized bounds on wasm32v1-none
#[allow(unused_imports)]
#[cfg(not(feature = "std"))]
use ::core::prelude::rust_2021::*;
use crate::ser::{Error, Serialize, SerializeTuple, Serializer};
////////////////////////////////////////////////////////////////////////////////
+5
View File
@@ -2,6 +2,11 @@
use crate::lib::*;
// Explicit prelude import for wasm32v1-none target compatibility
#[allow(unused_imports)]
#[cfg(not(feature = "std"))]
use ::core::prelude::rust_2021::*;
use crate::ser::{
self, Serialize, SerializeMap, SerializeSeq, SerializeStruct, SerializeStructVariant,
SerializeTuple, SerializeTupleStruct, SerializeTupleVariant,
+5
View File
@@ -109,6 +109,11 @@
use crate::lib::*;
// Explicit prelude import for wasm32v1-none target compatibility
#[allow(unused_imports)]
#[cfg(not(feature = "std"))]
use ::core::prelude::rust_2021::*;
mod fmt;
mod impls;
mod impossible;