]> git.lizzy.rs Git - rust.git/blob - tests/ui/trivially_copy_pass_by_ref.rs
Add license header to Rust files
[rust.git] / tests / ui / trivially_copy_pass_by_ref.rs
1 // Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution.
3 //
4 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7 // option. This file may not be copied, modified, or distributed
8 // except according to those terms.
9
10
11 #![feature(tool_lints)]
12
13 #![allow(clippy::many_single_char_names, clippy::blacklisted_name, clippy::redundant_field_names)]
14
15 #[derive(Copy, Clone)]
16 struct Foo(u32);
17
18 #[derive(Copy, Clone)]
19 struct Bar([u8; 24]);
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
30 fn good_return_implicit_lt_ref(foo: &Foo) -> &u32 {
31     &foo.0
32 }
33
34 #[allow(clippy::needless_lifetimes)]
35 fn good_return_explicit_lt_ref<'a>(foo: &'a Foo) -> &'a u32 {
36     &foo.0
37 }
38
39 fn good_return_implicit_lt_struct(foo: &Foo) -> FooRef {
40     FooRef {
41         foo,
42     }
43 }
44
45 #[allow(clippy::needless_lifetimes)]
46 fn good_return_explicit_lt_struct<'a>(foo: &'a Foo) -> FooRef<'a> {
47     FooRef {
48         foo,
49     }
50 }
51
52 fn bad(x: &u32, y: &Foo, z: &Baz) {
53 }
54
55 impl Foo {
56     fn good(self, a: &mut u32, b: u32, c: &Bar) {
57     }
58
59     fn good2(&mut self) {
60     }
61
62     fn bad(&self, x: &u32, y: &Foo, z: &Baz) {
63     }
64
65     fn bad2(x: &u32, y: &Foo, z: &Baz) {
66     }
67 }
68
69 impl AsRef<u32> for Foo {
70     fn as_ref(&self) -> &u32 {
71         &self.0
72     }
73 }
74
75 impl Bar {
76     fn good(&self, a: &mut u32, b: u32, c: &Bar) {
77     }
78
79     fn bad2(x: &u32, y: &Foo, z: &Baz) {
80     }
81 }
82
83 fn main() {
84     let (mut foo, bar) = (Foo(0), Bar([0; 24]));
85     let (mut a, b, c, x, y, z) = (0, 0, Bar([0; 24]), 0, Foo(0), 0);
86     good(&mut a, b, &c);
87     good_return_implicit_lt_ref(&y);
88     good_return_explicit_lt_ref(&y);
89     bad(&x, &y, &z);
90     foo.good(&mut a, b, &c);
91     foo.good2();
92     foo.bad(&x, &y, &z);
93     Foo::bad2(&x, &y, &z);
94     bar.good(&mut a, b, &c);
95     Bar::bad2(&x, &y, &z);
96     foo.as_ref();
97 }