Skip to content

Clarify and document operator overloading trait matching rules etc #10337

Closed
@nikomatsakis

Description

@nikomatsakis

Our current trait matching rules for operator overloading are somewhat ad-hoc. I've got a branch which implements a more straightforward set of rules, which I think is what we want for 1.0 going forward. Part of completing this bug will be updating the docs.

The rules I've in mind can be summarized as:

Given an expression l op r where op is a binary operator and l : L and r : R:

  • We search for a trait impl Op<R,T> for L. Note that there is no attempt to autoderef l and so forth.
  • At runtime we'll pass in &l and &r to the trait method (as is reflected in the &self type etc).
  • The type of l op r is T.

Metadata

Metadata

Assignees

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