1 // normalize-stderr-test "\(\d+ byte\)" -> "(N byte)"
2 // normalize-stderr-test "\(limit: \d+ byte\)" -> "(limit: N byte)"
3 #![deny(clippy::trivially_copy_pass_by_ref)]
5 clippy::disallowed_names,
6 clippy::redundant_field_names,
7 clippy::uninlined_format_args
10 #[derive(Copy, Clone)]
13 #[derive(Copy, Clone)]
16 #[derive(Copy, Clone)]
30 fn good(a: &mut u32, b: u32, c: &Bar) {}
32 fn good_return_implicit_lt_ref(foo: &Foo) -> &u32 {
36 #[allow(clippy::needless_lifetimes)]
37 fn good_return_explicit_lt_ref<'a>(foo: &'a Foo) -> &'a u32 {
41 fn good_return_implicit_lt_struct(foo: &Foo) -> FooRef {
45 #[allow(clippy::needless_lifetimes)]
46 fn good_return_explicit_lt_struct<'a>(foo: &'a Foo) -> FooRef<'a> {
50 fn bad(x: &u32, y: &Foo, z: &Baz) {}
53 fn good(self, a: &mut u32, b: u32, c: &Bar) {}
55 fn good2(&mut self) {}
57 fn bad(&self, x: &u32, y: &Foo, z: &Baz) {}
59 fn bad2(x: &u32, y: &Foo, z: &Baz) {}
61 fn bad_issue7518(self, other: &Self) {}
64 impl AsRef<u32> for Foo {
65 fn as_ref(&self) -> &u32 {
71 fn good(&self, a: &mut u32, b: u32, c: &Bar) {}
73 fn bad2(x: &u32, y: &Foo, z: &Baz) {}
77 fn trait_method(&self, _foo: &Foo);
81 fn trait_method2(&self, _color: &Color);
84 impl MyTrait for Foo {
85 fn trait_method(&self, _foo: &Foo) {
90 #[allow(unused_variables)]
93 #[allow(clippy::trivially_copy_pass_by_ref)]
97 #[allow(clippy::trivially_copy_pass_by_ref)]
102 // Don't lint here as it is always inlined
104 fn foo_always(x: &i32) {
109 fn foo_never(x: &i32) {
119 fn _ref_to_opt_ref_implicit(x: &u32) -> Option<&u32> {
123 #[allow(clippy::needless_lifetimes)]
124 fn _ref_to_opt_ref_explicit<'a>(x: &'a u32) -> Option<&'a u32> {
128 fn _with_constraint<'a, 'b: 'a>(x: &'b u32, y: &'a u32) -> &'a u32 {
129 if true { x } else { y }
132 async fn _async_implicit(x: &u32) -> &u32 {
136 #[allow(clippy::needless_lifetimes)]
137 async fn _async_explicit<'a>(x: &'a u32) -> &'a u32 {
141 fn _unrelated_lifetimes<'a, 'b>(_x: &'a u32, y: &'b u32) -> &'b u32 {
145 fn _return_ptr(x: &u32) -> *const u32 {
149 fn _return_field_ptr(x: &(u32, u32)) -> *const u32 {
153 fn _return_field_ptr_addr_of(x: &(u32, u32)) -> *const u32 {
154 core::ptr::addr_of!(x.0)
158 let (mut foo, bar) = (Foo(0), Bar([0; 24]));
159 let (mut a, b, c, x, y, z) = (0, 0, Bar([0; 24]), 0, Foo(0), 0);
161 good_return_implicit_lt_ref(&y);
162 good_return_explicit_lt_ref(&y);
164 foo.good(&mut a, b, &c);
167 Foo::bad2(&x, &y, &z);
168 bar.good(&mut a, b, &c);
169 Bar::bad2(&x, &y, &z);