Repository navigation
Write non-numeric compact ranges in the same struct form as without compact_ranges - #629
Merged
juntyr merged 2 commits intoOct 21, 2026
Merged
Conversation
…ompact_ranges
With compact_ranges enabled, a range whose bounds are not numbers falls back
to the struct form, but that fallback always wrote a bare '(' itself. It
skipped the struct name (struct_names / explicit_struct_names) and wrote its
own parentheses inside an unwrapped newtype variant, so with
explicit_struct_names or unwrap_variant_newtypes the output could not be
deserialized again.
ybai08
force-pushed
the
fix/compact-range-fallback-struct-form
branch
from
October 18, 2026 19:14
e258b5e to
1ba6921
Compare
Member
|
Thanks @ybai08! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
With
compact_ranges(true), a range whose bounds are not numbers falls back to the struct form, but the fallback inSerializeStruct::serialize_fieldalways wrote a bare(itself. It skipped two thingsserialize_structdoes:struct_namesor theexplicit_struct_namesextension is on, andunwrap_variant_newtypes.Two of those outputs can't be read back:
With
struct_names(true)alone the name is dropped ((start:"a",end:"z")instead ofRange(start:"a",end:"z")), which still parses.RangeCompoundnow keeps the struct name and whether it was entered as an unwrapped newtype variant, and the fallback writes the opening the wayserialize_structwould. Numeric ranges are unchanged (Numbers(0..5)inside an unwrapped variant already round-trips).test_non_numeric_range_falls_back_to_struct_formintests/601_support_for_number_ranges.rschecks thestruct_names,explicit_struct_namesandunwrap_variant_newtypesoutputs and reads them back. It fails on master. A local differential check (not part of the PR) over 40 configurations (5 extension sets ×struct_names×compact_structs× pretty/compact whitespace) on a struct holdingRange<String>,RangeFrom<char>and newtype variants found the output withcompact_ranges(true)identical to the output withcompact_ranges(false), and all of them read back.cargo test,cargo test --all-features,cargo test --features integer128,cargo test --features indexmapandcargo fmt --all -- --checkpass.cargo hackand the 1.64 MSRV toolchain were not run.CHANGELOG.md