Skip to content

Warn against Type::type methods #7142

Closed
@teor2345

Description

@teor2345

What it does

Warns when methods have the same name as their type.

Idiomatic Rust typically uses new, from, or from… to create a new value of the type.

Categories (optional)

  • Kind: style

It is easier to read and understand the code, because it is more consistent.

Repeating the name of the type is redundant.

Drawbacks

There might be reasons to repeat the type name?

Example

struct Type {}

impl Type {
    pub fn type() -> Type {
        Type
    }
}

Could be written as:

struct Type {}

impl Type {
    pub fn new() -> Type {
        Type
    }
}

Metadata

Metadata

Assignees

Labels

A-lintArea: New lintsL-styleLint: Belongs in the style lint groupgood first issueThese issues are a good way to get started with Clippy

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions