]> git.lizzy.rs Git - rust.git/blob - tests/ui/trivially_copy_pass_by_ref.rs
Merge pull request #2803 from Nemo157/trivially_copy_pass_by_ref
[rust.git] / tests / ui / trivially_copy_pass_by_ref.rs
1 #![allow(many_single_char_names, blacklisted_name)]
2
3 #[derive(Copy, Clone)]
4 struct Foo(u32);
5
6 #[derive(Copy, Clone)]
7 struct Bar([u8; 24]);
8
9 type Baz = u32;
10
11 fn good(a: &mut u32, b: u32, c: &Bar) {
12 }
13
14 fn bad(x: &u32, y: &Foo, z: &Baz) {
15 }
16
17 impl Foo {
18     fn good(self, a: &mut u32, b: u32, c: &Bar) {
19     }
20
21     fn good2(&mut self) {
22     }
23
24     fn bad(&self, x: &u32, y: &Foo, z: &Baz) {
25     }
26
27     fn bad2(x: &u32, y: &Foo, z: &Baz) {
28     }
29 }
30
31 impl AsRef<u32> for Foo {
32     fn as_ref(&self) -> &u32 {
33         &self.0
34     }
35 }
36
37 impl Bar {
38     fn good(&self, a: &mut u32, b: u32, c: &Bar) {
39     }
40
41     fn bad2(x: &u32, y: &Foo, z: &Baz) {
42     }
43 }
44
45 fn main() {
46     let (mut foo, bar) = (Foo(0), Bar([0; 24]));
47     let (mut a, b, c, x, y, z) = (0, 0, Bar([0; 24]), 0, Foo(0), 0);
48     good(&mut a, b, &c);
49     bad(&x, &y, &z);
50     foo.good(&mut a, b, &c);
51     foo.good2();
52     foo.bad(&x, &y, &z);
53     Foo::bad2(&x, &y, &z);
54     bar.good(&mut a, b, &c);
55     Bar::bad2(&x, &y, &z);
56     foo.as_ref();
57 }