[configuration] Fix unclear error messages for line-length values exceeding u16::MAX
#21329
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.
Summary
Fixed unclear error messages when
line-lengthconfiguration values exceedu16::MAX(65535). Previously, values > 65535 would produce a cryptic TOML parsing error "expected u16" instead of a clear validation message. Now all invalid values produce consistent, user-friendly error messages.Fixes #21328
Problem Analysis
The
LineLengthtype'sDeserializeimplementation attempted to deserialize directly asu16. When TOML contained values exceedingu16::MAX(65535), the TOML deserializer would fail before reaching the validation logic, resulting in unclear error messages:"invalid value: integer65536, expected u16"(unclear)"line-length must be between 1 and 320 (got 500)"(clear)This inconsistency violated the TOML spec's requirement to accept arbitrary 64-bit signed integers and handle validation errors gracefully.
Approach
Modified the
Deserializeimplementation forLineLengthincrates/ruff_linter/src/line_width.rsto:u64first: Accept any valid TOML integer valueu16::MAXbefore conversion"line-length must be between 1 and 320 (got {value})"Added test cases covering:
line-length = 65535(at u16::MAX)line-length = 65536line-length = 99_999All tests verify that the error messages are clear and consistent regardless of whether the value exceeds u16::MAX or just exceeds the valid range (1-320).