Skip to content

Commit

Permalink
Merge pull request #2818 from dtolnay/coreerror
Browse files Browse the repository at this point in the history
Stabilize no-std Error trait
  • Loading branch information
dtolnay committed Sep 6, 2024
2 parents d549f04 + 785c2d9 commit eeb8e44
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
7 changes: 7 additions & 0 deletions serde/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)");
Expand Down Expand Up @@ -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<u32> {
Expand Down
4 changes: 2 additions & 2 deletions serde/src/de/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
2 changes: 1 addition & 1 deletion serde/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)].
Expand Down
4 changes: 2 additions & 2 deletions serde/src/ser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down

0 comments on commit eeb8e44

Please sign in to comment.