Skip to content

False positive for boxed local in default Trait method implementation #4804

Closed
@MentalAllergen

Description

@MentalAllergen

Output of cargo clippy -V: clippy 0.0.212 (3aea8603 2019-09-03)

Given the following code:

trait Foo {
    fn bar(self: Box<Self>) -> u32 {
        5
    }
}

Clippy lint boxed local is triggered, advising us to remove the Box and have plain self in the argument list, like this:

trait Foo {
    fn bar(self) -> u32 {
        5
    }
}

However, doing this makes the code fail compilation with the following error:
the size for values of type "Self" cannot be known at compilation time,
which is always the case for traits.

I've encountered this while implementing the state design pattern with dynamic dispatch. I wouldn't usually opt for dynamic dispatch, however the problem domain requires it.

Ideally this lint should check weather the implementation is a default trait method implementation before triggering.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when applied

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions