Skip to content

Fix repetition operator mismatch in macro definitions #46

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 3, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,8 +465,6 @@ macro_rules! quick_error {
queue [ #[$qmeta:meta] $( $tail:tt )*]
) => {
quick_error!(SORT [$( $def )*]
enum [$( $(#[$emeta])* => $eitem $(( $($etyp),* ))* )*
$(#[$bmeta])* => $bitem: $bmode $(( $($btyp),* ))*]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand this deletion. Is this just the unused code that sneaked into the codebase?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not familiar with the code, but this rule is very broken. Here is a similar fix: https://github.com/rust-lang-nursery/error-chain/pull/269/files#r305615630. Ideally, someone who understands the code should review this. I'm also fine just reverting the pull request if it can't be reviewed.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aha, this is left from @colin-kiegel's simplification commit: 94f0680
The code that matches that rule is:

pub enum Test {
    #[cfg(feature = "foo")]
    Variant1
    #[cfg(feature = "foo")]
    Variant2
}

Will try to fix it soon.

How did you find these issues?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice find!

I've found those issues with a crater run when adding the meta_variable_misuse lint. You can try it with #![deny(meta_variable_misuse)] (or warn instead of deny).

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Thanks! I'm going to merge it as is and tackle the bug afterwards.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, thanks!

items [$($( #[$imeta:meta] )*
=> $iitem: $imode [$( $ivar:$ityp ),*] {$( $ifuncs )*} )*
$bitem: $bmode [$( $bvar:$btyp ),*] {} ]
Expand All @@ -483,7 +481,7 @@ macro_rules! quick_error {
) => {
quick_error!(SORT [$( $def )*]
items [$( $(#[$imeta])* => $iitem: $imode [$( $ivar:$ityp ),*] {$( $ifuncs )*} )*]
buf [$( #[$bmeta] )* => $bitem: TUPLE [$( $qvar:$qtyp ),*] ]
buf [$( #[$bmeta] )* => $bitem: TUPLE [$( $qvar:$qtyp ),+] ]
queue [$( $tail )*]
);
};
Expand All @@ -497,7 +495,7 @@ macro_rules! quick_error {
) => {
quick_error!(SORT [$( $def )*]
items [$( $(#[$imeta])* => $iitem: $imode [$( $ivar:$ityp ),*] {$( $ifuncs )*} )*]
buf [$( #[$bmeta] )* => $bitem: STRUCT [$( $qvar:$qtyp ),*] ]
buf [$( #[$bmeta] )* => $bitem: STRUCT [$( $qvar:$qtyp ),+] ]
queue [$( $tail )*]);
};
// Add struct enum-variant, with excess comma - e.g. { descr: &'static str, }
Expand All @@ -510,7 +508,7 @@ macro_rules! quick_error {
) => {
quick_error!(SORT [$( $def )*]
items [$( $(#[$imeta])* => $iitem: $imode [$( $ivar:$ityp ),*] {$( $ifuncs )*} )*]
buf [$( #[$bmeta] )* => $bitem: STRUCT [$( $qvar:$qtyp ),*] ]
buf [$( #[$bmeta] )* => $bitem: STRUCT [$( $qvar:$qtyp ),+] ]
queue [$( $tail )*]);
};
// Add braces and flush always on braces
Expand Down Expand Up @@ -572,7 +570,7 @@ macro_rules! quick_error {
pub enum $name {
$(
$(#[$imeta])*
$iitem $(($( $ttyp ),*))* $({$( $svar: $styp ),*})*,
$iitem $(($( $ttyp ),+))* $({$( $svar: $styp ),*})*,
)*
}
};
Expand All @@ -590,7 +588,7 @@ macro_rules! quick_error {
enum $name {
$(
$(#[$imeta])*
$iitem $(($( $ttyp ),*))* $({$( $svar: $styp ),*})*,
$iitem $(($( $ttyp ),+))* $({$( $svar: $styp ),*})*,
)*
}
};
Expand All @@ -616,7 +614,7 @@ macro_rules! quick_error {
) => {
quick_error!(ENUM_DEFINITION [ $($def)* ]
body [$($( #[$imeta] )* => $iitem ($(($( $ttyp ),+))*) {$({$( $svar: $styp ),*})*} )*
$( #[$qmeta] )* => $qitem (($( $qtyp ),*)) {} ]
$( #[$qmeta] )* => $qitem (($( $qtyp ),+)) {} ]
queue [ $($queue)* ]
);
};
Expand Down