diff --git a/build.rs b/build.rs index 8c4db41f0..3e5c29abd 100644 --- a/build.rs +++ b/build.rs @@ -32,6 +32,7 @@ fn main() { println!("cargo:rustc-check-cfg=cfg(compile_error_if_alloc)"); println!("cargo:rustc-check-cfg=cfg(compile_error_if_std)"); println!("cargo:rustc-check-cfg=cfg(cxx_experimental_no_alloc)"); + println!("cargo:rustc-check-cfg=cfg(no_core_error)"); println!("cargo:rustc-check-cfg=cfg(no_core_ffi_c_char)"); println!("cargo:rustc-check-cfg=cfg(skip_ui_tests)"); } @@ -48,6 +49,11 @@ fn main() { // core::ffi::c_char println!("cargo:rustc-cfg=no_core_ffi_c_char"); } + + if rustc.minor < 81 { + // core::error::Error + println!("cargo:rustc-cfg=no_core_error"); + } } } diff --git a/src/exception.rs b/src/exception.rs index c40db9f0b..80cd79a50 100644 --- a/src/exception.rs +++ b/src/exception.rs @@ -3,6 +3,11 @@ use alloc::boxed::Box; use core::fmt::{self, Display}; +#[cfg(all(feature = "std", not(no_core_error)))] +use core::error::Error as StdError; +#[cfg(all(feature = "std", no_core_error))] +use std::error::Error as StdError; + /// Exception thrown from an `extern "C++"` function. #[cfg_attr(docsrs, doc(cfg(feature = "alloc")))] #[derive(Debug)] @@ -18,7 +23,7 @@ impl Display for Exception { #[cfg(feature = "std")] #[cfg_attr(docsrs, doc(cfg(feature = "std")))] -impl std::error::Error for Exception {} +impl StdError for Exception {} impl Exception { #[allow(missing_docs)]