Fix zero literal rejection in decimal and octal#43
Fix zero literal rejection in decimal and octal#43leighmcculloch wants to merge 2 commits intomainfrom
Conversation
There was a problem hiding this comment.
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
0and0o0to pass the “leading zeros” check inbytes(). - Ensure byte output length accounts for the
0value case when constructing the output array. - Add tests covering zero handling and a range of byte-boundary values for both
bytesandbytesmin.
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.
| } 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. |
There was a problem hiding this comment.
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.
|
Closing in favor of #44. |
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