1 #![feature(box_syntax)]
4 clippy::needless_pass_by_value,
6 clippy::redundant_clone,
7 clippy::match_single_binding
9 #![warn(clippy::boxed_local)]
30 fn ok_box_trait(boxed_trait: &Box<dyn Z>) {
31 let boxed_local = boxed_trait;
40 fn warn_arg(x: Box<A>) {
44 fn nowarn_closure_arg() {
46 x.map_or((), |x| take_ref(&x));
49 fn warn_rename_call() {
53 y.foo(); // via autoderef
62 take_ref(&bz); // via deref coercion
65 fn nowarn_return() -> Box<A> {
66 box A // moved out, "escapes"
71 drop(bx) // moved in, "escapes"
75 bx.clone(); // method only available to Box, not via autoderef
80 take_box(&bx); // fn needs &Box
83 fn take_box(x: &Box<A>) {}
86 fn nowarn_ref_take() {
87 // false positive, should actually warn
94 let x = box A; // moved into a match
108 fn nowarn_large_array() {
109 // should not warn, is large array
110 // and should not be on stack
111 let x = box [1; 10000];
118 /// ICE regression test
123 impl<'a> Foo for &'a () {
127 pub struct PeekableSeekable<I: Foo> {
131 pub fn new(_needs_name: Box<PeekableSeekable<&()>>) -> () {}
133 /// Regression for #916, #1123
135 /// This shouldn't warn for `boxed_local`as the implementation of a trait
136 /// can't change much about the trait definition.
138 fn do_sth(self: Box<Self>);
141 impl BoxedAction for u64 {
142 fn do_sth(self: Box<Self>) {
143 println!("{}", *self)
147 /// Regression for #1478
149 /// This shouldn't warn for `boxed_local`as self itself is a box type.
154 impl<T> MyTrait for Box<T> {
158 // Issue #3739 - capture in closures
162 fn consume<T>(_: T) {}
163 fn borrow<T>(_: &T) {}
165 fn closure_consume(x: Box<A>) {
171 fn closure_borrow(x: Box<A>) {
180 /// This shouldn't warn for `boxed_local` as it is intended to called from non-Rust code.
181 pub extern "C" fn do_not_warn_me(_c_pointer: Box<String>) -> () {}
183 #[rustfmt::skip] // Forces rustfmt to not add ABI
184 pub extern fn do_not_warn_me_no_abi(_c_pointer: Box<String>) -> () {}