Compare commits

...

12 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
12 changed files with 195 additions and 105 deletions
+39 -13
View File
@@ -97,7 +97,9 @@
// Serde types in rustdoc of other crates get linked to here.
#![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))]
@@ -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> {
+76 -42
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))]
@@ -164,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;
};
+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
+8 -2
View File
@@ -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))]
@@ -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);
////////////////////////////////////////////////////////////////////////////////