]> git.proxmox.com Git - rustc.git/blob - src/tools/clippy/tests/ui/cmp_owned/with_suggestion.fixed
New upstream version 1.74.1+dfsg1
[rustc.git] / src / tools / clippy / tests / ui / cmp_owned / with_suggestion.fixed
1 #[warn(clippy::cmp_owned)]
2 #[allow(clippy::unnecessary_operation, clippy::no_effect, unused_must_use, clippy::eq_op)]
3 fn main() {
4 fn with_to_string(x: &str) {
5 x != "foo";
6
7 "foo" != x;
8 }
9
10 let x = "oh";
11
12 with_to_string(x);
13
14 x != "foo";
15
16 x != "foo";
17
18 42.to_string() == "42";
19
20 Foo == Foo;
21
22 "abc".chars().filter(|c| *c != 'X');
23
24 "abc".chars().filter(|c| *c != 'X');
25 }
26
27 struct Foo;
28
29 impl PartialEq for Foo {
30 // Allow this here, because it emits the lint
31 // without a suggestion. This is tested in
32 // `$DIR/without_suggestion.rs`
33 #[allow(clippy::cmp_owned)]
34 fn eq(&self, other: &Self) -> bool {
35 self.to_owned() == *other
36 }
37 }
38
39 impl ToOwned for Foo {
40 type Owned = Bar;
41 fn to_owned(&self) -> Bar {
42 Bar
43 }
44 }
45
46 #[derive(PartialEq, Eq)]
47 struct Bar;
48
49 impl PartialEq<Foo> for Bar {
50 fn eq(&self, _: &Foo) -> bool {
51 true
52 }
53 }
54
55 impl std::borrow::Borrow<Foo> for Bar {
56 fn borrow(&self) -> &Foo {
57 static FOO: Foo = Foo;
58 &FOO
59 }
60 }
61
62 #[derive(PartialEq, Eq)]
63 struct Baz;
64
65 impl ToOwned for Baz {
66 type Owned = Baz;
67 fn to_owned(&self) -> Baz {
68 Baz
69 }
70 }