fix(formatter): sort use self::... items by their full path compare_names("self", "self") returned Greater, violating sort reflexivity. Multiple use self::x; statements were therefore ordered only on the leading self segment and never recursed t - #10018
Merged
Conversation
compare_names("self", "self") returned Greater, violating sort
reflexivity. Multiple `use self::x;` statements were therefore ordered
only on the leading `self` segment and never recursed to compare the rest
of the path, leaving them unsorted. Add a `("self", "self") => Equal`
arm so equal leading segments fall through to the next segment.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Collaborator
Author
orizi
marked this pull request as ready for review
June 1, 2026 07:35
PR SummaryLow Risk Overview
Reviewed by Cursor Bugbot for commit e779462. Bugbot is set up for automated code reviews on this repo. Configure here. |
TomerStarkware
approved these changes
Jun 1, 2026
TomerStarkware
left a comment
Collaborator
There was a problem hiding this comment.
@TomerStarkware reviewed 4 files and all commit messages, and made 1 comment.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on eytan-starkware).
orizi
deleted the
orizi/06-01-fix_formatter_sort_use_self_._items_by_their_full_path_compare_names_self_self_returned_greater_violating_sort_reflexivity._multiple_use_self_x_statements_were_therefore_ordered_only_on_the_leading_self_segment_and_never_r
branch
June 1, 2026 09:34
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
Fixes a bug in
compare_nameswhere"self"compared against itself did not returnOrdering::Equal, causinguse self::*imports to not be sorted correctly among themselves.Type of change
Please check one:
Why is this change needed?
The
compare_namesfunction handled"self"in ordering rules relative to other keywords (super,crate) but was missing an explicit case for("self", "self"). Without it, the comparison fell through to the catch-all rules, which could produce an incorrect ordering (e.g.,Ordering::Greaterinstead ofOrdering::Equal), preventinguse self::*imports from being sorted alphabetically.What was the behavior or documentation before?
Multiple
use self::*imports were not sorted correctly by the formatter. For example:would not be reordered.
What is the behavior or documentation after?
use self::*imports are now sorted alphabetically:Related issue or discussion (if any)
N/A
Additional context
A new test case (
sort_self_use) was added with input and expected output files to cover this scenario.