Skip to content

RFC: Change operator method lookup to be less magical #4920

@nikomatsakis

Description

@nikomatsakis
Contributor

Right now, operator "methods" proceed according to the same logic as any other method. But this leads to surprising results like this: https://gist.github.com/bstrie/4948410

Also, operators are already handled somewhat specially because we auto-ref their arguments. This means that you can write val1-of-my-linear-type == val2-of-my-linear-type and it doesn't move or do anything creepy (to call eq explicitly, in contrast, you'd write val1-of-my-linear-type.eq(&val2-of-my-linear-type)).

I think method lookup for operators should never apply any automatic transformations to the receiver or arguments, other than the current auto-ref behavior (which means that a OP b is kind of implicitly (&a).OP(&b))

@pcwalton I expect you in particular might have an opinion about this.

Activity

nikomatsakis

nikomatsakis commented on Mar 26, 2013

@nikomatsakis
ContributorAuthor

I think this should apply also to unary operators and the [] operator, except that [] autoderefs its receiver (as it does normally).

nikomatsakis

nikomatsakis commented on Mar 26, 2013

@nikomatsakis
ContributorAuthor
nikomatsakis

nikomatsakis commented on Mar 26, 2013

@nikomatsakis
ContributorAuthor

It seems that we only partially discussed this issue in the meeting. In particular, we did not discuss:

  1. Removing argument coercions from uses of overloaded operators
  2. Extending auto-ref to the argument of the [] operator, which seems useful for hashtables

On point 2, currently a[b] is converted to a.index(b) but if we extended autoref (as we do with all other operators) it would be equivalent to a.index(&b).

graydon

graydon commented on Mar 26, 2013

@graydon
Contributor

seems reasonable to me

graydon

graydon commented on May 22, 2013

@graydon
Contributor

Looks like this was merged in #5558 .. @nikomatsakis can this close?

pnkfelix

pnkfelix commented on Sep 4, 2013

@pnkfelix
Member

Visiting for triage, email from 2013-09-02.

Nominating for milestone 1, well-defined.

(Of course, its possible that graydon's hypothesis that this might be closeable is true. @nikomatsakis, any thoughts?)

nikomatsakis

nikomatsakis commented on Sep 5, 2013

@nikomatsakis
ContributorAuthor

Not closeable in that point 1 remains unresolved: do we want to coerce arguments? I remember @pcwalton had this on the agenda recently (under the guise of == operations).

catamorphism

catamorphism commented on Sep 5, 2013

@catamorphism
Contributor

Accepted for milestone 1, well-defined

flaper87

flaper87 commented on Feb 12, 2014

@flaper87
Contributor

Triage bump, this still needs some work.

22 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-trait-systemArea: Trait systemA-type-systemArea: Type systemC-cleanupCategory: PRs that clean code up or issues documenting cleanup.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    Participants

    @flaper87@graydon@nikomatsakis@pnkfelix@catamorphism

    Issue actions

      RFC: Change operator method lookup to be less magical · Issue #4920 · rust-lang/rust