From 11543f1d7253b9a733e95edc1a2d10f31e739afe Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 18 Jun 2015 16:19:01 +0200 Subject: [PATCH 1/2] Add E0034 error explanation --- src/librustc_typeck/diagnostics.rs | 42 +++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index d89174295a892..ea8f508e52668 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -211,6 +211,47 @@ Reference: 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: + +``` +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::foo() // error, what foo() to call? +} +``` + +To avoid this error, you have to keep only one of them and remove the others. +So let's take our example and fix it: + +``` +struct Test; + +trait Trait1 { + fn foo(); +} + +impl Trait1 for Test { fn foo() {} } + +fn main() { + Test::foo() // and now that's good! +} +``` +"##, + E0040: r##" It is not allowed to manually call destructors in Rust. It is also not necessary to do this since `drop` is called automatically whenever a value goes @@ -1320,7 +1361,6 @@ For more information see the [opt-in builtin traits RFC](https://github.com/rust } register_diagnostics! { - E0034, // multiple applicable methods in scope E0035, // does not take type parameters E0036, // incorrect number of type parameters given for this method E0044, // foreign items may not have type parameters From e96dc9186f689048f1f765a16154ae0d516f69e3 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 18 Jun 2015 19:11:20 +0200 Subject: [PATCH 2/2] Add Universal Function Call Syntax example --- src/librustc_typeck/diagnostics.rs | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index ea8f508e52668..6951ccd7ce39c 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() { + ::foo() +} +``` "##, E0040: r##"