Skip to content

Comments

Fix zero literal rejection in decimal and octal#43

Closed
leighmcculloch wants to merge 2 commits intomainfrom
zero
Closed

Fix zero literal rejection in decimal and octal#43
leighmcculloch wants to merge 2 commits intomainfrom
zero

Conversation

@leighmcculloch
Copy link
Member

What

Allow zero literal for decimal and octal number types as inputs to the macros.

Why

It is supported for the hex and binary number types.

Close #41

@leighmcculloch leighmcculloch requested review from a team and Copilot February 24, 2026 07:02
@leighmcculloch leighmcculloch marked this pull request as ready for review February 24, 2026 07:03
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the bytes!/bytesmin! procedural macros to accept zero literals in decimal (0) and octal (0o0) forms, aligning behavior with existing hex/binary support and closing issue #41.

Changes:

  • Allow 0 and 0o0 to pass the “leading zeros” check in bytes().
  • Ensure byte output length accounts for the 0 value case when constructing the output array.
  • Add tests covering zero handling and a range of byte-boundary values for both bytes and bytesmin.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/bytes.rs Adjusts leading-zero rejection logic and output sizing; adds extensive tests for zero + boundary values.
src/bytesmin.rs Adds tests for zero + boundary values to validate minimal-byte output behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +47 to +51
} else if leading_zero_count > 0 && remainder.len() > 1 {
// If there are leading zeros without a bits per digit error, since a
// caller may expect the zeros to be preserved, and so it is better for
// us to error. They can proceed by removing the zeros.
// us to error. They can proceed by removing the zeros. A single digit
// `0` is permitted as it is unambiguously the value zero.
Copy link

Copilot AI Feb 24, 2026

Choose a reason for hiding this comment

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

The new leading_zero_count > 0 && remainder.len() > 1 check uses remainder derived from lit.to_string(), which includes any integer suffix (e.g. 0u8, 0usize). That means bytes!(0u8) (and bytes!(0o0u8)) will be rejected as “leading zeros” even though the digit portion is a single 0. Consider stripping the suffix before computing remainder.len() / leading-zero conditions (e.g., use LitInt APIs to access the digit part without the suffix, or split normalized into digits vs suffix based on the selected base) and add a regression test for 0u8/0o0u8.

Copilot uses AI. Check for mistakes.
@leighmcculloch
Copy link
Member Author

Closing in favor of #44.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bytes! macro rejects zero literal in decimal and octal forms

1 participant