-
Notifications
You must be signed in to change notification settings - Fork 13.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Suggest swapping LHS and RHS when RHS impls PartialEq<lhs_ty>
#132404
Conversation
PartialEq
PartialEq<lhs_ty>
PartialEq<lhs_ty>
PartialEq<lhs_ty>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also add an UI test as described in https://rustc-dev-guide.rust-lang.org/tests/ui.html
6998c73
to
1048e02
Compare
This comment has been minimized.
This comment has been minimized.
1048e02
to
bc41d76
Compare
bc41d76
to
739f29c
Compare
Thank you for the detailed and thoughtful review! Your suggestions really helped improve the code. Much appreciated. |
739f29c
to
ca81f0b
Compare
ca81f0b
to
7eadcaf
Compare
Just found when the integer type is not explicitly specified, the suggestion will not be emitted; instead, the following diagnostic message will be emitted: error[E0277]: can't compare `{integer}` with `T`
--> $DIR/partialeq_suggest_swap.rs:10:9
|
LL | 123 == T(123);
| ^^ no implementation for `{integer} == T`
|
= help: the trait `PartialEq<T>` is not implemented for `{integer}`
= help: the following other types implement trait `PartialEq<Rhs>`:
f128
f16
f32
f64
i128
i16
i32
i64
and 8 others
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0277`. I think we should consider this case, as Also the similar case is when the type is error[E0277]: can't compare `String` with `T`
--> $DIR/partialeq_suggest_swap.rs:10:26
|
LL | String::from("text") == T(String::from("text"));
| ^^ no implementation for `String == T`
|
= help: the trait `PartialEq<T>` is not implemented for `String`
= help: the following other types implement trait `PartialEq<Rhs>`:
`String` implements `PartialEq<&str>`
`String` implements `PartialEq<Cow<'_, str>>`
`String` implements `PartialEq<str>`
`String` implements `PartialEq`
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0277`. |
7eadcaf
to
5791a66
Compare
no, that case does not need to be handled right now |
The message can't compare Lines 238 to 249 in fbab782
So we may have to extend the |
@bors r+ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks. The remaining cases could be done as a followup.
☀️ Test successful - checks-actions |
Finished benchmarking commit (4d215e2): comparison URL. Overall result: no relevant changes - no action needed@rustbot label: -perf-regression Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)Results (primary -1.5%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResults (primary -1.3%, secondary -5.8%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 780.805s -> 780.212s (-0.08%) |
Closes: #130495
r? @fee1-dead