From 98205afe0b09b22e9d88968ed61095b15fcfb1e3 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 19 Jun 2015 13:54:57 +0200 Subject: [PATCH 1/9] Add E0036 error explanation --- src/librustc_typeck/diagnostics.rs | 47 ++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index d89174295a892..5b981ed141d10 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -211,6 +211,53 @@ Reference: http://doc.rust-lang.org/reference.html#trait-objects "##, +E0036: r##" +This error occurred when you pass too many or not enough type parameters to a +method. Example: + +``` +struct Test; + +impl Test { + fn method(&self, v: &[T]) -> usize { + v.len() + } +} + +fn main() { + let x = Test; + let v = &[0i32]; + + x.method::(v); // error: only one type parameter is expected! +} +``` + +To fix it, just specify a correct number of type parameters: + +``` +struct Test; + +impl Test { + fn method(&self, v: &[T]) -> usize { + v.len() + } +} + +fn main() { + let x = Test; + let v = &[0i32]; + + x.method::(v); // OK, we're good! +} +``` + +Please note on the last example that we could have called `method` like this: + +``` +x.method(v); +``` +"##, + 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 From 00e115d090180c9fe13856500576978ff3007cda Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 19 Jun 2015 13:56:53 +0200 Subject: [PATCH 2/9] Good time concordance --- src/librustc_typeck/diagnostics.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index 5b981ed141d10..a9fe1a1f82b9f 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 "##, E0036: r##" -This error occurred when you pass too many or not enough type parameters to a -method. Example: +This error occurrs when you pass too many or not enough type parameters to +a method. Example: ``` struct Test; From 04888e7c600fed71d989937cc8f582bea83423a2 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 19 Jun 2015 13:58:15 +0200 Subject: [PATCH 3/9] Add E0035 error explanation --- src/librustc_typeck/diagnostics.rs | 34 ++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index a9fe1a1f82b9f..c95dbd3ca13b9 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -211,6 +211,40 @@ Reference: http://doc.rust-lang.org/reference.html#trait-objects "##, +E0035: r##" +You tried to give a type parameter where it wasn't needed. Bad example: + +``` +struct Test; + +impl Test { + fn method(&self) {} +} + +fn main() { + let x = Test; + + x.method::(); // Error: Test::method doesn't need type parameter! +} +``` + +To fix this error, just remove the type parameter: + +``` +struct Test; + +impl Test { + fn method(&self) {} +} + +fn main() { + let x = Test; + + x.method(); // OK, we're good! +} +``` +"##, + E0036: r##" This error occurrs when you pass too many or not enough type parameters to a method. Example: From b4481e68deeffc9e6cf4648d10c51750adbb4c3b Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 19 Jun 2015 13:58:52 +0200 Subject: [PATCH 4/9] Remove unneeded indentation --- src/librustc_typeck/diagnostics.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index c95dbd3ca13b9..f338a774e90e5 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -223,7 +223,7 @@ impl Test { fn main() { let x = Test; - + x.method::(); // Error: Test::method doesn't need type parameter! } ``` @@ -239,7 +239,7 @@ impl Test { fn main() { let x = Test; - + x.method(); // OK, we're good! } ``` From d4c37088ca873a23e58d512d9418f59056477226 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 19 Jun 2015 13:59:51 +0200 Subject: [PATCH 5/9] Add E0034 error explanation --- src/librustc_typeck/diagnostics.rs | 41 ++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index f338a774e90e5..431880c2076bb 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! +} +``` +"##, + E0035: r##" You tried to give a type parameter where it wasn't needed. Bad example: From 8c5572fc2114fa2e8156c89cda89c799c9c3e9e0 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 19 Jun 2015 14:01:55 +0200 Subject: [PATCH 6/9] 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 431880c2076bb..bcc415e4e1a6f 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() +} +``` "##, E0035: r##" From 6471dccd3b3a5b83b4fccecffc94047e1086ca2f Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 19 Jun 2015 14:03:07 +0200 Subject: [PATCH 7/9] Add E0016 explanation --- src/librustc/diagnostics.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/librustc/diagnostics.rs b/src/librustc/diagnostics.rs index 0857fb3258eec..124117ca80bcd 100644 --- a/src/librustc/diagnostics.rs +++ b/src/librustc/diagnostics.rs @@ -256,6 +256,21 @@ See [RFC 911] for more details on the design of `const fn`s. [RFC 911]: https://github.com/rust-lang/rfcs/blob/master/text/0911-const-fn.md "##, +E0016: r##" +Blocks in constants may only contain items (such as constant, function +definition, etc...) and a tail expression. Example: + +``` +const FOO: i32 = { let x = 0; x }; // 'x' isn't an item! +``` + +To avoid it, you have to replace the non-item object: + +``` +const FOO: i32 = { const X : i32 = 0; X }; +``` +"##, + E0018: r##" The value of static and const variables must be known at compile time. You can't cast a pointer as an integer because we can't know what value the From 2015eb881e8d9e82c1a889595c5b7b33440b2ae7 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 19 Jun 2015 14:05:11 +0200 Subject: [PATCH 8/9] Replace "Bad example" by a better sentence --- src/librustc/diagnostics.rs | 38 +++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/src/librustc/diagnostics.rs b/src/librustc/diagnostics.rs index 124117ca80bcd..0f83cdff5372c 100644 --- a/src/librustc/diagnostics.rs +++ b/src/librustc/diagnostics.rs @@ -294,6 +294,42 @@ println!("{}", Y); ``` "##, +E0019: r##" +A function call isn't allowed in the const's initialization expression +because the expression's value must be known at compile-time. Example of +erroneous code: + +``` +enum Test { + V1 +} + +impl Test { + fn test(&self) -> i32 { + 12 + } +} + +fn main() { + const FOO: Test = Test::V1; + + const A: i32 = FOO.test(); // You can't call Test::func() here ! +} +``` + +Remember: you can't use a function call inside a const's initialization +expression! However, you can totally use it elsewhere you want: + +``` +fn main() { + const FOO: Test = Test::V1; + + FOO.func(); // here is good + let x = FOO.func(); // or even here! +} +``` +"##, + E0020: r##" This error indicates that an attempt was made to divide by zero (or take the remainder of a zero divisor) in a static or constant expression. @@ -965,9 +1001,7 @@ static mut BAR: Option> = None; register_diagnostics! { - E0016, E0017, - E0019, E0022, E0038, E0109, From 9679faa97afbdb9738df16b81175b7090915897f Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 19 Jun 2015 14:06:33 +0200 Subject: [PATCH 9/9] Remove error codes from macro --- src/librustc_typeck/diagnostics.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index bcc415e4e1a6f..fa29f8f1dcea9 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -1464,9 +1464,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 E0045, // variadic function must have C calling convention E0068,