Skip to content

Detect redundant Default implementations #7550

@tsoutsman

Description

@tsoutsman

What it does

Detects custom std::default::Default implementations that are identical to a derived implementation. This could probably be done with other derive attributes, but I think Default is a fairly common one that people may implement themselves.

Categories (optional)

  • Kind: clippy::style

What is the advantage of the recommended code over the original code

It is more concise.

Drawbacks

I have no clue about the internals of Clippy, so I'm not sure how hard it would be to implement.

Example

struct Foo {
    bar: bool
}

impl std::default::Default for Foo {
    fn default() -> Self {
        Self {
            bar: false
        }
    }
}

Could be written as:

#[derive(Default)]
struct Foo {
    bar: bool
}

Metadata

Metadata

Assignees

Labels

A-lintArea: New lints

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions