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

Commit

Permalink
allow Error::description to be used for rust below 1.42 (#285)
Browse files Browse the repository at this point in the history
  • Loading branch information
AnderEnder authored and AndyGauge committed Jan 14, 2020
1 parent d31288b commit ea81711
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
4 changes: 4 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ fn main() {
println!("cargo:rustc-cfg=has_error_source");
}

if is_min_version("1.42").unwrap_or(false) {
println!("cargo:rustc-cfg=has_error_description_deprecated");
}

// So we can get the build profile for has_backtrace_depending_on_env test
if let Ok(profile) = env::var("PROFILE") {
println!("cargo:rustc-cfg=build={:?}", profile);
Expand Down
18 changes: 17 additions & 1 deletion src/error_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,21 @@ macro_rules! impl_error_chain_cause_or_source {
};
}

/// Conditional usage of deprecated Error::description
#[doc(hidden)]
#[cfg(has_error_description_deprecated)]
#[macro_export(local_inner_macros)]
macro_rules! call_to_deprecated_description {
($e:ident) => { "" };
}

#[doc(hidden)]
#[cfg(not(has_error_description_deprecated))]
#[macro_export(local_inner_macros)]
macro_rules! call_to_deprecated_description {
($e:ident) => { ::std::error::Error::description($e) };
}

/// Prefer to use `error_chain` instead of this macro.
#[doc(hidden)]
#[macro_export(local_inner_macros)]
Expand Down Expand Up @@ -301,6 +316,7 @@ macro_rules! impl_error_chain_processed {
}

impl ::std::error::Error for $error_name {
#[cfg(not(has_error_description_deprecated))]
fn description(&self) -> &str {
self.description()
}
Expand Down Expand Up @@ -369,7 +385,7 @@ macro_rules! impl_error_chain_processed {
$(
$(#[$meta_foreign_links])*
$foreign_link_variant(err: $foreign_link_error_path) {
description(::std::error::Error::description(err))
description(call_to_deprecated_description!(err))
display("{}", err)
}
) *
Expand Down

0 comments on commit ea81711

Please sign in to comment.