diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2015-06-19 14:01:55 +0200 |
|---|---|---|
| committer | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2015-06-19 14:01:55 +0200 |
| commit | 8c5572fc2114fa2e8156c89cda89c799c9c3e9e0 (patch) | |
| tree | 175904f0cf48a602e530d06ec764b02fc82e2ba5 | |
| parent | d4c37088ca873a23e58d512d9418f59056477226 (diff) | |
| download | rust-8c5572fc2114fa2e8156c89cda89c799c9c3e9e0.tar.gz rust-8c5572fc2114fa2e8156c89cda89c799c9c3e9e0.zip | |
Add Universal Function Call Syntax example
| -rw-r--r-- | src/librustc_typeck/diagnostics.rs | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index 431880c2076..bcc415e4e1a 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -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##" |
