-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsD-papercutDiagnostics: An error or lint that needs small tweaks.Diagnostics: An error or lint that needs small tweaks.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
Code
#[derive(PartialEq, Eq, Clone)]
struct Foo {}
fn main() {
let foo = Foo {};
let bar = &Foo {};
if foo == bar {
println!("yay");
}
}
Current output
error[E0308]: mismatched types
--> src/main.rs:9:12
|
9 | if foo == bar {
| --- ^^^ expected struct `Foo`, found `&Foo`
| |
| expected because this is `Foo`
|
help: consider using clone here
|
9 | if foo == bar.clone() {
| ++++++++
Desired output
error[E0308]: mismatched types
--> src/main.rs:9:12
|
9 | if foo == bar {
| --- ^^^ expected struct `Foo`, found `&Foo`
| |
| expected because this is `Foo`
|
help: consider dereferencing bar
|
9 | if foo == *bar {
| +
Rationale and extra context
when using relational operators a clone is not necessary, and just dereferencing is more performant (for large types, obviously not in this case) and more readable.
Other cases
No response
Anything else?
No response
@rustbot modify labels +D-papercut
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsD-papercutDiagnostics: An error or lint that needs small tweaks.Diagnostics: An error or lint that needs small tweaks.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
asquared31415 commentedon Apr 18, 2023
An alternate suggestion could be&foo == bar
. Either way, suggesting Clone is not very helpful here.Update: I have been informed that there is not a blanket impl that would make this work.
Rollup merge of rust-lang#110550 - compiler-errors:deref-on-binop-rhs…