Skip to content

Commit d13e395

Browse files
authored
Merge pull request #30 from Yamakaky/patch-1
Propagate variants attributes to method definitions.
2 parents 5f232aa + 2b4e9ae commit d13e395

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

src/lib.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ macro_rules! quick_error {
361361
=> $iitem: $imode [$( $ivar: $ityp ),*] )*]
362362
);
363363
quick_error!(IMPLEMENTATIONS $name {$(
364-
$iitem: $imode [$( $ivar: $ityp ),*] {$( $ifuncs )*}
364+
$iitem: $imode [$(#[$imeta])*] [$( $ivar: $ityp ),*] {$( $ifuncs )*}
365365
)*});
366366
$(
367367
quick_error!(ERROR_CHECK $imode $($ifuncs)*);
@@ -380,7 +380,7 @@ macro_rules! quick_error {
380380
=> $iitem: $imode [$( $ivar: $ityp ),*] )*]
381381
);
382382
quick_error!(IMPLEMENTATIONS $name {$(
383-
$iitem: $imode [$( $ivar: $ityp ),*] {$( $ifuncs )*}
383+
$iitem: $imode [$(#[$imeta])*] [$( $ivar: $ityp ),*] {$( $ifuncs )*}
384384
)*});
385385
$(
386386
quick_error!(ERROR_CHECK $imode $($ifuncs)*);
@@ -585,7 +585,7 @@ macro_rules! quick_error {
585585
};
586586
(IMPLEMENTATIONS
587587
$name:ident {$(
588-
$item:ident: $imode:tt [$( $var:ident: $typ:ty ),*] {$( $funcs:tt )*}
588+
$item:ident: $imode:tt [$(#[$imeta:meta])*] [$( $var:ident: $typ:ty ),*] {$( $funcs:tt )*}
589589
)*}
590590
) => {
591591
#[allow(unused)]
@@ -595,6 +595,7 @@ macro_rules! quick_error {
595595
{
596596
match *self {
597597
$(
598+
$(#[$imeta])*
598599
quick_error!(ITEM_PATTERN
599600
$name $item: $imode [$( ref $var ),*]
600601
) => {
@@ -613,6 +614,7 @@ macro_rules! quick_error {
613614
fn description(&self) -> &str {
614615
match *self {
615616
$(
617+
$(#[$imeta])*
616618
quick_error!(ITEM_PATTERN
617619
$name $item: $imode [$( ref $var ),*]
618620
) => {
@@ -626,6 +628,7 @@ macro_rules! quick_error {
626628
fn cause(&self) -> Option<&::std::error::Error> {
627629
match *self {
628630
$(
631+
$(#[$imeta])*
629632
quick_error!(ITEM_PATTERN
630633
$name $item: $imode [$( ref $var ),*]
631634
) => {
@@ -1224,4 +1227,16 @@ mod test {
12241227
assert!(etext.starts_with(
12251228
"Path error at \"/tmp\": invalid utf-8"));
12261229
}
1230+
1231+
#[test]
1232+
fn conditional_compilation() {
1233+
quick_error! {
1234+
#[allow(dead_code)]
1235+
#[derive(Debug)]
1236+
pub enum Test {
1237+
#[cfg(feature = "foo")]
1238+
Variant
1239+
}
1240+
}
1241+
}
12271242
}

0 commit comments

Comments
 (0)