@@ -15,23 +15,22 @@ let log_pi = pi.unwrap_or(1.0).log(2.72);
15
15
```
16
16
17
17
When resolving method calls on an expression of type ` A ` , Rust will use the
18
- following order, only looking at methods that are
19
- [ visible] ( visibility-and-privacy.html ) . If the type of ` A ` is a type parameter
20
- or ` Self ` in a trait definitition then steps 2-4 first consider traits from
21
- bounds on the type paramter, then the traits that are in scope. For other
22
- types, only the traits that are in scope are considered.
18
+ following order, only looking at methods that are [ visible] . If the type of ` A `
19
+ is a type parameter or ` Self ` in a trait definitition then steps 2-4 first
20
+ consider traits from bounds on the type paramter, then the traits that are in
21
+ scope. For other types, only the traits that are in scope are considered.
23
22
24
23
1 . Inherent methods, with receiver of type ` A ` , ` &A ` , ` &mut A ` .
25
24
1 . Trait methods with receiver of type ` A ` .
26
25
1 . Trait methods with receiver of type ` &A ` .
27
26
1 . Trait methods with receiver of type ` &mut A ` .
28
27
1 . If it's possible, Rust will then repeat steps 1-5 with
29
28
` <A as std::ops::Deref>::Target ` , and insert a dereference operator.
30
- 1 . If ` A ` is now an [ array] ( types.html#array-and-slice-types ) type, then
31
- repeat steps 1-4 with the corresponding slice type.
29
+ 1 . If ` A ` is now an [ array] type, then repeat steps 1-4 with the corresponding
30
+ slice type.
32
31
33
- Note: that in steps 1-4 the receiver is used, not the type of ` Self ` nor the
34
- type of ` A ` . For example
32
+ Note: In steps 1-4, the receiver is used, not the type of ` Self ` nor the
33
+ type of ` A ` . For example:
35
34
36
35
``` rust,ignore
37
36
// `Self` is `&A`, receiver is `&A`.
@@ -48,10 +47,21 @@ Another note: this process does not use the mutability or lifetime of the
48
47
receiver, or whether ` unsafe ` methods can currently be called to resolve
49
48
methods. These constraints instead lead to compiler errors.
50
49
51
- If a step is reached where there is more than one possible method (where
52
- generic methods or traits are considered the same), then it is a compiler
53
- error. These cases require a [ more specific
54
- syntax.] ( expressions/call-expr.html#disambiguating-function-calls ) for method
50
+ If a step is reached where there is more than one possible method, such as where
51
+ generic methods or traits are considered the same, then it is a compiler
52
+ error. These cases require a [ disambiguating function call syntax] for method
55
53
and function invocation.
56
54
57
- [ IDENTIFIER ] : identifiers.html
55
+ > Warning: For [ trait objects] , if there is an inherent method of the same name
56
+ > as a trait method, it will give a compiler error when trying to call the
57
+ > method in a method call expression. Instead, you can call the method using
58
+ > [ disambiguating function call syntax] , in which case it calls the trait
59
+ > method, not the inherent method. There is no way to call the inherent method.
60
+ > Just don't define inherent methods on trait objects with the same name a trait
61
+ > method and you'll be fine.
62
+
63
+ [ IDENTIFIER ] : identifiers.html
64
+ [ visible ] : visibility-and-privacy.html
65
+ [ array ] : types.html#array-and-slice-types
66
+ [ trait objects ] : types.html#trait-objects
67
+ [ disambiguating function call syntax ] : expressions/call-expr.html#disambiguating-function-calls
0 commit comments