From 0770f665d98c28507746d17c46289f1f9f250f31 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 19 Jun 2015 15:49:08 +0200 Subject: [PATCH 1/5] Add E0044 error code explanation --- src/librustc_typeck/diagnostics.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index 16af8c6961e..59ddbc4f210 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -380,6 +380,19 @@ fn main() { ``` "##, +E0044: r##" +You can't use type parameters on foreign items. Example of erroneous code: + +``` +extern { fn some_func(); } +``` + +Just remove the type parameter to make this code works: + +``` +extern { fn some_func(); } +``` + E0045: r##" Rust only supports variadic parameters for interoperability with C code in its FFI. As such, variadic parameters can only be used with functions which are @@ -1488,7 +1501,9 @@ For more information see the [opt-in builtin traits RFC](https://github.com/rust } register_diagnostics! { - E0044, // foreign items may not have type parameters + E0034, // multiple applicable methods in scope + E0035, // does not take type parameters + E0036, // incorrect number of type parameters given for this method E0068, E0071, E0074, From 67c11b0146d875260ffd7d44184221e42c01186c Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 19 Jun 2015 16:47:01 +0200 Subject: [PATCH 2/5] Add E0071 error explanation --- src/librustc_typeck/diagnostics.rs | 33 +++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index 59ddbc4f210..59c21f581ea 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -746,6 +746,38 @@ fn some_func(x: &mut i32) { ``` "##, +E0071: r##" +You tried to use a structure initialization with a non-structure type. +Example of erroneous code: + +``` +enum Foo { f }; + +let u = Foo::f { value: 0i32 }; // error: Foo:f isn't a structure! +// or even more simple: +let u = t { random_field: 0i32 }; //error: t isn't a structure! +``` + +To fix this error, please declare the structure with the given name +first: + +``` +struct Inner { + value: i32 +} + +enum Foo { + f(Inner) +} + +fn main() { + let u = Foo::f(Inner { value: 0i32 }); + // or even more simple: + let t = Inner { value: 0i32 }; +} +``` +"##, + E0072: r##" When defining a recursive struct or enum, any use of the type being defined from inside the definition must occur behind a pointer (like `Box` or `&`). @@ -1505,7 +1537,6 @@ register_diagnostics! { E0035, // does not take type parameters E0036, // incorrect number of type parameters given for this method E0068, - E0071, E0074, E0075, E0076, From e52b94e259b7f416ec584164e6803dcbf038b200 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 23 Jun 2015 19:38:40 +0200 Subject: [PATCH 3/5] Replace example and message by @Manisheart proposition --- src/librustc_typeck/diagnostics.rs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index 59c21f581ea..d660f92db5e 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -384,13 +384,15 @@ E0044: r##" You can't use type parameters on foreign items. Example of erroneous code: ``` -extern { fn some_func(); } +extern { fn some_func(x: T); } ``` -Just remove the type parameter to make this code works: +To fix this, replace the type parameter with the specializations that you +need: ``` -extern { fn some_func(); } +extern { fn some_func_i32(x: i32); } +extern { fn some_func_i64(x: i64); } ``` E0045: r##" @@ -754,7 +756,7 @@ Example of erroneous code: enum Foo { f }; let u = Foo::f { value: 0i32 }; // error: Foo:f isn't a structure! -// or even more simple: +// or even simpler: let u = t { random_field: 0i32 }; //error: t isn't a structure! ``` @@ -772,7 +774,7 @@ enum Foo { fn main() { let u = Foo::f(Inner { value: 0i32 }); - // or even more simple: + // or even simpler: let t = Inner { value: 0i32 }; } ``` @@ -1533,9 +1535,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 E0068, E0074, E0075, From 4c2587c1c0865dfa04ce7bebb680c2ceec615f5c Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 23 Jun 2015 21:16:24 +0200 Subject: [PATCH 4/5] Add potential cause of the error --- src/librustc_typeck/diagnostics.rs | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index d660f92db5e..18341af7ea4 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -753,15 +753,21 @@ You tried to use a structure initialization with a non-structure type. Example of erroneous code: ``` -enum Foo { f }; +enum Foo { FirstValue }; -let u = Foo::f { value: 0i32 }; // error: Foo:f isn't a structure! -// or even simpler: -let u = t { random_field: 0i32 }; //error: t isn't a structure! +let u = Foo::FirstValue { value: 0i32 }; // error: Foo::FirstValue + // isn't a structure! +// or even simpler, if the structure wasn't defined at all: +let u = RandomName { random_field: 0i32 }; // error: RandomName + // isn't a structure! ``` -To fix this error, please declare the structure with the given name -first: +To fix this, please check: + * Did you spell it right? + * Did you accidentaly used an enum as a struct? + * Did you accidentaly make an enum when you intended to use a struct? + +Here is the previous code with all missing information: ``` struct Inner { @@ -769,12 +775,12 @@ struct Inner { } enum Foo { - f(Inner) + FirstValue(Inner) } fn main() { - let u = Foo::f(Inner { value: 0i32 }); - // or even simpler: + let u = Foo::FirstValue(Inner { value: 0i32 }); + let t = Inner { value: 0i32 }; } ``` From 3c987812569fbf4f590162d8324f026d53783bd1 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 24 Jun 2015 09:38:42 +0200 Subject: [PATCH 5/5] Add missing end of string --- src/librustc_typeck/diagnostics.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index 18341af7ea4..2c1b825f13a 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -394,6 +394,7 @@ need: extern { fn some_func_i32(x: i32); } extern { fn some_func_i64(x: i64); } ``` +"##, E0045: r##" Rust only supports variadic parameters for interoperability with C code in its