]> git.proxmox.com Git - rustc.git/blob - src/tools/clippy/tests/ui/cmp_owned/without_suggestion.rs
New upstream version 1.74.1+dfsg1
[rustc.git] / src / tools / clippy / tests / ui / cmp_owned / without_suggestion.rs
1 #[allow(clippy::unnecessary_operation)]
2 #[allow(clippy::implicit_clone)]
3
4 fn main() {
5 let x = &Baz;
6 let y = &Baz;
7 y.to_owned() == *x;
8 //~^ ERROR: this creates an owned instance just for comparison
9 //~| NOTE: `-D clippy::cmp-owned` implied by `-D warnings`
10
11 let x = &&Baz;
12 let y = &Baz;
13 y.to_owned() == **x;
14 //~^ ERROR: this creates an owned instance just for comparison
15
16 let x = 0u32;
17 let y = U32Wrapper(x);
18 let _ = U32Wrapper::from(x) == y;
19 }
20
21 struct Foo;
22
23 impl PartialEq for Foo {
24 fn eq(&self, other: &Self) -> bool {
25 self.to_owned() == *other
26 //~^ ERROR: this creates an owned instance just for comparison
27 }
28 }
29
30 impl ToOwned for Foo {
31 type Owned = Bar;
32 fn to_owned(&self) -> Bar {
33 Bar
34 }
35 }
36
37 #[derive(PartialEq, Eq)]
38 struct Baz;
39
40 impl ToOwned for Baz {
41 type Owned = Baz;
42 fn to_owned(&self) -> Baz {
43 Baz
44 }
45 }
46
47 #[derive(PartialEq, Eq)]
48 struct Bar;
49
50 impl PartialEq<Foo> for Bar {
51 fn eq(&self, _: &Foo) -> bool {
52 true
53 }
54 }
55
56 impl std::borrow::Borrow<Foo> for Bar {
57 fn borrow(&self) -> &Foo {
58 static FOO: Foo = Foo;
59 &FOO
60 }
61 }
62
63 #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
64 struct U32Wrapper(u32);
65 impl From<u32> for U32Wrapper {
66 fn from(x: u32) -> Self {
67 Self(x)
68 }
69 }
70 impl PartialEq<u32> for U32Wrapper {
71 fn eq(&self, other: &u32) -> bool {
72 self.0 == *other
73 }
74 }
75 impl PartialEq<U32Wrapper> for u32 {
76 fn eq(&self, other: &U32Wrapper) -> bool {
77 *self == other.0
78 }
79 }