]> git.lizzy.rs Git - rust.git/commitdiff
Add Universal Function Call Syntax example
authorGuillaume Gomez <guillaume1.gomez@gmail.com>
Fri, 19 Jun 2015 12:01:55 +0000 (14:01 +0200)
committerGuillaume Gomez <guillaume1.gomez@gmail.com>
Fri, 19 Jun 2015 12:01:55 +0000 (14:01 +0200)
src/librustc_typeck/diagnostics.rs

index 431880c2076bb693144a71bab9cb6e3074a32603..bcc415e4e1a6f58dbd731a4c75be511452cdf9fb 100644 (file)
@@ -212,8 +212,8 @@ struct Dog {
 "##,
 
 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##"