Skip to content

RFC: Define binary operator traits using associated fns, not methods. #6299

Closed
@nikomatsakis

Description

@nikomatsakis

There has been a constant stream of confusion relating to the interaction between auto-deref and various overloaded operators, particularly Eq (e.g., #6257). I think we ought to define the binary operator traits using an associated fn, not a method. This would side-step any issues around autoderef, and also helps to make the method resolution clearer.

For example, Eq would be define as follows:

trait Eq {
    fn eq(a: &Self, b: &Self);
}

meaning that x==y would be expanded to:

Eq::eq(&x, &y)

The same would apply to other binary operator traits.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions