]> git.proxmox.com Git - rustc.git/blame - src/tools/clippy/tests/ui/cmp_owned.rs
New upstream version 1.23.0+dfsg1
[rustc.git] / src / tools / clippy / tests / ui / cmp_owned.rs
CommitLineData
abe05a73
XL
1
2
ea8adc8c
XL
3
4#[warn(cmp_owned)]
5#[allow(unnecessary_operation)]
6fn main() {
7 fn with_to_string(x : &str) {
8 x != "foo".to_string();
9
10 "foo".to_string() != x;
11 }
12
13 let x = "oh";
14
15 with_to_string(x);
16
17 x != "foo".to_owned();
18
19 x != String::from("foo");
20
21 42.to_string() == "42";
22
23 Foo.to_owned() == Foo;
24}
25
26struct Foo;
27
28impl PartialEq for Foo {
29 fn eq(&self, other: &Self) -> bool {
30 self.to_owned() == *other
31 }
32}
33
34impl ToOwned for Foo {
35 type Owned = Bar;
36 fn to_owned(&self) -> Bar {
37 Bar
38 }
39}
40
41#[derive(PartialEq)]
42struct Bar;
43
44impl PartialEq<Foo> for Bar {
45 fn eq(&self, _: &Foo) -> bool {
46 true
47 }
48}
49
50impl std::borrow::Borrow<Foo> for Bar {
51 fn borrow(&self) -> &Foo {
52 static FOO: Foo = Foo;
53 &FOO
54 }
55}