Skip to content

Cannot define the same inherent method in disjoint blocks #19097

Closed
@aturon

Description

@aturon

Currently, the following fails to compile:

struct Foo<T>;

impl<'a, T> Foo<&'a T> {
    fn foo(&self) {}
}
impl<'a, T> Foo<&'a mut T> {
    fn foo(&self) {}
}

The error:

<anon>:7:5: 7:21 error: duplicate definition of value `foo`
<anon>:7     fn foo(&self) {}
             ^~~~~~~~~~~~~~~~
<anon>:4:5: 4:21 note: first definition of value `foo` here
<anon>:4     fn foo(&self) {}
             ^~~~~~~~~~~~~~~~

If you construct an analogous situation using two separate impls of a trait providing foo, it works just fine, because there is no overlap. Inherent impl blocks could be similarly flexible.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-type-systemArea: Type systemE-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions