Closed
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