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

Commit 2374ed1

Browse files
committed
Fix variant attributes handling.
1 parent df3f533 commit 2374ed1

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

src/error_chain.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ macro_rules! error_chain_processed {
5959
pub state: $crate::State,
6060
}
6161

62-
impl_error!($error_name $error_kind_name $($link_error_path)*);
62+
impl_error!($error_name
63+
$error_kind_name
64+
$([$link_error_path, $(#[$meta_links])*])*);
6365

6466
impl $error_name {
6567
/// Constructs an error from a kind.
@@ -300,7 +302,7 @@ macro_rules! error_chain {
300302
macro_rules! impl_error {
301303
($error_name: ident
302304
$error_kind_name: ident
303-
$($link_error_path: path)*) => {
305+
$([$link_error_path: path, $(#[$meta_links: meta])*])*) => {
304306
impl $error_name {
305307
/// Returns the backtrace associated with this error.
306308
pub fn backtrace(&self) -> Option<&$crate::Backtrace> {
@@ -321,16 +323,17 @@ macro_rules! impl_error {
321323
fn extract_backtrace(e: &(::std::error::Error + Send + 'static))
322324
-> Option<Option<::std::sync::Arc<$crate::Backtrace>>> {
323325
if let Some(e) = e.downcast_ref::<$error_name>() {
324-
Some(e.state.backtrace.clone())
326+
return Some(e.state.backtrace.clone());
325327
}
326328
$(
327-
else if let Some(e) = e.downcast_ref::<$link_error_path>() {
328-
Some(e.state.backtrace.clone())
329+
$( #[$meta_links] )*
330+
{
331+
if let Some(e) = e.downcast_ref::<$link_error_path>() {
332+
return Some(e.state.backtrace.clone());
333+
}
329334
}
330335
) *
331-
else {
332-
None
333-
}
336+
None
334337
}
335338
}
336339
}
@@ -347,7 +350,7 @@ macro_rules! impl_error {
347350
macro_rules! impl_error {
348351
($error_name: ident
349352
$error_kind_name: ident
350-
$($link_error_path: path)*) => {
353+
$([$link_error_path: path, $(#[$meta_links: meta])*])*) => {
351354
impl $crate::ChainedError for $error_name {
352355
type ErrorKind = $error_kind_name;
353356

tests/tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@ mod attributes_test {
369369
#[allow(unused_imports)]
370370
use std::io;
371371

372+
#[cfg(not(test))]
372373
mod inner {
373374
error_chain! {
374375

0 commit comments

Comments
 (0)