@@ -15,23 +15,22 @@ let log_pi = pi.unwrap_or(1.0).log(2.72);
1515```
1616
1717When 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.
2322
24231 . Inherent methods, with receiver of type ` A ` , ` &A ` , ` &mut A ` .
25241 . Trait methods with receiver of type ` A ` .
26251 . Trait methods with receiver of type ` &A ` .
27261 . Trait methods with receiver of type ` &mut A ` .
28271 . If it's possible, Rust will then repeat steps 1-5 with
2928 ` <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.
3231
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:
3534
3635``` rust,ignore
3736// `Self` is `&A`, receiver is `&A`.
@@ -48,10 +47,21 @@ Another note: this process does not use the mutability or lifetime of the
4847receiver, or whether ` unsafe ` methods can currently be called to resolve
4948methods. These constraints instead lead to compiler errors.
5049
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
5553and function invocation.
5654
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