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

Commit ea81711

Browse files
AnderEnderAndyGauge
authored andcommitted
allow Error::description to be used for rust below 1.42 (#285)
1 parent d31288b commit ea81711

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

build.rs

+4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ fn main() {
1010
println!("cargo:rustc-cfg=has_error_source");
1111
}
1212

13+
if is_min_version("1.42").unwrap_or(false) {
14+
println!("cargo:rustc-cfg=has_error_description_deprecated");
15+
}
16+
1317
// So we can get the build profile for has_backtrace_depending_on_env test
1418
if let Ok(profile) = env::var("PROFILE") {
1519
println!("cargo:rustc-cfg=build={:?}", profile);

src/error_chain.rs

+17-1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,21 @@ macro_rules! impl_error_chain_cause_or_source {
6868
};
6969
}
7070

71+
/// Conditional usage of deprecated Error::description
72+
#[doc(hidden)]
73+
#[cfg(has_error_description_deprecated)]
74+
#[macro_export(local_inner_macros)]
75+
macro_rules! call_to_deprecated_description {
76+
($e:ident) => { "" };
77+
}
78+
79+
#[doc(hidden)]
80+
#[cfg(not(has_error_description_deprecated))]
81+
#[macro_export(local_inner_macros)]
82+
macro_rules! call_to_deprecated_description {
83+
($e:ident) => { ::std::error::Error::description($e) };
84+
}
85+
7186
/// Prefer to use `error_chain` instead of this macro.
7287
#[doc(hidden)]
7388
#[macro_export(local_inner_macros)]
@@ -301,6 +316,7 @@ macro_rules! impl_error_chain_processed {
301316
}
302317

303318
impl ::std::error::Error for $error_name {
319+
#[cfg(not(has_error_description_deprecated))]
304320
fn description(&self) -> &str {
305321
self.description()
306322
}
@@ -369,7 +385,7 @@ macro_rules! impl_error_chain_processed {
369385
$(
370386
$(#[$meta_foreign_links])*
371387
$foreign_link_variant(err: $foreign_link_error_path) {
372-
description(::std::error::Error::description(err))
388+
description(call_to_deprecated_description!(err))
373389
display("{}", err)
374390
}
375391
) *

0 commit comments

Comments
 (0)