Skip to content

method_duplicate_name #7632

Closed
Closed
@lengyijun

Description

@lengyijun

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?
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lintsL-pedanticLint: Belongs in the pedantic 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