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

Commit db7d2d5

Browse files
committed
has_error_source flag used outside macro + reformat + rename
1 parent caec9fc commit db7d2d5

File tree

1 file changed

+34
-31
lines changed

1 file changed

+34
-31
lines changed

src/error_chain.rs

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,51 @@
11
#[doc(hidden)]
22
#[macro_export]
33
#[cfg(not(has_error_source))]
4-
macro_rules! impl_error_chain_source {
4+
macro_rules! impl_error_chain_cause_or_source {
55
(
6-
types {
6+
types {
77
$error_kind_name:ident
8-
}
9-
foreign_links {
10-
$( $foreign_link_variant:ident ( $foreign_link_error_path:path )
11-
$( #[$meta_foreign_links:meta] )*; )*
12-
}) => {
13-
14-
#[allow(unknown_lints, renamed_and_removed_lints, unused_doc_comment, unused_doc_comments)]
15-
fn cause(&self) -> Option<&::std::error::Error> {
16-
match self.1.next_error {
17-
Some(ref c) => Some(&**c),
18-
None => {
19-
match self.0 {
20-
$(
21-
$(#[$meta_foreign_links])*
22-
$error_kind_name::$foreign_link_variant(ref foreign_err) => {
23-
foreign_err.cause()
24-
}
25-
) *
26-
_ => None
8+
}
9+
10+
foreign_links {
11+
$( $foreign_link_variant:ident ( $foreign_link_error_path:path )
12+
$( #[$meta_foreign_links:meta] )*; )*
13+
}
14+
) => {
15+
#[allow(unknown_lints, renamed_and_removed_lints, unused_doc_comment, unused_doc_comments)]
16+
fn cause(&self) -> Option<&::std::error::Error> {
17+
match self.1.next_error {
18+
Some(ref c) => Some(&**c),
19+
None => {
20+
match self.0 {
21+
$(
22+
$(#[$meta_foreign_links])*
23+
$error_kind_name::$foreign_link_variant(ref foreign_err) => {
24+
foreign_err.cause()
25+
}
26+
) *
27+
_ => None
28+
}
2729
}
2830
}
2931
}
30-
}
3132
};
3233
}
3334

3435
#[cfg(has_error_source)]
3536
#[doc(hidden)]
3637
#[macro_export]
37-
macro_rules! impl_error_chain_source {
38+
macro_rules! impl_error_chain_cause_or_source {
3839
(
39-
types {
40-
$error_kind_name:ident
41-
}
42-
foreign_links {
43-
$( $foreign_link_variant:ident ( $foreign_link_error_path:path )
44-
$( #[$meta_foreign_links:meta] )*; )*
45-
}) => {
40+
types {
41+
$error_kind_name:ident
42+
}
43+
44+
foreign_links {
45+
$( $foreign_link_variant:ident ( $foreign_link_error_path:path )
46+
$( #[$meta_foreign_links:meta] )*; )*
47+
}
48+
) => {
4649

4750
#[allow(unknown_lints, renamed_and_removed_lints, unused_doc_comment, unused_doc_comments)]
4851
fn source(&self) -> Option<&(std::error::Error + 'static)> {
@@ -245,7 +248,7 @@ macro_rules! impl_error_chain_processed {
245248
self.description()
246249
}
247250

248-
$crate::impl_error_chain_source!{
251+
$crate::impl_error_chain_cause_or_source!{
249252
types {
250253
$error_kind_name
251254
}

0 commit comments

Comments
 (0)