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

Commit 98c1a5d

Browse files
authored
Merge pull request #103 from joshtriplett/rust-1.10
Make error_chain with default-features = false work with Rust 1.10
2 parents 302c7d5 + 38def8e commit 98c1a5d

File tree

3 files changed

+41
-25
lines changed

3 files changed

+41
-25
lines changed

.travis.yml

+11-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ rust:
33
- stable
44
- beta
55
- nightly
6-
# Oldest supported version.
6+
# Oldest supported version for all features.
77
# Use of https://github.com/rust-lang/rfcs/pull/16
88
- 1.13.0
9+
# Oldest supported version as dependency, with no features, tests, or examples.
10+
- 1.10.0
911

1012
sudo: false
1113
cache: cargo
@@ -22,8 +24,8 @@ before_script:
2224
export PATH=$HOME/.local/bin:$PATH
2325
2426
script:
25-
- cargo build --verbose $FEATURES
26-
- cargo test --verbose $FEATURES
27+
- travis-cargo build -- $FEATURES
28+
- travis-cargo --skip 1.10.0 test -- $FEATURES
2729

2830
after_success:
2931
- travis-cargo --only stable doc
@@ -32,6 +34,12 @@ after_success:
3234
env:
3335
global:
3436
- secure: ncxJbvJM1vCZfcEftjsFKJMxxhKLgWKaR8Go9AMo0VB5fB2XVW/6NYO5bQEEYpOf1Nc/+2FbI2+Dkz0S/mJpUcNSfBgablCHgwU2sHse7KsoaqfHj2mf1E3exjzSHoP96hPGicC5zAjSXFjCgJPOUSGqqRaJ7z5AsJLhJT6LuK7QpvwPBZzklUN8T+n1sVmws8TNmRIbaniq/q6wYHANHcy6Dl59dx4sKwniUGiZdUhCiddVpoxbECSxc0A8mN2pk7/aW+WGxK3goBs5ZF7+JXF318F62pDcXQmR5CX6WdpenIcJ25g1Vg1WhQ4Ifpe17CN0bfxV8ShuzrQUThCDMffZCo9XySBtODdEowwK1UIpjnFLfIxjOs45Cd8o3tM2j0CfvtnjOz6BCdUU0qiwNPPNx0wFkx3ZiOfSh+FhBhvyPM12HN2tdN0esgVBItFmEci+sSIIXqjVL6DNiu5zTjbu0bs6COwlUWdmL6vmsZtq5tl7Cno9+C3szxRVAkShGydd04l9NYjqNEzTa1EPG50OsnVRKGdRiFzSxhc3BWExNKvcQ4v867t6/PpPkW6s4oXmYI3+De+8O7ExWc6a4alcrDXKlMs5fCb5Pcd4Ju9kowcjkoJo5yf2wW3Ox5R8SJpaEEpvyhx5O/qtIxjhHNzeo8Wsr/6gdNDv20r91TI=
37+
- TRAVIS_CARGO_NIGHTLY_FEATURE=""
3538
matrix:
3639
- FEATURES=--features=backtrace
3740
- FEATURES=--no-default-features
41+
42+
matrix:
43+
exclude:
44+
- env: FEATURES=--features=backtrace
45+
rust: 1.10.0

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ to error-chain.
2828
Please view the beginning of the [Travis configuration file](.travis.yml)
2929
to see the oldest supported Rust version.
3030

31+
Note that `error-chain` supports older versions of Rust when built with
32+
`default-features = false`.
33+
3134
## License
3235

3336
MIT/Apache-2.0

src/lib.rs

+27-22
Original file line numberDiff line numberDiff line change
@@ -455,42 +455,47 @@ pub struct State {
455455
}
456456

457457
impl Default for State {
458+
#[cfg(feature = "backtrace")]
458459
fn default() -> State {
459-
#[cfg(feature = "backtrace")]
460-
let state = State {
460+
State {
461461
next_error: None,
462462
backtrace: make_backtrace(),
463-
};
464-
#[cfg(not(feature = "backtrace"))]
465-
let state = State { next_error: None };
466-
state
463+
}
464+
}
465+
466+
#[cfg(not(feature = "backtrace"))]
467+
fn default() -> State {
468+
State { next_error: None }
467469
}
468470
}
469471

470472
impl State {
471473
/// Creates a new State type
474+
#[cfg(feature = "backtrace")]
472475
pub fn new<CE: ChainedError>(e: Box<error::Error + Send>) -> State {
473-
#[cfg(feature = "backtrace")]
474-
let state = {
475-
let backtrace = CE::extract_backtrace(&*e).or_else(make_backtrace);
476-
State {
477-
next_error: Some(e),
478-
backtrace: backtrace,
479-
}
480-
};
481-
#[cfg(not(feature = "backtrace"))]
482-
let state = State { next_error: Some(e) };
476+
let backtrace = CE::extract_backtrace(&*e).or_else(make_backtrace);
477+
State {
478+
next_error: Some(e),
479+
backtrace: backtrace,
480+
}
481+
}
482+
483+
/// Creates a new State type
484+
#[cfg(not(feature = "backtrace"))]
485+
pub fn new<CE: ChainedError>(e: Box<error::Error + Send>) -> State {
486+
State { next_error: Some(e) }
487+
}
483488

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

487495
/// Returns the inner backtrace if present.
496+
#[cfg(not(feature = "backtrace"))]
488497
pub fn backtrace(&self) -> Option<&Backtrace> {
489-
#[cfg(feature = "backtrace")]
490-
let b = self.backtrace.as_ref().map(|v| &**v);
491-
#[cfg(not(feature = "backtrace"))]
492-
let b = None;
493-
b
498+
None
494499
}
495500
}
496501

0 commit comments

Comments
 (0)