Auto merge of #8807 - Jarcho:cmp_owned, r=giraffate

Fix `cmp_owned` on copy types

fixes #8803
fixes #7365

changelog: Don't lint `cmp_owned` on `From::from` for copy types
This commit is contained in:
bors 2022-05-18 00:19:36 +00:00
commit bf2e63104d
3 changed files with 50 additions and 26 deletions

View file

@ -9,6 +9,10 @@ fn main() {
let x = &&Baz;
let y = &Baz;
y.to_owned() == **x;
let x = 0u32;
let y = U32Wrapper(x);
let _ = U32Wrapper::from(x) == y;
}
struct Foo;
@ -51,3 +55,21 @@ impl std::borrow::Borrow<Foo> for Bar {
&FOO
}
}
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
struct U32Wrapper(u32);
impl From<u32> for U32Wrapper {
fn from(x: u32) -> Self {
Self(x)
}
}
impl PartialEq<u32> for U32Wrapper {
fn eq(&self, other: &u32) -> bool {
self.0 == *other
}
}
impl PartialEq<U32Wrapper> for u32 {
fn eq(&self, other: &U32Wrapper) -> bool {
*self == other.0
}
}

View file

@ -13,7 +13,7 @@ LL | y.to_owned() == **x;
| ^^^^^^^^^^^^^^^^^^^ try implementing the comparison without allocating
error: this creates an owned instance just for comparison
--> $DIR/without_suggestion.rs:18:9
--> $DIR/without_suggestion.rs:22:9
|
LL | self.to_owned() == *other
| ^^^^^^^^^^^^^^^^^^^^^^^^^ try implementing the comparison without allocating