]> git.lizzy.rs Git - rust.git/blob - tests/ui/cmp_owned.rs
Merge pull request #2984 from flip1995/single_char_pattern
[rust.git] / tests / ui / cmp_owned.rs
1
2
3
4 #[warn(cmp_owned)]
5 #[allow(unnecessary_operation)]
6 fn 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
26 struct Foo;
27
28 impl PartialEq for Foo {
29     fn eq(&self, other: &Self) -> bool {
30         self.to_owned() == *other
31     }
32 }
33
34 impl ToOwned for Foo {
35     type Owned = Bar;
36     fn to_owned(&self) -> Bar {
37         Bar
38     }
39 }
40
41 #[derive(PartialEq)]
42 struct Bar;
43
44 impl PartialEq<Foo> for Bar {
45     fn eq(&self, _: &Foo) -> bool {
46         true
47     }
48 }
49
50 impl std::borrow::Borrow<Foo> for Bar {
51     fn borrow(&self) -> &Foo {
52         static FOO: Foo = Foo;
53         &FOO
54     }
55 }