1 // normalize-stderr-test "\(\d+ byte\)" -> "(N byte)"
2 // normalize-stderr-test "\(limit: \d+ byte\)" -> "(limit: N byte)"
4 #![deny(clippy::trivially_copy_pass_by_ref)]
5 #![allow(clippy::blacklisted_name, clippy::redundant_field_names)]
10 #[derive(Copy, Clone)]
13 #[derive(Copy, Clone)]
27 fn good(a: &mut u32, b: u32, c: &Bar) {}
29 fn good_return_implicit_lt_ref(foo: &Foo) -> &u32 {
33 #[allow(clippy::needless_lifetimes)]
34 fn good_return_explicit_lt_ref<'a>(foo: &'a Foo) -> &'a u32 {
38 fn good_return_implicit_lt_struct(foo: &Foo) -> FooRef {
42 #[allow(clippy::needless_lifetimes)]
43 fn good_return_explicit_lt_struct<'a>(foo: &'a Foo) -> FooRef<'a> {
47 fn bad(x: &u32, y: &Foo, z: &Baz) {}
50 fn good(self, a: &mut u32, b: u32, c: &Bar) {}
52 fn good2(&mut self) {}
54 fn bad(&self, x: &u32, y: &Foo, z: &Baz) {}
56 fn bad2(x: &u32, y: &Foo, z: &Baz) {}
58 fn bad_issue7518(self, other: &Self) {}
61 impl AsRef<u32> for Foo {
62 fn as_ref(&self) -> &u32 {
68 fn good(&self, a: &mut u32, b: u32, c: &Bar) {}
70 fn bad2(x: &u32, y: &Foo, z: &Baz) {}
74 fn trait_method(&self, _foo: &Foo);
78 fn trait_method2(&self, _color: &Color);
81 impl MyTrait for Foo {
82 fn trait_method(&self, _foo: &Foo) {
87 #[allow(unused_variables)]
90 #[allow(clippy::trivially_copy_pass_by_ref)]
94 #[allow(clippy::trivially_copy_pass_by_ref)]
99 // Don't lint here as it is always inlined
101 fn foo_always(x: &i32) {
106 fn foo_never(x: &i32) {
116 fn _ref_to_opt_ref_implicit(x: &u32) -> Option<&u32> {
120 #[allow(clippy::needless_lifetimes)]
121 fn _ref_to_opt_ref_explicit<'a>(x: &'a u32) -> Option<&'a u32> {
125 fn _with_constraint<'a, 'b: 'a>(x: &'b u32, y: &'a u32) -> &'a u32 {
126 if true { x } else { y }
129 async fn _async_implicit(x: &u32) -> &u32 {
133 #[allow(clippy::needless_lifetimes)]
134 async fn _async_explicit<'a>(x: &'a u32) -> &'a u32 {
138 fn _unrelated_lifetimes<'a, 'b>(_x: &'a u32, y: &'b u32) -> &'b u32 {
142 fn _return_ptr(x: &u32) -> *const u32 {
146 fn _return_field_ptr(x: &(u32, u32)) -> *const u32 {
150 fn _return_field_ptr_addr_of(x: &(u32, u32)) -> *const u32 {
151 core::ptr::addr_of!(x.0)
155 let (mut foo, bar) = (Foo(0), Bar([0; 24]));
156 let (mut a, b, c, x, y, z) = (0, 0, Bar([0; 24]), 0, Foo(0), 0);
158 good_return_implicit_lt_ref(&y);
159 good_return_explicit_lt_ref(&y);
161 foo.good(&mut a, b, &c);
164 Foo::bad2(&x, &y, &z);
165 bar.good(&mut a, b, &c);
166 Bar::bad2(&x, &y, &z);