Add Universal Function Call Syntax example
This commit is contained in:
parent
d4c37088ca
commit
8c5572fc21
@ -212,8 +212,8 @@ http://doc.rust-lang.org/reference.html#trait-objects
|
||||
"##,
|
||||
|
||||
E0034: r##"
|
||||
The compiler doesn't know what method to call because more than one does
|
||||
have the same prototype. Example:
|
||||
The compiler doesn't know what method to call because more than one method
|
||||
has the same prototype. Example:
|
||||
|
||||
```
|
||||
struct Test;
|
||||
@ -230,7 +230,7 @@ impl Trait1 for Test { fn foo() {} }
|
||||
impl Trait2 for Test { fn foo() {} }
|
||||
|
||||
fn main() {
|
||||
Test::foo() // error, what foo() to call?
|
||||
Test::foo() // error, which foo() to call?
|
||||
}
|
||||
```
|
||||
|
||||
@ -250,6 +250,28 @@ fn main() {
|
||||
Test::foo() // and now that's good!
|
||||
}
|
||||
```
|
||||
|
||||
However, a better solution would be using fully explicit naming of type and
|
||||
trait:
|
||||
|
||||
```
|
||||
struct Test;
|
||||
|
||||
trait Trait1 {
|
||||
fn foo();
|
||||
}
|
||||
|
||||
trait Trait2 {
|
||||
fn foo();
|
||||
}
|
||||
|
||||
impl Trait1 for Test { fn foo() {} }
|
||||
impl Trait2 for Test { fn foo() {} }
|
||||
|
||||
fn main() {
|
||||
<Test as Trait1>::foo()
|
||||
}
|
||||
```
|
||||
"##,
|
||||
|
||||
E0035: r##"
|
||||
|
Loading…
Reference in New Issue
Block a user