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