]> git.lizzy.rs Git - rust.git/blob - tests/ui/trivially_copy_pass_by_ref.rs
Auto merge of #3645 - phansch:remove_copyright_headers, r=oli-obk
[rust.git] / tests / ui / trivially_copy_pass_by_ref.rs
1 #![allow(
2     clippy::many_single_char_names,
3     clippy::blacklisted_name,
4     clippy::redundant_field_names
5 )]
6
7 #[derive(Copy, Clone)]
8 struct Foo(u32);
9
10 #[derive(Copy, Clone)]
11 struct Bar([u8; 24]);
12
13 #[derive(Copy, Clone)]
14 pub struct Color {
15     pub r: u8,
16     pub g: u8,
17     pub b: u8,
18     pub a: u8,
19 }
20
21 struct FooRef<'a> {
22     foo: &'a Foo,
23 }
24
25 type Baz = u32;
26
27 fn good(a: &mut u32, b: u32, c: &Bar) {}
28
29 fn good_return_implicit_lt_ref(foo: &Foo) -> &u32 {
30     &foo.0
31 }
32
33 #[allow(clippy::needless_lifetimes)]
34 fn good_return_explicit_lt_ref<'a>(foo: &'a Foo) -> &'a u32 {
35     &foo.0
36 }
37
38 fn good_return_implicit_lt_struct(foo: &Foo) -> FooRef {
39     FooRef { foo }
40 }
41
42 #[allow(clippy::needless_lifetimes)]
43 fn good_return_explicit_lt_struct<'a>(foo: &'a Foo) -> FooRef<'a> {
44     FooRef { foo }
45 }
46
47 fn bad(x: &u32, y: &Foo, z: &Baz) {}
48
49 impl Foo {
50     fn good(self, a: &mut u32, b: u32, c: &Bar) {}
51
52     fn good2(&mut self) {}
53
54     fn bad(&self, x: &u32, y: &Foo, z: &Baz) {}
55
56     fn bad2(x: &u32, y: &Foo, z: &Baz) {}
57 }
58
59 impl AsRef<u32> for Foo {
60     fn as_ref(&self) -> &u32 {
61         &self.0
62     }
63 }
64
65 impl Bar {
66     fn good(&self, a: &mut u32, b: u32, c: &Bar) {}
67
68     fn bad2(x: &u32, y: &Foo, z: &Baz) {}
69 }
70
71 trait MyTrait {
72     fn trait_method(&self, _foo: &Foo);
73 }
74
75 pub trait MyTrait2 {
76     fn trait_method2(&self, _color: &Color);
77 }
78
79 impl MyTrait for Foo {
80     fn trait_method(&self, _foo: &Foo) {
81         unimplemented!()
82     }
83 }
84
85 fn main() {
86     let (mut foo, bar) = (Foo(0), Bar([0; 24]));
87     let (mut a, b, c, x, y, z) = (0, 0, Bar([0; 24]), 0, Foo(0), 0);
88     good(&mut a, b, &c);
89     good_return_implicit_lt_ref(&y);
90     good_return_explicit_lt_ref(&y);
91     bad(&x, &y, &z);
92     foo.good(&mut a, b, &c);
93     foo.good2();
94     foo.bad(&x, &y, &z);
95     Foo::bad2(&x, &y, &z);
96     bar.good(&mut a, b, &c);
97     Bar::bad2(&x, &y, &z);
98     foo.as_ref();
99 }