|
1 | | -/// Prefer to use `error_chain` instead of this macro. |
2 | 1 | #[doc(hidden)] |
3 | 2 | #[macro_export] |
| 3 | +#[cfg(not(has_error_source))] |
| 4 | +macro_rules! impl_error_chain_cause_or_source { |
| 5 | + ( |
| 6 | + types { |
| 7 | + $error_kind_name:ident |
| 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)] |
| 16 | + #[allow(unused_doc_comment, unused_doc_comments)] |
| 17 | + fn cause(&self) -> Option<&::std::error::Error> { |
| 18 | + match self.1.next_error { |
| 19 | + Some(ref c) => Some(&**c), |
| 20 | + None => { |
| 21 | + match self.0 { |
| 22 | + $( |
| 23 | + $(#[$meta_foreign_links])* |
| 24 | + $error_kind_name::$foreign_link_variant(ref foreign_err) => { |
| 25 | + foreign_err.cause() |
| 26 | + } |
| 27 | + ) * |
| 28 | + _ => None |
| 29 | + } |
| 30 | + } |
| 31 | + } |
| 32 | + } |
| 33 | + }; |
| 34 | +} |
| 35 | + |
| 36 | +#[cfg(has_error_source)] |
| 37 | +#[doc(hidden)] |
| 38 | +#[macro_export] |
| 39 | +macro_rules! impl_error_chain_cause_or_source { |
| 40 | + ( |
| 41 | + types { |
| 42 | + $error_kind_name:ident |
| 43 | + } |
| 44 | + |
| 45 | + foreign_links { |
| 46 | + $( $foreign_link_variant:ident ( $foreign_link_error_path:path ) |
| 47 | + $( #[$meta_foreign_links:meta] )*; )* |
| 48 | + } |
| 49 | + ) => { |
| 50 | + #[allow(unknown_lints, renamed_and_removed_lints)] |
| 51 | + #[allow(unused_doc_comment, unused_doc_comments)] |
| 52 | + fn source(&self) -> Option<&(std::error::Error + 'static)> { |
| 53 | + match self.1.next_error { |
| 54 | + Some(ref c) => Some(&**c), |
| 55 | + None => { |
| 56 | + match self.0 { |
| 57 | + $( |
| 58 | + $(#[$meta_foreign_links])* |
| 59 | + $error_kind_name::$foreign_link_variant(ref foreign_err) => { |
| 60 | + foreign_err.source() |
| 61 | + } |
| 62 | + ) * |
| 63 | + _ => None |
| 64 | + } |
| 65 | + } |
| 66 | + } |
| 67 | + } |
| 68 | + }; |
| 69 | +} |
| 70 | + |
| 71 | +/// Prefer to use `error_chain` instead of this macro. |
| 72 | +#[doc(hidden)] |
| 73 | +#[macro_export(local_inner_macros)] |
4 | 74 | macro_rules! impl_error_chain_processed { |
5 | 75 | // Default values for `types`. |
6 | 76 | ( |
@@ -179,22 +249,13 @@ macro_rules! impl_error_chain_processed { |
179 | 249 | self.description() |
180 | 250 | } |
181 | 251 |
|
182 | | - #[allow(unknown_lints, renamed_and_removed_lints)] |
183 | | - #[allow(unused_doc_comment, unused_doc_comments)] |
184 | | - fn cause(&self) -> Option<&::std::error::Error> { |
185 | | - match self.1.next_error { |
186 | | - Some(ref c) => Some(&**c), |
187 | | - None => { |
188 | | - match self.0 { |
189 | | - $( |
190 | | - $(#[$meta_foreign_links])* |
191 | | - $error_kind_name::$foreign_link_variant(ref foreign_err) => { |
192 | | - foreign_err.cause() |
193 | | - } |
194 | | - ) * |
195 | | - _ => None |
196 | | - } |
197 | | - } |
| 252 | + impl_error_chain_cause_or_source!{ |
| 253 | + types { |
| 254 | + $error_kind_name |
| 255 | + } |
| 256 | + foreign_links { |
| 257 | + $( $foreign_link_variant ( $foreign_link_error_path ) |
| 258 | + $( #[$meta_foreign_links] )*; )* |
198 | 259 | } |
199 | 260 | } |
200 | 261 | } |
@@ -348,7 +409,7 @@ macro_rules! impl_error_chain_processed { |
348 | 409 |
|
349 | 410 | /// Internal macro used for reordering of the fields. |
350 | 411 | #[doc(hidden)] |
351 | | -#[macro_export] |
| 412 | +#[macro_export(local_inner_macros)] |
352 | 413 | macro_rules! error_chain_processing { |
353 | 414 | ( |
354 | 415 | ({}, $b:tt, $c:tt, $d:tt) |
@@ -401,7 +462,7 @@ macro_rules! error_chain_processing { |
401 | 462 | } |
402 | 463 |
|
403 | 464 | /// Macro for generating error types and traits. See crate level documentation for details. |
404 | | -#[macro_export] |
| 465 | +#[macro_export(local_inner_macros)] |
405 | 466 | macro_rules! error_chain { |
406 | 467 | ( $( $block_name:ident { $( $block_content:tt )* } )* ) => { |
407 | 468 | error_chain_processing! { |
|
0 commit comments