Repository navigation
Suggest swapping == operands when unsuffixed literals are involved - #166178
Open
Yogeshwaran-Projects wants to merge 1 commit into
Open
Yogeshwaran-Projects wants to merge 1 commit into
Yogeshwaran-Projects wants to merge 1 commit into
Conversation
Collaborator
|
Thanks for the pull request, and welcome! The Rust Project has assigned @tmiasko (or someone else) to review your changes, you should hear from them (or someone else) within the next two weeks. Please see the contribution instructions and our LLM policy for more information. Why was this reviewer chosen?The reviewer was selected based on:
|
This comment has been minimized.
This comment has been minimized.
Yogeshwaran-Projects
force-pushed
the
rock/binop-swap-sugg
branch
from
November 20, 2026 04:12
5ee3961 to
964578b
Compare
Collaborator
|
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. |
This branch has not been deployed
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.
Part of #165968
The “consider swapping the equality” suggestion already existed for
==/!=, but it could be dropped when an untyped literal made the reverse-PartialEqcheck return only “maybe” (for example[1, 2, 3] == vec![1, 2, 3]). Cases such as4 == T(4)already produced the suggestion. This PR assigns the default types (i32/f64) to those literals before the existing check runs, allowing the swap suggestion and the accompanying note to appear. The default types are used only for the check; the printed message still shows{integer}. The same change is applied on the E0308 path. No suggestion is emitted when an operand type is an error, and other binary operators (such as*and+) are outside the scope of this PR. Forassert_eq!the note was previously missing because the source text inside the std macro is not readable; a code suggestion is still omitted on purpose, since there is nothing the user can swap inside the macro (see #139050).Before:
After:
For
assert_eq!(a, v)only the note is added, with no suggestion: