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

Commit 11dd09a

Browse files
committed
allow Error::description to be used for rust below 1.42
1 parent d31288b commit 11dd09a

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-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

+16-1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,20 @@ 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+
#[cfg(not(has_error_description_deprecated))]
80+
#[macro_export(local_inner_macros)]
81+
macro_rules! call_to_deprecated_description {
82+
($e:ident) => { ::std::error::Error::description($e) };
83+
}
84+
7185
/// Prefer to use `error_chain` instead of this macro.
7286
#[doc(hidden)]
7387
#[macro_export(local_inner_macros)]
@@ -301,6 +315,7 @@ macro_rules! impl_error_chain_processed {
301315
}
302316

303317
impl ::std::error::Error for $error_name {
318+
#[cfg(not(has_error_description_deprecated))]
304319
fn description(&self) -> &str {
305320
self.description()
306321
}
@@ -369,7 +384,7 @@ macro_rules! impl_error_chain_processed {
369384
$(
370385
$(#[$meta_foreign_links])*
371386
$foreign_link_variant(err: $foreign_link_error_path) {
372-
description(::std::error::Error::description(err))
387+
description(call_to_deprecated_description!(err))
373388
display("{}", err)
374389
}
375390
) *

0 commit comments

Comments
 (0)