Skip to content

Associated types with the same name as a function make an unimplementable trait #35600

Closed
@talchas

Description

@talchas
trait Foo {
    type bar;
    fn bar();
}

is accepted (though generally considered bad style), but is unimplementable:

impl Foo for () {
    type bar = ();
    fn bar() {
    }
}

gives the error "item bar is an associated method, which doesn't match its trait <() as Foo>"

This seems kinda silly. Allowing this non-conflicting name reuse might be useful for macros as long as procedural macros don't yet exist and concat_idents is useless. Forbidding it outright seems fine, but should be done at the trait definition.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-associated-itemsArea: Associated items (types, constants & functions)A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-feature-requestCategory: A feature request, i.e: not implemented / a PR.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions