From 0ced932d64e5219e2e74866e4cc77e4dfa226dd2 Mon Sep 17 00:00:00 2001 From: David Ross Date: Wed, 19 Sep 2018 14:54:28 -0700 Subject: [PATCH 1/2] Add 'std2' feature. This enables someone to use 'std' features of failure without depending on the 'backtrace' crate. It's a bit hask-ish, but the 'std2' name is necessary to retain backwards compatibility within v0.1 where 'std' must be dependent on 'backtrace'. --- .travis.yml | 2 ++ Cargo.toml | 6 +++++- src/backtrace/mod.rs | 8 ++++---- src/error/mod.rs | 6 +++--- src/lib.rs | 12 ++++++------ src/result_ext.rs | 22 +++++++++++----------- travis.sh | 1 + 7 files changed, 32 insertions(+), 25 deletions(-) diff --git a/.travis.yml b/.travis.yml index 61d8965..f205473 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,4 +8,6 @@ cache: cargo script: - cargo test - cargo test --features backtrace + - cargo test --no-default-features --features std2,derive - cargo check --no-default-features + - cargo check --no-default-features --features std2 diff --git a/Cargo.toml b/Cargo.toml index d8c505a..2057ae2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,5 +23,9 @@ members = [".", "failure_derive"] [features] default = ["std", "derive"] #small-error = ["std"] -std = ["backtrace"] +std = ["backtrace", "std2"] +# temporary feature to enable 'std' without enabling 'backtrace' while still keeping backwards +# compatibility ("std" has always depended on "backtrace" and it would be a breaking change to +# change that) +std2 = [] derive = ["failure_derive"] diff --git a/src/backtrace/mod.rs b/src/backtrace/mod.rs index 58f0477..3a0960e 100644 --- a/src/backtrace/mod.rs +++ b/src/backtrace/mod.rs @@ -1,7 +1,7 @@ use core::fmt::{self, Debug, Display}; -macro_rules! with_backtrace { ($($i:item)*) => ($(#[cfg(all(feature = "backtrace", feature = "std"))]$i)*) } -macro_rules! without_backtrace { ($($i:item)*) => ($(#[cfg(not(all(feature = "backtrace", feature = "std")))]$i)*) } +macro_rules! with_backtrace { ($($i:item)*) => ($(#[cfg(all(feature = "backtrace", feature = "std2"))]$i)*) } +macro_rules! without_backtrace { ($($i:item)*) => ($(#[cfg(not(all(feature = "backtrace", feature = "std2")))]$i)*) } without_backtrace! { /// A `Backtrace`. @@ -43,12 +43,12 @@ without_backtrace! { Backtrace { _secret: () } } - #[cfg(feature = "std")] + #[cfg(feature = "std2")] pub(crate) fn none() -> Backtrace { Backtrace { _secret: () } } - #[cfg(feature = "std")] + #[cfg(feature = "std2")] pub(crate) fn is_none(&self) -> bool { true } diff --git a/src/error/mod.rs b/src/error/mod.rs index 04c0303..d9cd5de 100644 --- a/src/error/mod.rs +++ b/src/error/mod.rs @@ -5,14 +5,14 @@ use backtrace::Backtrace; use context::Context; use compat::Compat; -#[cfg(feature = "std")] +#[cfg(feature = "std2")] use box_std::BoxStd; #[cfg_attr(feature = "small-error", path = "./error_impl_small.rs")] mod error_impl; use self::error_impl::ErrorImpl; -#[cfg(feature = "std")] +#[cfg(feature = "std2")] use std::error::Error as StdError; @@ -59,7 +59,7 @@ impl Error { /// Ok(92) /// } /// ``` - #[cfg(feature = "std")] + #[cfg(feature = "std2")] pub fn from_boxed_compat(err: Box) -> Error { Error::from(BoxStd(err)) } diff --git a/src/lib.rs b/src/lib.rs index 1002e76..1104165 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -20,13 +20,13 @@ //! variable to a non-zero value (this also enables backtraces for panics). //! Use the `RUST_FAILURE_BACKTRACE` variable to enable or disable backtraces //! for `failure` specifically. -#![cfg_attr(not(feature = "std"), no_std)] +#![cfg_attr(not(feature = "std2"), no_std)] #![deny(missing_docs)] #![deny(warnings)] #![cfg_attr(feature = "small-error", feature(extern_types, allocator_api))] -macro_rules! with_std { ($($i:item)*) => ($(#[cfg(feature = "std")]$i)*) } -macro_rules! without_std { ($($i:item)*) => ($(#[cfg(not(feature = "std"))]$i)*) } +macro_rules! with_std { ($($i:item)*) => ($(#[cfg(feature = "std2")]$i)*) } +macro_rules! without_std { ($($i:item)*) => ($(#[cfg(not(feature = "std2"))]$i)*) } // Re-export libcore using an alias so that the macros can work without // requiring `extern crate core` downstream. @@ -34,7 +34,7 @@ macro_rules! without_std { ($($i:item)*) => ($(#[cfg(not(feature = "std"))]$i)*) pub extern crate core as _core; mod backtrace; -#[cfg(feature = "std")] +#[cfg(feature = "std2")] mod box_std; mod compat; mod context; @@ -251,10 +251,10 @@ impl Fail { } } -#[cfg(feature = "std")] +#[cfg(feature = "std2")] impl Fail for E {} -#[cfg(feature = "std")] +#[cfg(feature = "std2")] impl Fail for Box { fn cause(&self) -> Option<&Fail> { (**self).cause() diff --git a/src/result_ext.rs b/src/result_ext.rs index f4125cd..6c286a1 100644 --- a/src/result_ext.rs +++ b/src/result_ext.rs @@ -14,9 +14,9 @@ pub trait ResultExt { /// # tests::run_test(); /// # } /// # - /// # #[cfg(not(all(feature = "std", feature = "derive")))] mod tests { pub fn run_test() { } } - /// # - /// # #[cfg(all(feature = "std", feature = "derive"))] mod tests { + /// # #[cfg(not(all(feature = "std2", feature = "derive")))] mod tests { pub fn run_test() { } } + /// # + /// # #[cfg(all(feature = "std2", feature = "derive"))] mod tests { /// use std::error::Error; /// # use std::fmt; /// # @@ -65,19 +65,19 @@ pub trait ResultExt { /// # Examples /// /// ``` - /// # #[cfg(all(feature = "std", feature = "derive"))] + /// # #[cfg(all(feature = "std2", feature = "derive"))] /// # #[macro_use] extern crate failure; /// # - /// # #[cfg(all(feature = "std", feature = "derive"))] + /// # #[cfg(all(feature = "std2", feature = "derive"))] /// # #[macro_use] extern crate failure_derive; /// # /// # fn main() { /// # tests::run_test(); /// # } /// # - /// # #[cfg(not(all(feature = "std", feature = "derive")))] mod tests { pub fn run_test() { } } + /// # #[cfg(not(all(feature = "std2", feature = "derive")))] mod tests { pub fn run_test() { } } /// # - /// # #[cfg(all(feature = "std", feature = "derive"))] mod tests { + /// # #[cfg(all(feature = "std2", feature = "derive"))] mod tests { /// # /// # use failure::{self, ResultExt}; /// # @@ -108,19 +108,19 @@ pub trait ResultExt { /// # Examples /// /// ``` - /// # #[cfg(all(feature = "std", feature = "derive"))] + /// # #[cfg(all(feature = "std2", feature = "derive"))] /// # #[macro_use] extern crate failure; /// # - /// # #[cfg(all(feature = "std", feature = "derive"))] + /// # #[cfg(all(feature = "std2", feature = "derive"))] /// # #[macro_use] extern crate failure_derive; /// # /// # fn main() { /// # tests::run_test(); /// # } /// # - /// # #[cfg(not(all(feature = "std", feature = "derive")))] mod tests { pub fn run_test() { } } + /// # #[cfg(not(all(feature = "std2", feature = "derive")))] mod tests { pub fn run_test() { } } /// # - /// # #[cfg(all(feature = "std", feature = "derive"))] mod tests { + /// # #[cfg(all(feature = "std2", feature = "derive"))] mod tests { /// # /// # use failure::{self, ResultExt}; /// # diff --git a/travis.sh b/travis.sh index 6c621ca..a194eac 100644 --- a/travis.sh +++ b/travis.sh @@ -10,6 +10,7 @@ test_failure_in() { cd $1 cargo_test cargo_test --no-default-features + cargo_test --features std2,derive cargo_test --features backtrace test_derive_in "$1/failure_derive" cd $DIR From 9512f8a032120b492423fd3cb09dbe140d3ca669 Mon Sep 17 00:00:00 2001 From: David Ross Date: Wed, 19 Sep 2018 15:13:32 -0700 Subject: [PATCH 2/2] Use rust 1.18.0 compatible syntax in .travis.yml. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index f205473..014c866 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,6 +8,6 @@ cache: cargo script: - cargo test - cargo test --features backtrace - - cargo test --no-default-features --features std2,derive + - cargo test --no-default-features --features "std2 derive" - cargo check --no-default-features - cargo check --no-default-features --features std2