Skip to content

False positive for boxed_local with trait default methods #3739

Closed
@dmarcuse

Description

@dmarcuse

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)

Example Code
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();
}
clippy output
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

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thing

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions