mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-04-22 05:37:58 +00:00
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
This commit is contained in:
@@ -3,28 +3,35 @@ 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"))]
|
||||
// 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(feature = "std")]
|
||||
#[cfg(all(feature = "std", not(target_os = "none")))]
|
||||
pub use ::std::*;
|
||||
}
|
||||
|
||||
// Re-export the full prelude for wasm32v1-none and other targets
|
||||
#[cfg(not(feature = "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(feature = "std")]
|
||||
#[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(not(feature = "std"))]
|
||||
#[cfg(any(not(feature = "std"), target_os = "none"))]
|
||||
pub use ::core::option::Option::{self, None, Some};
|
||||
#[cfg(not(feature = "std"))]
|
||||
#[cfg(any(not(feature = "std"), target_os = "none"))]
|
||||
pub use ::core::result::Result::{self, Err, Ok};
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg(all(feature = "std", not(target_os = "none")))]
|
||||
pub use ::std::option::Option::{self, None, Some};
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg(all(feature = "std", not(target_os = "none")))]
|
||||
pub use ::std::result::Result::{self, Err, Ok};
|
||||
|
||||
pub use self::core::{f32, f64};
|
||||
@@ -51,93 +58,95 @@ macro_rules! crate_root {
|
||||
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))]
|
||||
@@ -189,7 +198,7 @@ macro_rules! crate_root {
|
||||
|
||||
include!(concat!(env!("OUT_DIR"), "/private.rs"));
|
||||
|
||||
#[cfg(all(not(feature = "std"), no_core_error))]
|
||||
#[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;
|
||||
};
|
||||
|
||||
+24
-24
@@ -1,9 +1,9 @@
|
||||
use crate::lib::*;
|
||||
|
||||
// Explicit prelude import for wasm32v1-none target compatibility
|
||||
// These may appear unused but are required for ?Sized bounds on wasm32v1-none
|
||||
// Explicit prelude import for wasm32v1-none and other no_std targets
|
||||
// Even when "std" feature is enabled (due to Cargo feature unification),
|
||||
// the prelude may not be injected on wasm32v1-none target
|
||||
#[allow(unused_imports)]
|
||||
#[cfg(not(feature = "std"))]
|
||||
use ::core::prelude::rust_2021::*;
|
||||
|
||||
use crate::de::{
|
||||
@@ -237,7 +237,7 @@ macro_rules! num_as_copysign_self {
|
||||
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 };
|
||||
@@ -1113,7 +1113,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,
|
||||
@@ -1569,7 +1569,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,
|
||||
@@ -1787,10 +1787,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;
|
||||
|
||||
@@ -1815,7 +1815,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>
|
||||
@@ -1826,10 +1826,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;
|
||||
|
||||
@@ -1870,7 +1870,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>
|
||||
@@ -1882,7 +1882,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
|
||||
}
|
||||
@@ -1893,17 +1893,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;
|
||||
|
||||
@@ -1944,7 +1944,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>
|
||||
@@ -1976,7 +1976,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
|
||||
}
|
||||
@@ -2111,13 +2111,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
|
||||
}
|
||||
@@ -2272,7 +2272,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>
|
||||
@@ -3105,7 +3105,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)*) => {
|
||||
$(
|
||||
@@ -3123,7 +3123,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"
|
||||
@@ -3136,7 +3136,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"
|
||||
|
||||
@@ -114,9 +114,8 @@
|
||||
|
||||
use crate::lib::*;
|
||||
|
||||
// Explicit prelude import for wasm32v1-none target compatibility
|
||||
// Explicit prelude import for wasm32v1-none and other no_std targets
|
||||
#[allow(unused_imports)]
|
||||
#[cfg(not(feature = "std"))]
|
||||
use ::core::prelude::rust_2021::*;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -127,13 +126,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;
|
||||
|
||||
@@ -305,10 +304,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`
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -37,7 +37,9 @@
|
||||
// Serde types in rustdoc of other crates get linked to here.
|
||||
#![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))]
|
||||
|
||||
@@ -2,9 +2,8 @@
|
||||
|
||||
use crate::lib::*;
|
||||
|
||||
// Explicit prelude import for wasm32v1-none target compatibility
|
||||
// Explicit prelude import for wasm32v1-none and other no_std targets
|
||||
#[allow(unused_imports)]
|
||||
#[cfg(not(feature = "std"))]
|
||||
use ::core::prelude::rust_2021::*;
|
||||
|
||||
use crate::ser;
|
||||
@@ -23,7 +22,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,8 +1,7 @@
|
||||
use crate::lib::*;
|
||||
|
||||
// Explicit prelude import for wasm32v1-none target compatibility
|
||||
// Explicit prelude import for wasm32v1-none and other no_std targets
|
||||
#[allow(unused_imports)]
|
||||
#[cfg(not(feature = "std"))]
|
||||
use ::core::prelude::rust_2021::*;
|
||||
|
||||
use crate::ser::{Error, Impossible, Serialize, Serializer};
|
||||
|
||||
+15
-15
@@ -1,9 +1,9 @@
|
||||
use crate::lib::*;
|
||||
|
||||
// Explicit prelude import for wasm32v1-none target compatibility
|
||||
// These may appear unused but are required for ?Sized bounds on wasm32v1-none
|
||||
// Explicit prelude import for wasm32v1-none and other no_std targets
|
||||
// Even when "std" feature is enabled (due to Cargo feature unification),
|
||||
// the prelude may not be injected on wasm32v1-none target
|
||||
#[allow(unused_imports)]
|
||||
#[cfg(not(feature = "std"))]
|
||||
use ::core::prelude::rust_2021::*;
|
||||
|
||||
use crate::ser::{Error, Serialize, SerializeTuple, Serializer};
|
||||
@@ -225,7 +225,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>
|
||||
}
|
||||
@@ -456,7 +456,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>
|
||||
}
|
||||
@@ -630,7 +630,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
|
||||
@@ -647,7 +647,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
|
||||
@@ -703,7 +703,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>
|
||||
@@ -909,7 +909,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>
|
||||
@@ -923,7 +923,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>
|
||||
@@ -934,7 +934,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)]
|
||||
@@ -957,7 +957,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>
|
||||
@@ -1012,7 +1012,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)*) => {
|
||||
$(
|
||||
@@ -1031,7 +1031,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"
|
||||
@@ -1044,7 +1044,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"
|
||||
|
||||
@@ -2,9 +2,8 @@
|
||||
|
||||
use crate::lib::*;
|
||||
|
||||
// Explicit prelude import for wasm32v1-none target compatibility
|
||||
// Explicit prelude import for wasm32v1-none and other no_std targets
|
||||
#[allow(unused_imports)]
|
||||
#[cfg(not(feature = "std"))]
|
||||
use ::core::prelude::rust_2021::*;
|
||||
|
||||
use crate::ser::{
|
||||
|
||||
@@ -109,9 +109,8 @@
|
||||
|
||||
use crate::lib::*;
|
||||
|
||||
// Explicit prelude import for wasm32v1-none target compatibility
|
||||
// Explicit prelude import for wasm32v1-none and other no_std targets
|
||||
#[allow(unused_imports)]
|
||||
#[cfg(not(feature = "std"))]
|
||||
use ::core::prelude::rust_2021::*;
|
||||
|
||||
mod fmt;
|
||||
@@ -120,13 +119,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;
|
||||
|
||||
@@ -193,10 +192,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);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Reference in New Issue
Block a user