]> git.lizzy.rs Git - rust.git/blob - tests/ui/cmp_owned.rs
Auto merge of #4314 - chansuke:add-negation-to-is_empty, r=flip1995
[rust.git] / tests / ui / cmp_owned.rs
1 #[warn(clippy::cmp_owned)]
2 #[allow(clippy::unnecessary_operation)]
3 fn main() {
4     fn with_to_string(x: &str) {
5         x != "foo".to_string();
6
7         "foo".to_string() != x;
8     }
9
10     let x = "oh";
11
12     with_to_string(x);
13
14     x != "foo".to_owned();
15
16     x != String::from("foo");
17
18     42.to_string() == "42";
19
20     Foo.to_owned() == Foo;
21
22     "abc".chars().filter(|c| c.to_owned() != 'X');
23
24     "abc".chars().filter(|c| *c != 'X');
25
26     let x = &Baz;
27     let y = &Baz;
28
29     y.to_owned() == *x;
30
31     let x = &&Baz;
32     let y = &Baz;
33
34     y.to_owned() == **x;
35 }
36
37 struct Foo;
38
39 impl PartialEq for Foo {
40     fn eq(&self, other: &Self) -> bool {
41         self.to_owned() == *other
42     }
43 }
44
45 impl ToOwned for Foo {
46     type Owned = Bar;
47     fn to_owned(&self) -> Bar {
48         Bar
49     }
50 }
51
52 #[derive(PartialEq)]
53 struct Bar;
54
55 impl PartialEq<Foo> for Bar {
56     fn eq(&self, _: &Foo) -> bool {
57         true
58     }
59 }
60
61 impl std::borrow::Borrow<Foo> for Bar {
62     fn borrow(&self) -> &Foo {
63         static FOO: Foo = Foo;
64         &FOO
65     }
66 }
67
68 #[derive(PartialEq)]
69 struct Baz;
70
71 impl ToOwned for Baz {
72     type Owned = Baz;
73     fn to_owned(&self) -> Baz {
74         Baz
75     }
76 }