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

Use Error::description only for rust below 1.42 #285

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) };
}
Comment on lines +79 to +84
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this need a doc comment, too? Wouldn't #![deny(missing_documentation)] trigger in case not(has_error_description_deprecated)?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's why CI fails.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested, it fails and reverted it back


/// 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