1 // Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution.
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.
10 #![feature(box_syntax)]
12 #![allow(clippy::borrowed_box, clippy::needless_pass_by_value, clippy::unused_unit)]
13 #![warn(clippy::boxed_local)]
35 fn ok_box_trait(boxed_trait: &Box<Z>) {
36 let boxed_local = boxed_trait;
45 fn warn_arg(x: Box<A>) {
49 fn nowarn_closure_arg() {
51 x.map_or((), |x| take_ref(&x));
54 fn warn_rename_call() {
58 y.foo(); // via autoderef
67 take_ref(&bz); // via deref coercion
70 fn nowarn_return() -> Box<A> {
71 box A // moved out, "escapes"
76 drop(bx) // moved in, "escapes"
80 bx.clone(); // method only available to Box, not via autoderef
85 take_box(&bx); // fn needs &Box
89 fn take_box(x: &Box<A>) {}
93 fn nowarn_ref_take() {
94 // false positive, should actually warn
101 let x = box A; // moved into a match
109 match &x { // not moved
114 fn nowarn_large_array() {
115 // should not warn, is large array
116 // and should not be on stack
117 let x = box [1; 10000];
118 match &x { // not moved
124 /// ICE regression test
129 impl<'a> Foo for &'a () {
133 pub struct PeekableSeekable<I: Foo> {
137 pub fn new(_needs_name: Box<PeekableSeekable<&()>>) -> () {
140 /// Regression for #916, #1123
142 /// This shouldn't warn for `boxed_local`as the implementation of a trait
143 /// can't change much about the trait definition.
145 fn do_sth(self: Box<Self>);
148 impl BoxedAction for u64 {
149 fn do_sth(self: Box<Self>) {
150 println!("{}", *self)
154 /// Regression for #1478
156 /// This shouldn't warn for `boxed_local`as self itself is a box type.
161 impl<T> MyTrait for Box<T> {