Uh oh!
There was an error while loading. Please reload this page.
float: Fix panic at max exponential precision - #154052
Conversation
rustbot
commented
Mar 18, 2026
rustbot has assigned @Mark-Simulacrum. Use Why was this reviewer chosen?The reviewer was selected based on:
|
71fe342 to
d57cfdfCompareUh oh!
There was an error while loading. Please reload this page.
d57cfdf to
77f6ba6Comparerustbot
commented
Mar 20, 2026
Some changes occurred in float parsing cc @tgross35 |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
rustbot
commented
Mar 23, 2026
Reminder, once the PR becomes ready for a review, use |
Rust's formatting machinery allows precision values of up to u16::MAX. Exponential formatting works out the number of significant digits to use by adding one (for the integral digit before the decimal point). This previously used usize precision, so the maximum validated precision did not overflow, but in commit fb9ce02 ("Limit formatting width and precision to 16 bits.") the precision type was narrowed to u16 without widening that addition first. As a result an exponential precision value of 65535 is no longer handled correctly, because the digit count wraps to 0, and thus "{:.65535e}" panics in flt2dec::to_exact_exp_str with "assertion failed: ndigits > 0". Other formats (and the parser) accept values up to u16::MAX. A naive fix would be to widen that addition back to usize, but that still does not properly address 16-bit targets, where usize is only guaranteed to be able to represent values up to u16::MAX. The real issue is that this internal API is expressed in the wrong units for the formatter. Fix this by changing exact exponential formatting to take fractional digits internally as well, and compute the temporary significant digit bound only when sizing the scratch buffer. To support that let's also make formatted length accounting saturate so that extremely large rendered outputs do not reintroduce overflows in padding logic. This preserves the existing intent and keeps FormattingOptions compact while making formatting work consistently again.
77f6ba6 to
2ae6c61Comparerustbot
commented
Apr 4, 2026
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
cdown
commented
Apr 4, 2026
@rustbot ready |
Mark-Simulacrum
commented
Apr 4, 2026
@bors r+ |
…uwer Rollup of 6 pull requests Successful merges: - #147552 ([Debugger Visualizers] Optimize lookup behavior) - #154052 (float: Fix panic at max exponential precision) - #154706 (fix compilation of time/hermit.rs) - #154707 (Make `substr_range` and `subslice_range` return the new `Range` type) - #154767 (triagebot: roll library reviewers for `{coretests,alloctests}`) - #154797 (bootstrap: Include shorthand aliases in x completions)
Uh oh!
There was an error while loading. Please reload this page.
Rollup merge of #154052 - cdown:cdown/2026-03-19/precision, r=Mark-Simulacrum float: Fix panic at max exponential precision Rust's formatting machinery allows precision values of up to u16::MAX. Exponential formatting works out the number of significant digits to use by adding one (for the integral digit before the decimal point). This previously used usize precision, so the maximum validated precision did not overflow, but in commit fb9ce02 ("Limit formatting width and precision to 16 bits.") the precision type was narrowed to u16 without widening that addition first. As a result an exponential precision value of 65535 is no longer handled correctly, because the digit count wraps to 0, and thus "{:.65535e}" panics in flt2dec::to_exact_exp_str with "assertion failed: ndigits > 0". Other formats (and the parser) accept values up to u16::MAX. A naive fix would be to widen that addition back to usize, but that still does not properly address 16-bit targets, where usize is only guaranteed to be able to represent values up to u16::MAX. The real issue is that this internal API is expressed in the wrong units for the formatter. Fix this by changing exact exponential formatting to take fractional digits internally as well, and compute the temporary significant digit bound only when sizing the scratch buffer. To support that let's also make formatted length accounting saturate so that extremely large rendered outputs do not reintroduce overflows in padding logic. This preserves the existing intent and keeps FormattingOptions compact while making formatting work consistently again.
…uwer Rollup of 6 pull requests Successful merges: - rust-lang/rust#147552 ([Debugger Visualizers] Optimize lookup behavior) - rust-lang/rust#154052 (float: Fix panic at max exponential precision) - rust-lang/rust#154706 (fix compilation of time/hermit.rs) - rust-lang/rust#154707 (Make `substr_range` and `subslice_range` return the new `Range` type) - rust-lang/rust#154767 (triagebot: roll library reviewers for `{coretests,alloctests}`) - rust-lang/rust#154797 (bootstrap: Include shorthand aliases in x completions)
Rust's formatting machinery allows precision values of up to u16::MAX. Exponential formatting works out the number of significant digits to use by adding one (for the integral digit before the decimal point).
This previously used usize precision, so the maximum validated precision did not overflow, but in commit fb9ce02 ("Limit formatting width and precision to 16 bits.") the precision type was narrowed to u16 without widening that addition first.
As a result an exponential precision value of 65535 is no longer handled correctly, because the digit count wraps to 0, and thus "{:.65535e}" panics in flt2dec::to_exact_exp_str with "assertion failed: ndigits > 0". Other formats (and the parser) accept values up to u16::MAX.
A naive fix would be to widen that addition back to usize, but that still does not properly address 16-bit targets, where usize is only guaranteed to be able to represent values up to u16::MAX. The real issue is that this internal API is expressed in the wrong units for the formatter.
Fix this by changing exact exponential formatting to take fractional digits internally as well, and compute the temporary significant digit bound only when sizing the scratch buffer. To support that let's also make formatted length accounting saturate so that extremely large rendered outputs do not reintroduce overflows in padding logic.
This preserves the existing intent and keeps FormattingOptions compact while making formatting work consistently again.