Skip to content

Commit 4cf22df

Browse files
sfacklerseanmonstar
authored andcommitted
feat(error): implement Error::source when available
Closes #1768
1 parent 0bf30cc commit 4cf22df

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ tokio-threadpool = { version = "0.1.3", optional = true }
3838
tokio-timer = { version = "0.2", optional = true }
3939
want = "0.0.6"
4040

41+
[build-dependencies]
42+
rustc_version = "0.2"
43+
4144
[dev-dependencies]
4245
futures-timer = "0.1"
4346
num_cpus = "1.0"

build.rs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
extern crate rustc_version;
2+
3+
use rustc_version::{version, Version};
4+
5+
fn main() {
6+
if version().unwrap() >= Version::parse("1.30.0").unwrap() {
7+
println!("cargo:rustc-cfg=error_source");
8+
}
9+
}

src/error.rs

+10
Original file line numberDiff line numberDiff line change
@@ -323,13 +323,23 @@ impl StdError for Error {
323323
}
324324
}
325325

326+
#[cfg(not(error_source))]
326327
fn cause(&self) -> Option<&StdError> {
327328
self
328329
.inner
329330
.cause
330331
.as_ref()
331332
.map(|cause| &**cause as &StdError)
332333
}
334+
335+
#[cfg(error_source)]
336+
fn source(&self) -> Option<&(StdError + 'static)> {
337+
self
338+
.inner
339+
.cause
340+
.as_ref()
341+
.map(|cause| &**cause as &(StdError + 'static))
342+
}
333343
}
334344

335345
#[doc(hidden)]

0 commit comments

Comments
 (0)