From 7ce49dc38b3da98b016dd06327a1d4d5cf7c8f51 Mon Sep 17 00:00:00 2001 From: Kurdistan Tech Ministry Date: Fri, 9 Jan 2026 12:44:12 +0300 Subject: [PATCH] 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 --- serde_core/src/crate_root.rs | 31 ++++++++++++++++++++++++++++--- serde_core/src/lib.rs | 4 ++++ 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/serde_core/src/crate_root.rs b/serde_core/src/crate_root.rs index 2cf75a40..11059852 100644 --- a/serde_core/src/crate_root.rs +++ b/serde_core/src/crate_root.rs @@ -6,11 +6,27 @@ macro_rules! crate_root { mod lib { mod core { #[cfg(not(feature = "std"))] - pub use core::*; + pub use ::core::*; #[cfg(feature = "std")] - pub use std::*; + pub use ::std::*; } + // Re-export the full prelude for wasm32v1-none and other targets + #[cfg(not(feature = "std"))] + pub use ::core::prelude::rust_2021::*; + #[cfg(feature = "std")] + pub use ::std::prelude::rust_2021::*; + + // Prelude items that may not be re-exported by glob import + #[cfg(not(feature = "std"))] + pub use ::core::option::Option::{self, None, Some}; + #[cfg(not(feature = "std"))] + pub use ::core::result::Result::{self, Err, Ok}; + #[cfg(feature = "std")] + pub use ::std::option::Option::{self, None, Some}; + #[cfg(feature = "std")] + pub use ::std::result::Result::{self, Err, Ok}; + pub use self::core::{f32, f64}; pub use self::core::{iter, num, str}; @@ -20,7 +36,16 @@ 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; diff --git a/serde_core/src/lib.rs b/serde_core/src/lib.rs index b2b32b50..54bfc1bc 100644 --- a/serde_core/src/lib.rs +++ b/serde_core/src/lib.rs @@ -103,6 +103,10 @@ #[cfg(feature = "alloc")] 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]