From 5c4715fff56c64b70f0905e1386870616d46674d Mon Sep 17 00:00:00 2001 From: Tim Diekmann <21277928+TimDiekmann@users.noreply.github.com> Date: Wed, 7 Sep 2022 09:17:28 +0200 Subject: [PATCH 1/3] Support `core::error::Error` --- packages/libs/error-stack/src/context.rs | 16 ++++++++++------ packages/libs/error-stack/src/lib.rs | 2 +- packages/libs/error-stack/src/macros.rs | 4 ++-- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/packages/libs/error-stack/src/context.rs b/packages/libs/error-stack/src/context.rs index 4e2b9503806..1899441eacc 100644 --- a/packages/libs/error-stack/src/context.rs +++ b/packages/libs/error-stack/src/context.rs @@ -1,15 +1,19 @@ #[cfg(nightly)] use core::any::Demand; +#[cfg(nightly)] +use core::error::Error; use core::fmt; +#[cfg(all(not(nightly), feature = "std"))] +use std::error::Error; use crate::Report; /// Defines the current context of a [`Report`]. /// -/// When in a `std` environment, every [`Error`] is a valid `Context`. This trait is not limited to -/// [`Error`]s and can also be manually implemented for custom objects. +/// When in a `std` environment or on a nightly toolchain, every [`Error`] is a valid `Context`. +/// This trait is not limited to [`Error`]s and can also be manually implemented for custom objects. /// -/// [`Error`]: std::error::Error +/// [`Error`]: core::error::Error /// /// ## Example /// @@ -80,10 +84,10 @@ where } } -#[cfg(feature = "std")] -impl Context for C { +#[cfg(any(nightly, feature = "std"))] +impl Context for C { #[cfg(nightly)] fn provide<'a>(&'a self, demand: &mut Demand<'a>) { - std::error::Error::provide(self, demand); + Error::provide(self, demand); } } diff --git a/packages/libs/error-stack/src/lib.rs b/packages/libs/error-stack/src/lib.rs index ae43088e6db..2d80df97239 100644 --- a/packages/libs/error-stack/src/lib.rs +++ b/packages/libs/error-stack/src/lib.rs @@ -438,7 +438,7 @@ //! [`SpanTrace`]: tracing_error::SpanTrace //! [`smallvec`]: https://docs.rs/smallvec #![cfg_attr(not(feature = "std"), no_std)] -#![cfg_attr(nightly, feature(provide_any))] +#![cfg_attr(nightly, feature(provide_any, error_in_core))] #![cfg_attr(all(doc, nightly), feature(doc_auto_cfg))] #![cfg_attr( all(nightly, feature = "std"), diff --git a/packages/libs/error-stack/src/macros.rs b/packages/libs/error-stack/src/macros.rs index 356c38c73eb..1f9e5bd1a41 100644 --- a/packages/libs/error-stack/src/macros.rs +++ b/packages/libs/error-stack/src/macros.rs @@ -73,7 +73,7 @@ pub mod __private { /// /// [`Report`]: crate::Report /// [`Context`]: crate::Context -/// [`Error`]: std::error::Error +/// [`Error`]: core::error::Error /// /// # Examples /// @@ -144,7 +144,7 @@ macro_rules! report { /// /// Create a [`Report`] from [`Error`]: /// -/// [`Error`]: std::error::Error +/// [`Error`]: core::error::Error /// /// ``` /// # #[cfg(all(not(miri), feature = "std"))] { From 7fd6830a212d5135d36cbc8054159ab090dcaff0 Mon Sep 17 00:00:00 2001 From: Tim Diekmann <21277928+TimDiekmann@users.noreply.github.com> Date: Wed, 7 Sep 2022 10:04:38 +0200 Subject: [PATCH 2/3] Apply suggestions from code review Co-authored-by: Bilal Mahmoud --- packages/libs/error-stack/src/context.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/libs/error-stack/src/context.rs b/packages/libs/error-stack/src/context.rs index 1899441eacc..93a069fd403 100644 --- a/packages/libs/error-stack/src/context.rs +++ b/packages/libs/error-stack/src/context.rs @@ -11,7 +11,7 @@ use crate::Report; /// Defines the current context of a [`Report`]. /// /// When in a `std` environment or on a nightly toolchain, every [`Error`] is a valid `Context`. -/// This trait is not limited to [`Error`]s and can also be manually implemented for custom objects. +/// This trait is not limited to [`Error`]s and can also be manually implemented on a type. /// /// [`Error`]: core::error::Error /// From 0b706ae3c9c35a925d6dd8e4f8f594b0dd166758 Mon Sep 17 00:00:00 2001 From: Tim Diekmann <21277928+TimDiekmann@users.noreply.github.com> Date: Wed, 7 Sep 2022 16:40:56 +0200 Subject: [PATCH 3/3] Fix missing feature on non-std --- packages/libs/error-stack/src/lib.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/libs/error-stack/src/lib.rs b/packages/libs/error-stack/src/lib.rs index f549f92286b..a9f9e0a1a82 100644 --- a/packages/libs/error-stack/src/lib.rs +++ b/packages/libs/error-stack/src/lib.rs @@ -438,12 +438,12 @@ //! [`SpanTrace`]: tracing_error::SpanTrace //! [`smallvec`]: https://docs.rs/smallvec #![cfg_attr(not(feature = "std"), no_std)] -#![cfg_attr(nightly, feature(provide_any, error_in_core))] -#![cfg_attr(all(doc, nightly), feature(doc_auto_cfg))] #![cfg_attr( - all(nightly, feature = "std"), - feature(backtrace_frames, error_generic_member_access) + nightly, + feature(provide_any, error_in_core, error_generic_member_access) )] +#![cfg_attr(all(doc, nightly), feature(doc_auto_cfg))] +#![cfg_attr(all(nightly, feature = "std"), feature(backtrace_frames))] #![warn( missing_docs, unreachable_pub,