-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Description
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 commentedon Mar 26, 2013
I think this should apply also to unary operators and the
[]
operator, except that[]
autoderefs its receiver (as it does normally).nikomatsakis commentedon Mar 26, 2013
Discussed in meeting: https://github.com/mozilla/rust/wiki/Meeting-weekly-2013-03-12
nikomatsakis commentedon Mar 26, 2013
It seems that we only partially discussed this issue in the meeting. In particular, we did not discuss:
[]
operator, which seems useful for hashtablesOn point 2, currently
a[b]
is converted toa.index(b)
but if we extended autoref (as we do with all other operators) it would be equivalent toa.index(&b)
.graydon commentedon Mar 26, 2013
seems reasonable to me
graydon commentedon May 22, 2013
Looks like this was merged in #5558 .. @nikomatsakis can this close?
pnkfelix commentedon Sep 4, 2013
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 commentedon Sep 5, 2013
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 commentedon Sep 5, 2013
Accepted for milestone 1, well-defined
&5i + 5i
compiles but5i + &5i
or&5i == 5i
don't #8895flaper87 commentedon Feb 12, 2014
Triage bump, this still needs some work.
22 remaining items