fix(ron): round-trip non-finite floats (inf/-inf/NaN) - #170
Merged
knickish merged 1 commit intoAug 26, 2026
Conversation
SerRon serializes non-finite floats as `inf`, `-inf` and `NaN` (matching
the RON specification and the reference `ron` crate via `{:?}` formatting),
but the RON deserializer rejected all of these tokens. As a result
`deserialize_ron(serialize_ron(x))` returned an error for any float that was
infinite or NaN, breaking the round-trip contract for both `f32` and `f64`.
Bare `inf`/`NaN` are scanned as identifiers, so accept them in `as_f64` when
a float is expected; `-inf`/`+inf` reach the number branch after the sign, so
parse the `inf` literal there. Adds a regression test covering scalars, the
literal forms, and non-finite floats nested inside a struct/Vec/Option.
not-fl3
approved these changes
Aug 26, 2026
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.
SerRonserializes non-finite floats asinf,-infandNaN(matching the RON specification and the referenceroncrate), but the RON deserializer rejected all of these tokens. As a resultdeserialize_ron(serialize_ron(x))returned an error for anyf32/f64that was infinite or NaN, including values nested inside a struct/Vec/Option.Before:
Bare
inf/NaNare scanned as identifiers, so they're now accepted inas_f64when a float is expected;-inf/+infreach the number branch after the sign, so theinfliteral is parsed there. Serialization is unchanged. Adds a regression test covering scalars, the literal forms (inf/+inf/-inf/NaN), and non-finite floats nested in a struct. (The sibling TOML module already handles these tokens; RON was simply missed.)