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)]
11 #![allow(clippy::borrowed_box, clippy::needless_pass_by_value, clippy::unused_unit)]
12 #![warn(clippy::boxed_local)]
33 fn ok_box_trait(boxed_trait: &Box<Z>) {
34 let boxed_local = boxed_trait;
43 fn warn_arg(x: Box<A>) {
47 fn nowarn_closure_arg() {
49 x.map_or((), |x| take_ref(&x));
52 fn warn_rename_call() {
56 y.foo(); // via autoderef
65 take_ref(&bz); // via deref coercion
68 fn nowarn_return() -> Box<A> {
69 box A // moved out, "escapes"
74 drop(bx) // moved in, "escapes"
78 bx.clone(); // method only available to Box, not via autoderef
83 take_box(&bx); // fn needs &Box
86 fn take_box(x: &Box<A>) {}
89 fn nowarn_ref_take() {
90 // false positive, should actually warn
97 let x = box A; // moved into a match
111 fn nowarn_large_array() {
112 // should not warn, is large array
113 // and should not be on stack
114 let x = box [1; 10000];
121 /// ICE regression test
126 impl<'a> Foo for &'a () {
130 pub struct PeekableSeekable<I: Foo> {
134 pub fn new(_needs_name: Box<PeekableSeekable<&()>>) -> () {}
136 /// Regression for #916, #1123
138 /// This shouldn't warn for `boxed_local`as the implementation of a trait
139 /// can't change much about the trait definition.
141 fn do_sth(self: Box<Self>);
144 impl BoxedAction for u64 {
145 fn do_sth(self: Box<Self>) {
146 println!("{}", *self)
150 /// Regression for #1478
152 /// This shouldn't warn for `boxed_local`as self itself is a box type.
157 impl<T> MyTrait for Box<T> {