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

Commit 855337e

Browse files
committed
[WIP] Fix #63
1 parent dcf1d1d commit 855337e

File tree

2 files changed

+43
-9
lines changed

2 files changed

+43
-9
lines changed

src/error_chain.rs

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ macro_rules! error_chain_processed {
3636
}
3737

3838
links {
39-
$( $link_variant:ident ( $link_error_path:path )
40-
$( #[$meta_links:meta] )*; ) *
39+
$( [$( #[$meta_links:meta] )*]
40+
$link_variant:ident ( $link_error_path:path ); ) *
4141
}
4242

4343
foreign_links {
44-
$( $foreign_link_variant:ident ( $foreign_link_error_path:path )
45-
$( #[$meta_foreign_links:meta] )*; )*
44+
$( [$( #[$meta_foreign_links:meta] )*]
45+
$foreign_link_variant:ident ( $foreign_link_error_path:path ); )*
4646
}
4747

4848
errors {
@@ -251,6 +251,38 @@ macro_rules! error_chain_processed {
251251
};
252252
}
253253

254+
/// Internal macro used for reordering of the fields.
255+
#[doc(hidden)]
256+
#[macro_export]
257+
macro_rules! handle_attributes {
258+
( { $($inner: tt)* } ) => {
259+
handle_attributes!([] { $($inner)* } {})
260+
};
261+
( [ $($attrs: tt)* ]
262+
{ #[$attr: meta] $( $to_parse:tt )* }
263+
{ $( $already_parsed:tt )* } ) => {
264+
handle_attributes!([ $( $attrs )* #[$attr] ]
265+
{ $( $to_parse )* }
266+
{ $( $already_parsed )* })
267+
};
268+
( [ $($attrs: tt)* ]
269+
{ $name:ident ( $variant:path ) $( $to_parse:tt )* }
270+
{ $already_parsed:tt } ) => {
271+
handle_attributes!([]
272+
{ $( $to_parse )* }
273+
{ $( $already_parsed )*
274+
[ $( $attrs )* ]
275+
$name ( $variant )})
276+
};
277+
( []
278+
{}
279+
{ $( $parsed:tt )* }) => {
280+
{
281+
$( $parsed )*
282+
}
283+
};
284+
}
285+
254286
/// Internal macro used for reordering of the fields.
255287
#[doc(hidden)]
256288
#[macro_export]
@@ -261,7 +293,7 @@ macro_rules! error_chain_processing {
261293
$( $tail:tt )*
262294
) => {
263295
error_chain_processing! {
264-
($content, $b, $c, $d)
296+
(handle_attributes!($content), $b, $c, $d)
265297
$($tail)*
266298
}
267299
};
@@ -271,7 +303,7 @@ macro_rules! error_chain_processing {
271303
$( $tail:tt )*
272304
) => {
273305
error_chain_processing! {
274-
($a, $content, $c, $d)
306+
($a, handle_attributes!($content), $c, $d)
275307
$($tail)*
276308
}
277309
};

src/example_generated.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,15 @@ pub mod inner {
2626

2727
error_chain! {
2828
links {
29-
Inner(inner::Error) #[doc = "Link to another `ErrorChain`."];
29+
/// "Link to another `ErrorChain`.
30+
Inner(inner::Error);
3031
}
3132
foreign_links {
32-
Io(::std::io::Error) #[doc = "Link to a `std::error::Error` type."];
33+
/// Link to a `std::error::Error` type.
34+
Io(::std::io::Error);
3335
}
3436
errors {
35-
#[doc = "A custom error kind."]
37+
/// "A custom error kind."
3638
Custom
3739
}
3840
}

0 commit comments

Comments
 (0)