From afc256855196327614d7b51353835ffcbb84eab0 Mon Sep 17 00:00:00 2001 From: David Ross Date: Wed, 10 Jan 2018 16:17:29 -0800 Subject: [PATCH 1/2] Split backtrace and std features up. This allows depending on std Fail implementations without depending on the backtrace crate. Note that with this, both the 'backtrace' and 'std' features must be enabled in order to access backtrace functionality. There is no current way to depend on the 'std' feature from the 'backtrace' feature in cargo, as it is named after a dependency. --- .travis.yml | 2 ++ Cargo.toml | 4 ++-- src/backtrace/mod.rs | 14 ++++++++++++-- src/lib.rs | 6 ++++++ 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index c771d1a..f311898 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,3 +8,5 @@ cache: cargo script: - cargo test - cargo test --no-default-features +- cargo test --no-default-features --features std +- cargo test --no-default-features --features backtrace diff --git a/Cargo.toml b/Cargo.toml index 56e8df8..30256e5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,8 +17,8 @@ optional = true version = "0.3.3" [features] -default = ["std", "derive"] -std = ["backtrace"] +default = ["std", "derive", "backtrace"] +std = [] derive = ["failure_derive"] [[example]] diff --git a/src/backtrace/mod.rs b/src/backtrace/mod.rs index a29e9a0..c211516 100644 --- a/src/backtrace/mod.rs +++ b/src/backtrace/mod.rs @@ -1,6 +1,6 @@ use core::fmt::{self, Debug, Display}; -without_std! { +without_backtrace! { /// A `Backtrace`. /// /// This is an opaque wrapper around the backtrace provided by @@ -39,6 +39,16 @@ without_std! { pub fn new() -> Backtrace { Backtrace { _secret: () } } + + with_backtrace! { + pub(crate) fn none() -> Backtrace { + Backtrace { _secret: () } + } + + pub(crate) fn is_none(&self) -> bool { + true + } + } } impl Default for Backtrace { @@ -60,7 +70,7 @@ without_std! { } } -with_std! { +with_backtrace! { extern crate backtrace; mod internal; diff --git a/src/lib.rs b/src/lib.rs index 3789585..91db97b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -16,6 +16,12 @@ macro_rules! with_std { ($($i:item)*) => ($(#[cfg(feature = "std")]$i)*) } macro_rules! without_std { ($($i:item)*) => ($(#[cfg(not(feature = "std"))]$i)*) } +macro_rules! with_backtrace { + ($($i:item)*) => ($(#[cfg(all(feature = "backtrace", feature = "std"))]$i)*) +} +macro_rules! without_backtrace { + ($($i:item)*) => ($(#[cfg(any(not(feature = "backtrace"), not(feature = "std")))]$i)*) +} mod backtrace; mod compat; From 39545d06dce7fd23935dd77b01b887a7152f3a30 Mon Sep 17 00:00:00 2001 From: David Ross Date: Wed, 10 Jan 2018 16:26:29 -0800 Subject: [PATCH 2/2] Fix syntax error. --- src/backtrace/mod.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/backtrace/mod.rs b/src/backtrace/mod.rs index c211516..d24dfdf 100644 --- a/src/backtrace/mod.rs +++ b/src/backtrace/mod.rs @@ -40,14 +40,14 @@ without_backtrace! { Backtrace { _secret: () } } - with_backtrace! { - pub(crate) fn none() -> Backtrace { - Backtrace { _secret: () } - } - - pub(crate) fn is_none(&self) -> bool { - true - } + #[cfg(feature = "std")] + pub(crate) fn none() -> Backtrace { + Backtrace { _secret: () } + } + + #[cfg(feature = "std")] + pub(crate) fn is_none(&self) -> bool { + true } }