Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support core::error::Error #1038

Merged
merged 4 commits into from
Sep 7, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions packages/libs/error-stack/src/context.rs
Original file line number Diff line number Diff line change
@@ -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.
TimDiekmann marked this conversation as resolved.
Show resolved Hide resolved
///
/// [`Error`]: std::error::Error
/// [`Error`]: core::error::Error
///
/// ## Example
///
Expand Down Expand Up @@ -80,10 +84,10 @@ where
}
}

#[cfg(feature = "std")]
impl<C: std::error::Error + Send + Sync + 'static> Context for C {
#[cfg(any(nightly, feature = "std"))]
impl<C: Error + Send + Sync + 'static> Context for C {
#[cfg(nightly)]
fn provide<'a>(&'a self, demand: &mut Demand<'a>) {
std::error::Error::provide(self, demand);
Error::provide(self, demand);
}
}
2 changes: 1 addition & 1 deletion packages/libs/error-stack/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
4 changes: 2 additions & 2 deletions packages/libs/error-stack/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub mod __private {
///
/// [`Report`]: crate::Report
/// [`Context`]: crate::Context
/// [`Error`]: std::error::Error
/// [`Error`]: core::error::Error
///
/// # Examples
///
Expand Down Expand Up @@ -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"))] {
Expand Down