You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A _method call_ consists of an expression (the *receiver*) followed by a single dot, an expression path segment, and a parenthesized expression-list.
12
+
13
+
r[expr.method.target]
8
14
Method calls are resolved to associated [methods] on specific traits, either statically dispatching to a method if the exact `self`-type of the left-hand-side is known, or dynamically dispatching if the left-hand-side expression is an indirect [trait object](../types/trait-object.md).
9
15
10
16
```rust
@@ -13,16 +19,21 @@ let log_pi = pi.unwrap_or(1.0).log(2.72);
13
19
# assert!(1.14<log_pi&&log_pi<1.15)
14
20
```
15
21
22
+
r[expr.method.autoref-deref]
16
23
When looking up a method call, the receiver may be automatically dereferenced or borrowed in order to call a method.
17
24
This requires a more complex lookup process than for other functions, since there may be a number of possible methods to call.
18
25
The following procedure is used:
19
26
27
+
r[expr.method.candidate-recievers]
20
28
The first step is to build a list of candidate receiver types.
21
29
Obtain these by repeatedly [dereferencing][dereference] the receiver expression's type, adding each type encountered to the list, then finally attempting an [unsized coercion] at the end, and adding the result type if that is successful.
30
+
31
+
r[expr.method.candidate-recievers-refs]
22
32
Then, for each candidate `T`, add `&T` and `&mut T` to the list immediately after `T`.
23
33
24
34
For instance, if the receiver has type `Box<[i32;2]>`, then the candidate types will be `Box<[i32;2]>`, `&Box<[i32;2]>`, `&mut Box<[i32;2]>`, `[i32; 2]` (by dereferencing), `&[i32; 2]`, `&mut [i32; 2]`, `[i32]` (by unsized coercion), `&[i32]`, and finally `&mut [i32]`.
25
35
36
+
r[expr.method.candidate-search]
26
37
Then, for each candidate type `T`, search for a [visible] method with a receiver of that type in the following places:
27
38
28
39
1.`T`'s inherent methods (methods implemented directly on `T`).
@@ -58,11 +69,14 @@ Then, for each candidate type `T`, search for a [visible] method with a receiver
0 commit comments