From 785c2d9605ee73cc172dfd421228c1dccca984c9 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Fri, 6 Sep 2024 11:09:11 -0700 Subject: [PATCH] Stabilize no-std StdError trait --- serde/build.rs | 7 +++++++ serde/src/de/mod.rs | 4 ++-- serde/src/lib.rs | 2 +- serde/src/ser/mod.rs | 4 ++-- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/serde/build.rs b/serde/build.rs index 60451158..8a4f7257 100644 --- a/serde/build.rs +++ b/serde/build.rs @@ -15,6 +15,7 @@ fn main() { if minor >= 77 { println!("cargo:rustc-check-cfg=cfg(no_core_cstr)"); + println!("cargo:rustc-check-cfg=cfg(no_core_error)"); println!("cargo:rustc-check-cfg=cfg(no_core_net)"); println!("cargo:rustc-check-cfg=cfg(no_core_num_saturating)"); println!("cargo:rustc-check-cfg=cfg(no_core_try_from)"); @@ -98,6 +99,12 @@ fn main() { if minor < 78 { println!("cargo:rustc-cfg=no_diagnostic_namespace"); } + + // The Error trait became available in core in 1.81. + // https://blog.rust-lang.org/2024/09/05/Rust-1.81.0.html#coreerrorerror + if minor < 81 { + println!("cargo:rustc-cfg=no_core_error"); + } } fn rustc_minor_version() -> Option { diff --git a/serde/src/de/mod.rs b/serde/src/de/mod.rs index a87558ec..21cfd041 100644 --- a/serde/src/de/mod.rs +++ b/serde/src/de/mod.rs @@ -124,10 +124,10 @@ pub(crate) mod size_hint; pub use self::ignored_any::IgnoredAny; -#[cfg(not(any(feature = "std", feature = "unstable")))] +#[cfg(all(not(feature = "std"), no_core_error))] #[doc(no_inline)] pub use crate::std_error::Error as StdError; -#[cfg(all(feature = "unstable", not(feature = "std")))] +#[cfg(not(any(feature = "std", no_core_error)))] #[doc(no_inline)] pub use core::error::Error as StdError; #[cfg(feature = "std")] diff --git a/serde/src/lib.rs b/serde/src/lib.rs index f40f6a60..72f6f8bc 100644 --- a/serde/src/lib.rs +++ b/serde/src/lib.rs @@ -325,7 +325,7 @@ pub mod __private; #[path = "de/seed.rs"] mod seed; -#[cfg(not(any(feature = "std", feature = "unstable")))] +#[cfg(all(not(feature = "std"), no_core_error))] mod std_error; // Re-export #[derive(Serialize, Deserialize)]. diff --git a/serde/src/ser/mod.rs b/serde/src/ser/mod.rs index 30a64809..fb0033ec 100644 --- a/serde/src/ser/mod.rs +++ b/serde/src/ser/mod.rs @@ -115,10 +115,10 @@ mod impossible; pub use self::impossible::Impossible; -#[cfg(not(any(feature = "std", feature = "unstable")))] +#[cfg(all(not(feature = "std"), no_core_error))] #[doc(no_inline)] pub use crate::std_error::Error as StdError; -#[cfg(all(feature = "unstable", not(feature = "std")))] +#[cfg(not(any(feature = "std", no_core_error)))] #[doc(no_inline)] pub use core::error::Error as StdError; #[cfg(feature = "std")]