Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warn against Type::type methods #7142

Closed
teor2345 opened this issue Apr 28, 2021 · 1 comment · Fixed by #7403
Closed

Warn against Type::type methods #7142

teor2345 opened this issue Apr 28, 2021 · 1 comment · Fixed by #7403
Assignees
Labels
A-lint Area: New lints good-first-issue These issues are a good way to get started with Clippy L-style Lint: Belongs in the style lint group

Comments

@teor2345
Copy link
Contributor

teor2345 commented Apr 28, 2021

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
    }
}
@teor2345 teor2345 added the A-lint Area: New lints label Apr 28, 2021
@camsteffen camsteffen added good-first-issue These issues are a good way to get started with Clippy L-style Lint: Belongs in the style lint group labels May 3, 2021
@Anthuang
Copy link
Contributor

@rustbot claim

bors added a commit that referenced this issue Jul 18, 2021
New lint: [`self_named_constructor`]

Adds the `self_named_constructor` lint for detecting when an implemented method has the same name as the type it is implemented for.

changelog: [`self_named_constructor`]

closes: #7142
@bors bors closed this as completed in f70a074 Jul 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints good-first-issue These issues are a good way to get started with Clippy L-style Lint: Belongs in the style lint group
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants