Skip to content

method_duplicate_name #7632

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

Closed
lengyijun opened this issue Sep 4, 2021 · 0 comments · Fixed by #7653
Closed

method_duplicate_name #7632

lengyijun opened this issue Sep 4, 2021 · 0 comments · Fixed by #7653
Labels
A-lint Area: New lints good first issue These issues are a good way to get started with Clippy L-pedantic Lint: Belongs in the pedantic lint group

Comments

@lengyijun
Copy link
Contributor

What it does

What does this lint do?

A struct has two methods with the same name:
one defined in impl trait, another in normal impl.

We shouldn't lint two method in two traits.This may break a lot. (I'm not sure)

Categories

clippy::all, clippy::style

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

  • Remove confusing method call.

Drawbacks

Maybe meet difficulty in renaming the methods.

Example

trait T1 {
    fn foo(&self) {}
}

struct S;

impl S {
    fn foo(&self) {
        dbg!("impl");
    }
}

impl T1 for S {
    fn foo(&self) {
        dbg!("T1");
    }
}

fn bar<T: T1>(x: T) {
    x.foo(); // which foo?
}

fn main() {
    bar(S);

    let s = S;
    s.foo(); // which foo?
}
@lengyijun lengyijun added the A-lint Area: New lints label Sep 4, 2021
@flip1995 flip1995 added good first issue These issues are a good way to get started with Clippy L-pedantic Lint: Belongs in the pedantic lint group labels Sep 8, 2021
@bors bors closed this as completed in ed7a82e Sep 17, 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-pedantic Lint: Belongs in the pedantic lint group
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants