Skip to content

Associated consts from traits not always resolved in match patterns #25017

Closed
@quantheory

Description

@quantheory

Note that the following addition to the associated-const-match-patterns test would fail:

assert!(match Bar::Var1 {
    Foo::THEBAR => true,
    _ => false,
});

However, the existing test uses <Foo>::THEBAR and passes, even though the two syntaxes should be equivalent. There is no particularly deep issue here, I just seem to have been misunderstanding UFCS on the day when I wrote the resolve code involved, and as a result only inherent impls are picked up unless you use angle brackets. I plan to have a PR to fix this and a few other easy issues this weekend.

For future reference, this should be the case for associated constants:

Type::CONST // Equivalent to `<Type>::CONST`
<Type>::CONST // Resolves to `CONST` in an inherent impl if there is one, else a trait impl if not ambiguous.
Trait::CONST // Meaningless; there is absolutely no way to resolve this.
<Trait>::CONST // Currently meaningless, but may be useful if we add constants to the vtable for  trait objects in the future.
<Type as Trait>::CONST // Resolves to the particular impl of `Trait for Type`.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-associated-itemsArea: Associated items (types, constants & functions)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions