@@ -79,33 +79,34 @@ behavior should be reconsidered in light of where clauses.
79
79
TODO: Is this FIXME still accurate?
80
80
81
81
** Extension candidates** are derived from imported traits. If I have
82
- the trait ` ToString ` imported, and I call ` to_string() ` on a value of
83
- type ` T ` , then we will go off to find out whether there is an impl of
84
- ` ToString ` for ` T ` . These kinds of method calls are called "extension
85
- methods". They can be defined in any crate, not only the one that
86
- defined ` T ` . Furthermore, you must import the trait to call such a
87
- method.
82
+ the trait ` ToString ` imported, and I call ` to_string() ` as a method,
83
+ then we will list the ` to_string() ` definition in each impl of
84
+ ` ToString ` as a candidate. These kinds of method calls are called
85
+ "extension methods".
88
86
89
87
So, let's continue our example. Imagine that we were calling a method
90
88
` foo ` with the receiver ` Rc<Box<[T; 3]>> ` and there is a trait ` Foo `
91
89
that defines it with ` &self ` for the type ` Rc<U> ` as well as a method
92
- on the type ` Box ` that defines ` Foo ` but with ` &mut self ` . Then we
90
+ on the type ` Box ` that defines ` foo ` but with ` &mut self ` . Then we
93
91
might have two candidates:
94
92
95
- - ` &Rc<Box<[T; 3]>> ` from the impl of ` Foo ` for ` Rc< U>` where ` U=Box<[T; 3]> `
96
- - ` &mut Box<[T; 3]>> ` from the inherent impl on ` Box<U> ` where ` U=[T; 3] `
93
+ - ` &Rc<U> ` as an extension candidate
94
+ - ` &mut Box<U> ` as an inherent candidate
97
95
98
96
### Candidate search
99
97
100
98
Finally, to actually pick the method, we will search down the steps,
101
99
trying to match the receiver type against the candidate types. At
102
100
each step, we also consider an auto-ref and auto-mut-ref to see whether
103
- that makes any of the candidates match. We pick the first step where
104
- we find a match.
101
+ that makes any of the candidates match. For each resulting receiver
102
+ type, we consider inherent candidates before extension candidates.
103
+ If there are multiple matching candidates in a group, we report an
104
+ error, except that multiple impls of the same trait are treated as a
105
+ single match. Otherwise we pick the first match we find.
105
106
106
107
In the case of our example, the first step is ` Rc<Box<[T; 3]>> ` ,
107
108
which does not itself match any candidate. But when we autoref it, we
108
- get the type ` &Rc<Box<[T; 3]>> ` which does match . We would then
109
+ get the type ` &Rc<Box<[T; 3]>> ` which matches ` &Rc<U> ` . We would then
109
110
recursively consider all where-clauses that appear on the impl: if
110
111
those match (or we cannot rule out that they do), then this is the
111
112
method we would pick. Otherwise, we would continue down the series of
0 commit comments