profile
viewpoint

Ask questionsFalse positive for `boxed_local` with trait default methods

When defining a trait that has a method accepting a self: Box<Self> which has a default implementation on the trait itself, the boxed_local lint is triggered. This was fixed for impls in #3321, but still triggers for traits.

Clippy version: clippy 0.0.212 (b2601be 2018-11-27)

<details> <summary>Example Code</summary>

trait ExampleTrait {
    fn method(self: Box<Self>) { // boxed_local lint triggered here
        unimplemented!()
    }       
}

struct SomeObject;

impl ExampleTrait for SomeObject {}

#[allow(unused_variables)]
fn main() {
    let trait_object: Box<dyn ExampleTrait> = Box::new(SomeObject {});
    trait_object.method();
}

</details>

<details> <summary>clippy output</summary>

warning: local variable doesn't need to be boxed here
 --> src/main.rs:2:15
  |
2 |     fn method(self: Box<Self>) {
  |               ^^^^
  |
  = note: #[warn(clippy::boxed_local)] on by default
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#boxed_local

</details>

rust-lang/rust-clippy

Answer questions mikerite

method(self: Box<Self>) can't be replaced with method(self) because the Self isn't sized, but couldn't you change it to method(&self) or method(&mut self) instead?

useful!
source:https://uonfu.com/
Github User Rank List