Skip to content

"Duplicate method" error should point to previous definition #32971

Closed
@jonas-schievink

Description

@jonas-schievink

(same goes for "duplicate associated function" and similar errors)

I was playing around with macro-generated methods, and stumbled upon a bad diagnostic:

struct S;

macro_rules! methods {
    ( $($name:ident)* ) => {
        $( fn $name(&self) {} )*
    }
}

impl S {
    fn a(&self) {}

    methods!(a b c);
}

fn main() {}

gives:

<anon>:5:12: 5:30 error: duplicate method [E0201]
<anon>:5         $( fn $name(&self) {} )*
                    ^~~~~~~~~~~~~~~~~~
<anon>:12:5: 12:21 note: in this expansion of methods! (defined in <anon>)

Rustc should print a note: previous definition here and include the name of the method in the diagnostic (since both could be defined by macros, in which case the name will not be obvious).

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions