]> git.lizzy.rs Git - rust.git/blob - tests/ui/trivially_copy_pass_by_ref.rs
Adapt the *.stderr files of the ui-tests to the tool_lints
[rust.git] / tests / ui / trivially_copy_pass_by_ref.rs
1 #![feature(tool_lints)]
2
3 #![allow(clippy::many_single_char_names, clippy::blacklisted_name, clippy::redundant_field_names)]
4
5 #[derive(Copy, Clone)]
6 struct Foo(u32);
7
8 #[derive(Copy, Clone)]
9 struct Bar([u8; 24]);
10
11 struct FooRef<'a> {
12     foo: &'a Foo,
13 }
14
15 type Baz = u32;
16
17 fn good(a: &mut u32, b: u32, c: &Bar) {
18 }
19
20 fn good_return_implicit_lt_ref(foo: &Foo) -> &u32 {
21     &foo.0
22 }
23
24 #[allow(clippy::needless_lifetimes)]
25 fn good_return_explicit_lt_ref<'a>(foo: &'a Foo) -> &'a u32 {
26     &foo.0
27 }
28
29 fn good_return_implicit_lt_struct(foo: &Foo) -> FooRef {
30     FooRef {
31         foo,
32     }
33 }
34
35 #[allow(clippy::needless_lifetimes)]
36 fn good_return_explicit_lt_struct<'a>(foo: &'a Foo) -> FooRef<'a> {
37     FooRef {
38         foo,
39     }
40 }
41
42 fn bad(x: &u32, y: &Foo, z: &Baz) {
43 }
44
45 impl Foo {
46     fn good(self, a: &mut u32, b: u32, c: &Bar) {
47     }
48
49     fn good2(&mut self) {
50     }
51
52     fn bad(&self, x: &u32, y: &Foo, z: &Baz) {
53     }
54
55     fn bad2(x: &u32, y: &Foo, z: &Baz) {
56     }
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
69     fn bad2(x: &u32, y: &Foo, z: &Baz) {
70     }
71 }
72
73 fn main() {
74     let (mut foo, bar) = (Foo(0), Bar([0; 24]));
75     let (mut a, b, c, x, y, z) = (0, 0, Bar([0; 24]), 0, Foo(0), 0);
76     good(&mut a, b, &c);
77     good_return_implicit_lt_ref(&y);
78     good_return_explicit_lt_ref(&y);
79     bad(&x, &y, &z);
80     foo.good(&mut a, b, &c);
81     foo.good2();
82     foo.bad(&x, &y, &z);
83     Foo::bad2(&x, &y, &z);
84     bar.good(&mut a, b, &c);
85     Bar::bad2(&x, &y, &z);
86     foo.as_ref();
87 }