Skip to content
This repository was archived by the owner on Aug 16, 2021. It is now read-only.

Make error_chain with default-features = false work with Rust 1.10 #103

Merged
merged 2 commits into from
Dec 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 11 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ rust:
- stable
- beta
- nightly
# Oldest supported version.
# Oldest supported version for all features.
# Use of https://github.com/rust-lang/rfcs/pull/16
- 1.13.0
# Oldest supported version as dependency, with no features, tests, or examples.
- 1.10.0

sudo: false
cache: cargo
Expand All @@ -22,8 +24,8 @@ before_script:
export PATH=$HOME/.local/bin:$PATH

script:
- cargo build --verbose $FEATURES
- cargo test --verbose $FEATURES
- travis-cargo build -- $FEATURES
- travis-cargo --skip 1.10.0 test -- $FEATURES

after_success:
- travis-cargo --only stable doc
Expand All @@ -32,6 +34,12 @@ after_success:
env:
global:
- secure: ncxJbvJM1vCZfcEftjsFKJMxxhKLgWKaR8Go9AMo0VB5fB2XVW/6NYO5bQEEYpOf1Nc/+2FbI2+Dkz0S/mJpUcNSfBgablCHgwU2sHse7KsoaqfHj2mf1E3exjzSHoP96hPGicC5zAjSXFjCgJPOUSGqqRaJ7z5AsJLhJT6LuK7QpvwPBZzklUN8T+n1sVmws8TNmRIbaniq/q6wYHANHcy6Dl59dx4sKwniUGiZdUhCiddVpoxbECSxc0A8mN2pk7/aW+WGxK3goBs5ZF7+JXF318F62pDcXQmR5CX6WdpenIcJ25g1Vg1WhQ4Ifpe17CN0bfxV8ShuzrQUThCDMffZCo9XySBtODdEowwK1UIpjnFLfIxjOs45Cd8o3tM2j0CfvtnjOz6BCdUU0qiwNPPNx0wFkx3ZiOfSh+FhBhvyPM12HN2tdN0esgVBItFmEci+sSIIXqjVL6DNiu5zTjbu0bs6COwlUWdmL6vmsZtq5tl7Cno9+C3szxRVAkShGydd04l9NYjqNEzTa1EPG50OsnVRKGdRiFzSxhc3BWExNKvcQ4v867t6/PpPkW6s4oXmYI3+De+8O7ExWc6a4alcrDXKlMs5fCb5Pcd4Ju9kowcjkoJo5yf2wW3Ox5R8SJpaEEpvyhx5O/qtIxjhHNzeo8Wsr/6gdNDv20r91TI=
- TRAVIS_CARGO_NIGHTLY_FEATURE=""
matrix:
- FEATURES=--features=backtrace
- FEATURES=--no-default-features

matrix:
exclude:
- env: FEATURES=--features=backtrace
rust: 1.10.0
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ to error-chain.
Please view the beginning of the [Travis configuration file](.travis.yml)
to see the oldest supported Rust version.

Note that `error-chain` supports older versions of Rust when built with
`default-features = false`.

## License

MIT/Apache-2.0
49 changes: 27 additions & 22 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,42 +455,47 @@ pub struct State {
}

impl Default for State {
#[cfg(feature = "backtrace")]
fn default() -> State {
#[cfg(feature = "backtrace")]
let state = State {
State {
next_error: None,
backtrace: make_backtrace(),
};
#[cfg(not(feature = "backtrace"))]
let state = State { next_error: None };
state
}
}

#[cfg(not(feature = "backtrace"))]
fn default() -> State {
State { next_error: None }
}
}

impl State {
/// Creates a new State type
#[cfg(feature = "backtrace")]
pub fn new<CE: ChainedError>(e: Box<error::Error + Send>) -> State {
#[cfg(feature = "backtrace")]
let state = {
let backtrace = CE::extract_backtrace(&*e).or_else(make_backtrace);
State {
next_error: Some(e),
backtrace: backtrace,
}
};
#[cfg(not(feature = "backtrace"))]
let state = State { next_error: Some(e) };
let backtrace = CE::extract_backtrace(&*e).or_else(make_backtrace);
State {
next_error: Some(e),
backtrace: backtrace,
}
}

/// Creates a new State type
#[cfg(not(feature = "backtrace"))]
pub fn new<CE: ChainedError>(e: Box<error::Error + Send>) -> State {
State { next_error: Some(e) }
}

state
/// Returns the inner backtrace if present.
#[cfg(feature = "backtrace")]
pub fn backtrace(&self) -> Option<&Backtrace> {
self.backtrace.as_ref().map(|v| &**v)
}

/// Returns the inner backtrace if present.
#[cfg(not(feature = "backtrace"))]
pub fn backtrace(&self) -> Option<&Backtrace> {
#[cfg(feature = "backtrace")]
let b = self.backtrace.as_ref().map(|v| &**v);
#[cfg(not(feature = "backtrace"))]
let b = None;
b
None
}
}

Expand Down