Skip to content
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

Match against an optional single trailing colon #1010

Merged

Conversation

tcharding
Copy link
Member

@tcharding tcharding commented May 26, 2022

Currently we allow multiple trailing colons when matching within the
check_format_non_negative macro. We can be more restrictive with no
loss of usability.

Use $(;)? instead of $(;)* to match against 0 or 1 semi-colons
instead of 0 or more.

Done as part of the edition 2018 checklist.

Currently we allow multiple trailing colons when matching within the
`check_format_non_negative` macro. We can be more restrictive with no
loss of usability.

Use `$(;)?` instead of `$(;)*` to match against 0 or 1 semi-colons
instead of 0 or more.
@@ -1640,7 +1640,7 @@ mod tests {

// Creates individual test functions to make it easier to find which check failed.
macro_rules! check_format_non_negative {
($denom:ident; $($test_name:ident, $val:expr, $format_string:expr, $expected:expr);* $(;)*) => {
($denom:ident; $($test_name:ident, $val:expr, $format_string:expr, $expected:expr);* $(;)?) => {
Copy link
Member Author

@tcharding tcharding May 26, 2022

Choose a reason for hiding this comment

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

@Kixunil, one of the other task items in edition 2018 checklist mentions using literal instead of expr. This is the location here, right? I can do the change but I cannot justify it. I get that literal is more restrictive than expr, what is the benefit of being more restrictive? Or is there some other benefit? Thanks.

(FTR the justification for this PR is a bit soft as well.)

Copy link
Collaborator

Choose a reason for hiding this comment

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

If one accidentally passes non-literal the compiler should produce better errors because it realizes the argument is wrong at the place where the macro was used - the error wouldn't come out of inside of the macro.

This PR is purely cosmetic to avoid potentially confusing some_macro!(a,b,c, ,,,,,,,);

Copy link
Member Author

Choose a reason for hiding this comment

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

re the literal/expr thing, cheers, that makes good sense. I'll patch it.

re the cosmetic thing, I guessed as much. Is there a specif reason that you didn't do this (put the semi-colon inside the match pattern):

        ($denom:ident; $($test_name:ident, $val:expr, $format_string:expr, $expected:expr;)*) => {

Was it to be inline with how Rust allows for an optional comma? (Just out of interest and for my education.)

Copy link
Member Author

Choose a reason for hiding this comment

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

expr -> literal change done in #1014

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, trailing commas/semicolons are optional and putting it inside would make it mandatory.

Copy link
Collaborator

@Kixunil Kixunil left a comment

Choose a reason for hiding this comment

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

ACK 88ce8fe

@Kixunil Kixunil added trivial Obvious, easy and quick to review (few lines or doc-only...) one ack PRs that have one ACK, so one more can progress them labels May 26, 2022
Copy link
Member

@apoelstra apoelstra left a comment

Choose a reason for hiding this comment

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

ACK 88ce8fe

Nice!

@apoelstra apoelstra merged commit 99ae48a into rust-bitcoin:master May 27, 2022
@tcharding tcharding deleted the 05-26-match-single-semi-colon branch May 31, 2022 00:07
ChallengeDev210 pushed a commit to ChallengeDev210/rust-bitcoin that referenced this pull request Aug 1, 2022
…e trailing colon

88ce8fe Match against an optional single trailing colon (Tobin C. Harding)

Pull request description:

  Currently we allow multiple trailing colons when matching within the
  `check_format_non_negative` macro. We can be more restrictive with no
  loss of usability.

  Use `$(;)?` instead of `$(;)*` to match against 0 or 1 semi-colons
  instead of 0 or more.

  Done as part of the [edition 2018 checklist](rust-bitcoin/rust-bitcoin#510).

ACKs for top commit:
  Kixunil:
    ACK 88ce8fe
  apoelstra:
    ACK 88ce8fe

Tree-SHA512: 4409c094f6a0aa49ddebdad850fd1d5a31a57dae8828f5a1db0ee5a855e1bce9e43aea69fa0b4d132068c3a43f1f62d35409b9ac5b32ed876e4dd586829e8e68
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
one ack PRs that have one ACK, so one more can progress them trivial Obvious, easy and quick to review (few lines or doc-only...)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants