1 #![feature(box_syntax)]
2 #![feature(lint_reasons)]
5 clippy::needless_pass_by_value,
7 clippy::redundant_clone,
8 clippy::match_single_binding
10 #![warn(clippy::boxed_local)]
31 fn ok_box_trait(boxed_trait: &Box<dyn Z>) {
32 let boxed_local = boxed_trait;
41 fn warn_arg(x: Box<A>) {
45 fn nowarn_closure_arg() {
47 x.map_or((), |x| take_ref(&x));
50 fn warn_rename_call() {
54 y.foo(); // via autoderef
63 take_ref(&bz); // via deref coercion
66 fn nowarn_return() -> Box<A> {
67 box A // moved out, "escapes"
72 drop(bx) // moved in, "escapes"
76 bx.clone(); // method only available to Box, not via autoderef
81 take_box(&bx); // fn needs &Box
84 fn take_box(x: &Box<A>) {}
87 fn nowarn_ref_take() {
88 // false positive, should actually warn
95 let x = box A; // moved into a match
109 fn nowarn_large_array() {
110 // should not warn, is large array
111 // and should not be on stack
112 let x = box [1; 10000];
119 /// ICE regression test
124 impl<'a> Foo for &'a () {
128 pub struct PeekableSeekable<I: Foo> {
132 pub fn new(_needs_name: Box<PeekableSeekable<&()>>) -> () {}
134 /// Regression for #916, #1123
136 /// This shouldn't warn for `boxed_local`as the implementation of a trait
137 /// can't change much about the trait definition.
139 fn do_sth(self: Box<Self>);
142 impl BoxedAction for u64 {
143 fn do_sth(self: Box<Self>) {
144 println!("{}", *self)
148 /// Regression for #1478
150 /// This shouldn't warn for `boxed_local`as self itself is a box type.
155 impl<T> MyTrait for Box<T> {
159 // Issue #3739 - capture in closures
163 fn consume<T>(_: T) {}
164 fn borrow<T>(_: &T) {}
166 fn closure_consume(x: Box<A>) {
172 fn closure_borrow(x: Box<A>) {
181 /// This shouldn't warn for `boxed_local` as it is intended to called from non-Rust code.
182 pub extern "C" fn do_not_warn_me(_c_pointer: Box<String>) -> () {}
184 #[rustfmt::skip] // Forces rustfmt to not add ABI
185 pub extern fn do_not_warn_me_no_abi(_c_pointer: Box<String>) -> () {}
187 // Issue #4804 - default implementation in trait
189 trait DefaultTraitImplTest {
190 // don't warn on `self`
191 fn default_impl(self: Box<Self>) -> u32 {
195 // warn on `x: Box<u32>`
196 fn default_impl_x(self: Box<Self>, x: Box<u32>) -> u32 {
202 // warn on `x: Box<u32>`
203 fn foo(x: Box<u32>) {}
207 fn check_expect(#[expect(clippy::boxed_local)] x: Box<A>) {