]> git.lizzy.rs Git - rust.git/blob - tests/ui/trivially_copy_pass_by_ref.rs
Merge pull request #2823 from flip1995/thingies_things
[rust.git] / tests / ui / trivially_copy_pass_by_ref.rs
1 #![allow(many_single_char_names, blacklisted_name, redundant_field_names)]
2
3 #[derive(Copy, Clone)]
4 struct Foo(u32);
5
6 #[derive(Copy, Clone)]
7 struct Bar([u8; 24]);
8
9 struct FooRef<'a> {
10     foo: &'a Foo,
11 }
12
13 type Baz = u32;
14
15 fn good(a: &mut u32, b: u32, c: &Bar) {
16 }
17
18 fn good_return_implicit_lt_ref(foo: &Foo) -> &u32 {
19     &foo.0
20 }
21
22 #[allow(needless_lifetimes)]
23 fn good_return_explicit_lt_ref<'a>(foo: &'a Foo) -> &'a u32 {
24     &foo.0
25 }
26
27 fn good_return_implicit_lt_struct(foo: &Foo) -> FooRef {
28     FooRef {
29         foo,
30     }
31 }
32
33 #[allow(needless_lifetimes)]
34 fn good_return_explicit_lt_struct<'a>(foo: &'a Foo) -> FooRef<'a> {
35     FooRef {
36         foo,
37     }
38 }
39
40 fn bad(x: &u32, y: &Foo, z: &Baz) {
41 }
42
43 impl Foo {
44     fn good(self, a: &mut u32, b: u32, c: &Bar) {
45     }
46
47     fn good2(&mut self) {
48     }
49
50     fn bad(&self, x: &u32, y: &Foo, z: &Baz) {
51     }
52
53     fn bad2(x: &u32, y: &Foo, z: &Baz) {
54     }
55 }
56
57 impl AsRef<u32> for Foo {
58     fn as_ref(&self) -> &u32 {
59         &self.0
60     }
61 }
62
63 impl Bar {
64     fn good(&self, a: &mut u32, b: u32, c: &Bar) {
65     }
66
67     fn bad2(x: &u32, y: &Foo, z: &Baz) {
68     }
69 }
70
71 fn main() {
72     let (mut foo, bar) = (Foo(0), Bar([0; 24]));
73     let (mut a, b, c, x, y, z) = (0, 0, Bar([0; 24]), 0, Foo(0), 0);
74     good(&mut a, b, &c);
75     good_return_implicit_lt_ref(&y);
76     good_return_explicit_lt_ref(&y);
77     bad(&x, &y, &z);
78     foo.good(&mut a, b, &c);
79     foo.good2();
80     foo.bad(&x, &y, &z);
81     Foo::bad2(&x, &y, &z);
82     bar.good(&mut a, b, &c);
83     Bar::bad2(&x, &y, &z);
84     foo.as_ref();
85 }