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

Commit fd24f31

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

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
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

+27
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ macro_rules! impl_error_chain_processed {
301301
}
302302

303303
impl ::std::error::Error for $error_name {
304+
#[cfg(not(has_error_description_deprecated))]
304305
fn description(&self) -> &str {
305306
self.description()
306307
}
@@ -354,6 +355,7 @@ macro_rules! impl_error_chain_processed {
354355
// The ErrorKind type
355356
// --------------
356357

358+
#[cfg(not(has_error_description_deprecated))]
357359
impl_error_chain_kind! {
358360
/// The kind of an error.
359361
#[derive(Debug)]
@@ -378,6 +380,31 @@ macro_rules! impl_error_chain_processed {
378380
}
379381
}
380382

383+
#[cfg(has_error_description_deprecated)]
384+
impl_error_chain_kind! {
385+
/// The kind of an error.
386+
#[derive(Debug)]
387+
pub enum $error_kind_name {
388+
$(
389+
$(#[$meta_links])*
390+
$link_variant(e: $link_kind_path) {
391+
description(e.description())
392+
display("{}", e)
393+
}
394+
) *
395+
396+
$(
397+
$(#[$meta_foreign_links])*
398+
$foreign_link_variant(err: $foreign_link_error_path) {
399+
description("")
400+
display("{}", err)
401+
}
402+
) *
403+
404+
$($error_chunks)*
405+
}
406+
}
407+
381408
$(
382409
$(#[$meta_links])*
383410
impl From<$link_kind_path> for $error_kind_name {

0 commit comments

Comments
 (0)