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

Commit baee12b

Browse files
andy128kYamakaky
authored andcommitted
Cleanup impl_error_chain_kind macro.
- Remove support of private enums; - Remove function from; - Remove function cause;
1 parent 9989177 commit baee12b

File tree

1 file changed

+0
-174
lines changed

1 file changed

+0
-174
lines changed

src/impl_error_chain_kind.rs

Lines changed: 0 additions & 174 deletions
Original file line numberDiff line numberDiff line change
@@ -13,33 +13,7 @@ macro_rules! impl_error_chain_kind {
1313
items [] buf []
1414
queue [ $($chunks)* ]);
1515
};
16-
( $(#[$meta:meta])*
17-
enum $name:ident { $($chunks:tt)* }
18-
) => {
19-
impl_error_chain_kind!(SORT [enum $name $(#[$meta])* ]
20-
items [] buf []
21-
queue [ $($chunks)* ]);
22-
};
2316
// Queue is empty, can do the work
24-
(SORT [enum $name:ident $( #[$meta:meta] )*]
25-
items [$($( #[$imeta:meta] )*
26-
=> $iitem:ident: $imode:tt [$( $ivar:ident: $ityp:ty ),*]
27-
{$( $ifuncs:tt )*} )* ]
28-
buf [ ]
29-
queue [ ]
30-
) => {
31-
impl_error_chain_kind!(ENUM_DEFINITION [enum $name $( #[$meta] )*]
32-
body []
33-
queue [$($( #[$imeta] )*
34-
=> $iitem: $imode [$( $ivar: $ityp ),*] )*]
35-
);
36-
impl_error_chain_kind!(IMPLEMENTATIONS $name {$(
37-
$iitem: $imode [$(#[$imeta])*] [$( $ivar: $ityp ),*] {$( $ifuncs )*}
38-
)*});
39-
$(
40-
impl_error_chain_kind!(ERROR_CHECK $imode $($ifuncs)*);
41-
)*
42-
};
4317
(SORT [pub enum $name:ident $( #[$meta:meta] )*]
4418
items [$($( #[$imeta:meta] )*
4519
=> $iitem:ident: $imode:tt [$( $ivar:ident: $ityp:ty ),*]
@@ -206,20 +180,6 @@ macro_rules! impl_error_chain_kind {
206180
__Nonexhaustive {}
207181
}
208182
};
209-
// Private enum (Queue Empty)
210-
(ENUM_DEFINITION [enum $name:ident $( #[$meta:meta] )*]
211-
body [$($( #[$imeta:meta] )*
212-
=> $iitem:ident ($(($( $ttyp:ty ),+))*) {$({$( $svar:ident: $styp:ty ),*})*} )* ]
213-
queue [ ]
214-
) => {
215-
$(#[$meta])*
216-
enum $name {
217-
$(
218-
$(#[$imeta])*
219-
$iitem $(($( $ttyp ),*))* $({$( $svar: $styp ),*})*,
220-
)*
221-
}
222-
};
223183
// Unit variant
224184
(ENUM_DEFINITION [$( $def:tt )*]
225185
body [$($( #[$imeta:meta] )*
@@ -287,35 +247,6 @@ macro_rules! impl_error_chain_kind {
287247
}
288248
}
289249
}
290-
/*#[allow(unused)]
291-
impl ::std::error::Error for $name {
292-
fn description(&self) -> &str {
293-
match *self {
294-
$(
295-
impl_error_chain_kind!(ITEM_PATTERN
296-
$name $item: $imode [$( ref $var ),*]
297-
) => {
298-
impl_error_chain_kind!(FIND_DESCRIPTION_IMPL
299-
$item: $imode self fmt [$( $var ),*]
300-
{$( $funcs )*})
301-
}
302-
)*
303-
}
304-
}
305-
fn cause(&self) -> Option<&::std::error::Error> {
306-
match *self {
307-
$(
308-
impl_error_chain_kind!(ITEM_PATTERN
309-
$name $item: $imode [$( ref $var ),*]
310-
) => {
311-
impl_error_chain_kind!(FIND_CAUSE_IMPL
312-
$item: $imode [$( $var ),*]
313-
{$( $funcs )*})
314-
}
315-
)*
316-
}
317-
}
318-
}*/
319250
#[allow(unknown_lints, unused, unused_doc_comment)]
320251
impl $name {
321252
/// A string describing the error kind.
@@ -336,11 +267,6 @@ macro_rules! impl_error_chain_kind {
336267
}
337268
}
338269
}
339-
$(
340-
impl_error_chain_kind!(FIND_FROM_IMPL
341-
$name $item: $imode [$( $var:$typ ),*]
342-
{$( $funcs )*});
343-
)*
344270
};
345271
(FIND_DISPLAY_IMPL $name:ident $item:ident: $imode:tt
346272
{ display($self_:tt) -> ($( $exprs:tt )*) $( $tail:tt )*}
@@ -393,96 +319,6 @@ macro_rules! impl_error_chain_kind {
393319
) => {
394320
stringify!($item)
395321
};
396-
(FIND_CAUSE_IMPL $item:ident: $imode:tt
397-
[$( $var:ident ),*]
398-
{ cause($expr:expr) $( $tail:tt )*}
399-
) => {
400-
Some($expr)
401-
};
402-
(FIND_CAUSE_IMPL $item:ident: $imode:tt
403-
[$( $var:ident ),*]
404-
{ $t:tt $( $tail:tt )*}
405-
) => {
406-
impl_error_chain_kind!(FIND_CAUSE_IMPL
407-
$item: $imode [$( $var ),*]
408-
{ $($tail)* })
409-
};
410-
(FIND_CAUSE_IMPL $item:ident: $imode:tt
411-
[$( $var:ident ),*]
412-
{ }
413-
) => {
414-
None
415-
};
416-
(FIND_FROM_IMPL $name:ident $item:ident: $imode:tt
417-
[$( $var:ident: $typ:ty ),*]
418-
{ from() $( $tail:tt )*}
419-
) => {
420-
$(
421-
impl From<$typ> for $name {
422-
fn from($var: $typ) -> $name {
423-
$name::$item($var)
424-
}
425-
}
426-
)*
427-
impl_error_chain_kind!(FIND_FROM_IMPL
428-
$name $item: $imode [$( $var:$typ ),*]
429-
{$( $tail )*});
430-
};
431-
(FIND_FROM_IMPL $name:ident $item:ident: UNIT
432-
[ ]
433-
{ from($ftyp:ty) $( $tail:tt )*}
434-
) => {
435-
impl From<$ftyp> for $name {
436-
fn from(_discarded_error: $ftyp) -> $name {
437-
$name::$item
438-
}
439-
}
440-
impl_error_chain_kind!(FIND_FROM_IMPL
441-
$name $item: UNIT [ ]
442-
{$( $tail )*});
443-
};
444-
(FIND_FROM_IMPL $name:ident $item:ident: TUPLE
445-
[$( $var:ident: $typ:ty ),*]
446-
{ from($fvar:ident: $ftyp:ty) -> ($( $texpr:expr ),*) $( $tail:tt )*}
447-
) => {
448-
impl From<$ftyp> for $name {
449-
fn from($fvar: $ftyp) -> $name {
450-
$name::$item($( $texpr ),*)
451-
}
452-
}
453-
impl_error_chain_kind!(FIND_FROM_IMPL
454-
$name $item: TUPLE [$( $var:$typ ),*]
455-
{ $($tail)* });
456-
};
457-
(FIND_FROM_IMPL $name:ident $item:ident: STRUCT
458-
[$( $var:ident: $typ:ty ),*]
459-
{ from($fvar:ident: $ftyp:ty) -> {$( $tvar:ident: $texpr:expr ),*} $( $tail:tt )*}
460-
) => {
461-
impl From<$ftyp> for $name {
462-
fn from($fvar: $ftyp) -> $name {
463-
$name::$item {
464-
$( $tvar: $texpr ),*
465-
}
466-
}
467-
}
468-
impl_error_chain_kind!(FIND_FROM_IMPL
469-
$name $item: STRUCT [$( $var:$typ ),*]
470-
{ $($tail)* });
471-
};
472-
(FIND_FROM_IMPL $name:ident $item:ident: $imode:tt
473-
[$( $var:ident: $typ:ty ),*]
474-
{ $t:tt $( $tail:tt )*}
475-
) => {
476-
impl_error_chain_kind!(FIND_FROM_IMPL
477-
$name $item: $imode [$( $var:$typ ),*]
478-
{$( $tail )*}
479-
);
480-
};
481-
(FIND_FROM_IMPL $name:ident $item:ident: $imode:tt
482-
[$( $var:ident: $typ:ty ),*]
483-
{ }
484-
) => {
485-
};
486322
(ITEM_BODY $(#[$imeta:meta])* $item:ident: UNIT
487323
) => { };
488324
(ITEM_BODY $(#[$imeta:meta])* $item:ident: TUPLE
@@ -521,16 +357,6 @@ macro_rules! impl_error_chain_kind {
521357
=> { impl_error_chain_kind!(ERROR_CHECK_COMMA $imode $($tail)*); };
522358
(ERROR_CHECK $imode:tt description($expr:expr) $( $tail:tt )*)
523359
=> { impl_error_chain_kind!(ERROR_CHECK_COMMA $imode $($tail)*); };
524-
(ERROR_CHECK $imode:tt cause($expr:expr) $($tail:tt)*)
525-
=> { impl_error_chain_kind!(ERROR_CHECK_COMMA $imode $($tail)*); };
526-
(ERROR_CHECK $imode:tt from() $($tail:tt)*)
527-
=> { impl_error_chain_kind!(ERROR_CHECK_COMMA $imode $($tail)*); };
528-
(ERROR_CHECK $imode:tt from($ftyp:ty) $($tail:tt)*)
529-
=> { impl_error_chain_kind!(ERROR_CHECK_COMMA $imode $($tail)*); };
530-
(ERROR_CHECK TUPLE from($fvar:ident: $ftyp:ty) -> ($( $e:expr ),*) $( $tail:tt )*)
531-
=> { impl_error_chain_kind!(ERROR_CHECK_COMMA TUPLE $($tail)*); };
532-
(ERROR_CHECK STRUCT from($fvar:ident: $ftyp:ty) -> {$( $v:ident: $e:expr ),*} $( $tail:tt )*)
533-
=> { impl_error_chain_kind!(ERROR_CHECK_COMMA STRUCT $($tail)*); };
534360
(ERROR_CHECK $imode:tt ) => {};
535361
(ERROR_CHECK_COMMA $imode:tt , $( $tail:tt )*)
536362
=> { impl_error_chain_kind!(ERROR_CHECK $imode $($tail)*); };

0 commit comments

Comments
 (0)