[configuration] Fix unclear error messages for line-length values exceeding u16::MAX#21329
Merged
MichaReiser merged 3 commits intoastral-sh:mainfrom Nov 10, 2025
Merged
[configuration] Fix unclear error messages for line-length values exceeding u16::MAX#21329MichaReiser merged 3 commits intoastral-sh:mainfrom
configuration] Fix unclear error messages for line-length values exceeding u16::MAX#21329MichaReiser merged 3 commits intoastral-sh:mainfrom
Conversation
configuration] Fix unclear error messages for line-length values exceeding u16::MAXconfiguration] Fix unclear error messages for line-length values exceeding u16::MAX
MichaReiser
requested changes
Nov 10, 2025
- Change deserialization from u64 to i64 to handle negative values per TOML spec - Merge u16 conversion and LineLength validation into a single chain using and_then - Add test case for negative line-length values
MichaReiser
approved these changes
Nov 10, 2025
Member
|
Thank you. For us reviewers, it's very helpful to get feedback when suggestions don't work (I obviously didn't realize that Rust won't like |
dcreager
added a commit
that referenced
this pull request
Nov 11, 2025
* origin/main: (38 commits) [ty] Make implicit submodule imports only occur in global scope (#21370) [ty] introduce local variables for `from` imports of submodules in `__init__.py(i)` (#21173) [`ruff`] Ignore `str()` when not used for simple conversion (`RUF065`) (#21330) [ty] implement `typing.NewType` by adding `Type::NewTypeInstance` [ty] supress inlay hints for `+1` and `-1` (#21368) [ty] Use type context for inference of generic constructors (#20933) [ty] Improve generic call expression inference (#21210) [ty] supress some trivial expr inlay hints (#21367) [`configuration`] Fix unclear error messages for line-length values exceeding `u16::MAX` (#21329) [ty] Fix incorrect inference of `enum.auto()` for enums with non-`int` mixins, and imprecise inference of `enum.auto()` for single-member enums (#20541) [`refurb`] Detect empty f-strings (`FURB105`) (#21348) [ty] provide `import` completion when in `from <name> <name>` statement (#21291) [ty] elide redundant inlay hints for function args (#21365) Fix syntax error false positive on alternative `match` patterns (#21362) Add a new "Opening a PR" section to the contribution guide (#21298) [`flake8-simplify`] Fix SIM222 false positive for `tuple(generator) or None` (`SIM222`) (#21187) Rebuild ruff binary instead of sharing it across jobs (#21361) [ty] Fix `--exclude` and `src.exclude` merging (#21341) [ty] Add support for properties that return `Self` (#21335) Add upstream linter URL to `ruff linter --output-format=json` (#21316) ...
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.
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).