From 5429c9be78a0d55424a65244b956ea50e79c1f1e Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 29 Jul 2015 14:45:24 +0200 Subject: [PATCH 01/13] Add E0423 error explanation --- src/librustc_resolve/diagnostics.rs | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/librustc_resolve/diagnostics.rs b/src/librustc_resolve/diagnostics.rs index 5ddc2547fd9c..cd0da6a35d8c 100644 --- a/src/librustc_resolve/diagnostics.rs +++ b/src/librustc_resolve/diagnostics.rs @@ -425,6 +425,29 @@ match 0 { ``` "##, +E0424: r##" +A `struct` variant name was used like a function name. Example of +erroneous code: + +``` +struct Foo { a: bool}; + +println!("I am {}", Foo); +// error: `Foo` is a struct variant name, but this expression uses +// it like a function name +``` + +Please verify you didn't misspell the name of what you actually wanted +to use here. Example: + +``` +struct Foo { a: bool}; + +let foo = Foo { a: true }; +println!("I am {}", foo); // ok! +``` +"##, + E0424: r##" The `self` keyword was used in a static method. Example of erroneous code: @@ -660,8 +683,6 @@ register_diagnostics! { E0420, // is not an associated const E0421, // unresolved associated const E0422, // does not name a structure - E0423, // is a struct variant name, but this expression uses it like a - // function name E0427, // cannot use `ref` binding mode with ... E0429, // `self` imports are only allowed within a { } list E0434, // can't capture dynamic environment in a fn item From 086a5c74febf31650dff3ffbd7c2806056f02933 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 29 Jul 2015 14:53:25 +0200 Subject: [PATCH 02/13] Add E0413 error explanation --- src/librustc_resolve/diagnostics.rs | 37 ++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/src/librustc_resolve/diagnostics.rs b/src/librustc_resolve/diagnostics.rs index cd0da6a35d8c..e6daee98821b 100644 --- a/src/librustc_resolve/diagnostics.rs +++ b/src/librustc_resolve/diagnostics.rs @@ -397,6 +397,39 @@ impl Bar { ``` "##, +E0413: r##" +A declaration shadows an enum variant or unit-like struct in scope. +Example of erroneous code: + +``` +struct Foo; + +let Foo = 12i32; // error: declaration of `Foo` shadows an enum variant or + // unit-like struct in scope +``` + + +To fix this error, you have to change the name of the declaration of the +shadowed object. Please also verify that neither name was misspelled. +Example: + +``` +struct Foo; + +let foo = 12i32; // ok! +``` + +Or: + +``` +struct FooStruct; + +let Foo = 12i32; // ok! +``` + +The goal here is to avoid a conflict of names. +"##, + E0417: r##" A static variable was referenced in a pattern. Example of erroneous code: @@ -425,7 +458,7 @@ match 0 { ``` "##, -E0424: r##" +E0423: r##" A `struct` variant name was used like a function name. Example of erroneous code: @@ -673,8 +706,6 @@ register_diagnostics! { E0410, // variable from pattern is not bound in pattern 1 E0411, // use of `Self` outside of an impl or trait E0412, // use of undeclared - E0413, // declaration of shadows an enum variant or unit-like struct in - // scope E0414, // only irrefutable patterns allowed here E0415, // identifier is bound more than once in this parameter list E0416, // identifier is bound more than once in the same pattern From cd0af4515b6a3e523034c499a820b5f3bf3318cd Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 31 Jul 2015 14:40:27 +0200 Subject: [PATCH 03/13] Add E0435 error explanation --- src/librustc_resolve/diagnostics.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/librustc_resolve/diagnostics.rs b/src/librustc_resolve/diagnostics.rs index e6daee98821b..cb14b843522e 100644 --- a/src/librustc_resolve/diagnostics.rs +++ b/src/librustc_resolve/diagnostics.rs @@ -638,6 +638,26 @@ use something_which_doesnt_exist; Please verify you didn't misspell the import's name. "##, +E0435: r##" +A non-constant value was used in a const. Example of erroneous code: + +``` +let foo = 42u32; +const FOO : u32 = foo; // error: attempt to use a non-constant value in a + // constant +``` + +To fix this error, please replace the value by a constant one. Example: + +``` +const FOO : u32 = 42u32; // ok! + +// or: +const OTHER_FOO : u32 = 42u32; +const FOO : u32 = OTHER_FOO; // ok! +``` +"##, + E0437: r##" Trait impls can only implement associated types that are members of the trait in question. This error indicates that you attempted to implement an associated @@ -717,5 +737,4 @@ register_diagnostics! { E0427, // cannot use `ref` binding mode with ... E0429, // `self` imports are only allowed within a { } list E0434, // can't capture dynamic environment in a fn item - E0435, // attempt to use a non-constant value in a constant } From 050b8d370bc400bb0863de3800f1f20138d41837 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 4 Aug 2015 12:02:30 +0200 Subject: [PATCH 04/13] Add E0412 error explanation --- src/librustc_resolve/diagnostics.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/librustc_resolve/diagnostics.rs b/src/librustc_resolve/diagnostics.rs index cb14b843522e..b567d19f0a3d 100644 --- a/src/librustc_resolve/diagnostics.rs +++ b/src/librustc_resolve/diagnostics.rs @@ -397,6 +397,23 @@ impl Bar { ``` "##, +E0412: r##" +An undeclared type name was used. Example of erroneous code: + +``` +impl Something {} // error: use of undeclared type name `Something` +``` + +To fix this error, please verify you didn't misspell the type name or +you did declare it. Example: + +``` +struct Something; + +impl Something {} +``` +"##, + E0413: r##" A declaration shadows an enum variant or unit-like struct in scope. Example of erroneous code: @@ -725,7 +742,6 @@ register_diagnostics! { // pattern #1 E0410, // variable from pattern is not bound in pattern 1 E0411, // use of `Self` outside of an impl or trait - E0412, // use of undeclared E0414, // only irrefutable patterns allowed here E0415, // identifier is bound more than once in this parameter list E0416, // identifier is bound more than once in the same pattern From 028aba38ff073cc951991d46e458f099dcb05ef4 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 4 Aug 2015 15:15:45 +0200 Subject: [PATCH 05/13] Add E0102 error explanation --- src/librustc_typeck/diagnostics.rs | 31 +++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index bbeb907fd18b..29efa0819d64 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -1118,6 +1118,36 @@ fn main() { ``` "##, +E0102: r##" +You hit this error because the compiler the compiler lacks information +to determine a type for this variable. Erroneous code example: + +``` +fn main() { + let x: &_; // error: cannot determine a type for this local variable +} +``` + +You have two possibilities to solve this situation: + * Give an explicit definition of the variable + * Infer the variable + +Examples: + +``` +fn some_func(x: u32) { + // some code +} + +fn main() { + let x = 0u32; // ok! + // or: + let x = 0; + some_func(x); +} +``` +"##, + E0106: r##" This error indicates that a lifetime is missing from a type. If it is an error inside a function signature, the problem may be with failing to adhere to the @@ -2303,7 +2333,6 @@ register_diagnostics! { E0085, E0086, E0090, - E0102, E0103, E0104, E0118, From 6ae31b6f893a16999c5c85f6426dbda0d6648283 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 6 Aug 2015 11:57:53 +0200 Subject: [PATCH 06/13] Add examples in E0412 --- src/librustc_resolve/diagnostics.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/librustc_resolve/diagnostics.rs b/src/librustc_resolve/diagnostics.rs index b567d19f0a3d..c13e372eceef 100644 --- a/src/librustc_resolve/diagnostics.rs +++ b/src/librustc_resolve/diagnostics.rs @@ -398,19 +398,29 @@ impl Bar { "##, E0412: r##" -An undeclared type name was used. Example of erroneous code: +An undeclared type name was used. Example of erroneous codes: ``` impl Something {} // error: use of undeclared type name `Something` +// or: +trait Foo { + fn bar(N); // error: use of undeclared type name `N` +} ``` To fix this error, please verify you didn't misspell the type name or -you did declare it. Example: +you did declare it. Examples: ``` struct Something; impl Something {} +// or: +trait Foo { + type N; + + fn bar(Self::N); +} ``` "##, From 59574759a817e55722a2c998853bd9d4eec65552 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 6 Aug 2015 12:07:55 +0200 Subject: [PATCH 07/13] Add E0419 error explanation --- src/librustc_resolve/diagnostics.rs | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/librustc_resolve/diagnostics.rs b/src/librustc_resolve/diagnostics.rs index c13e372eceef..f656c289f846 100644 --- a/src/librustc_resolve/diagnostics.rs +++ b/src/librustc_resolve/diagnostics.rs @@ -485,6 +485,33 @@ match 0 { ``` "##, +E0419: r##" +An unknown enum variant, struct or const was used. Example of +erroneous code: + +``` +match 0 { + Something::Foo => {} // error: unresolved enum variant, struct + // or const `Foo` +} +``` + +Please verify you didn't misspell it or the enum variant, struct +or const was well declared and/or imported. Example: + +``` +enum Something { + Foo, + NotFoo, +} + +match Something::NotFoo { + Something::Foo => {} // ok! + _ => {} +} +``` +"##, + E0423: r##" A `struct` variant name was used like a function name. Example of erroneous code: @@ -756,7 +783,6 @@ register_diagnostics! { E0415, // identifier is bound more than once in this parameter list E0416, // identifier is bound more than once in the same pattern E0418, // is not an enum variant, struct or const - E0419, // unresolved enum variant, struct or const E0420, // is not an associated const E0421, // unresolved associated const E0422, // does not name a structure From 4840c13f1ae38a6d6b2c3068a7a066ea4af30b11 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 6 Aug 2015 15:21:25 +0200 Subject: [PATCH 08/13] Add E0415 error explanation --- src/librustc_resolve/diagnostics.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/librustc_resolve/diagnostics.rs b/src/librustc_resolve/diagnostics.rs index f656c289f846..5551837cdce3 100644 --- a/src/librustc_resolve/diagnostics.rs +++ b/src/librustc_resolve/diagnostics.rs @@ -457,6 +457,22 @@ let Foo = 12i32; // ok! The goal here is to avoid a conflict of names. "##, +E0415: r##" +More than one parameter have the same name. Example of erroneous +code: + +``` +fn foo(f: i32, f: i32) {} // error: identifier `f` is bound more than + // once in this parameter list +``` + +Please verify you didn't misspell parameters' name. Example: + +``` +fn foo(f: i32, g: i32) {} // ok! +``` +"##, + E0417: r##" A static variable was referenced in a pattern. Example of erroneous code: @@ -780,7 +796,6 @@ register_diagnostics! { E0410, // variable from pattern is not bound in pattern 1 E0411, // use of `Self` outside of an impl or trait E0414, // only irrefutable patterns allowed here - E0415, // identifier is bound more than once in this parameter list E0416, // identifier is bound more than once in the same pattern E0418, // is not an enum variant, struct or const E0420, // is not an associated const From 378aba4743f8f26747829fd5da1ab1037ead11d9 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 6 Aug 2015 15:30:33 +0200 Subject: [PATCH 09/13] Add E0416 error explanation --- src/librustc_resolve/diagnostics.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/librustc_resolve/diagnostics.rs b/src/librustc_resolve/diagnostics.rs index 5551837cdce3..d2914b5913ac 100644 --- a/src/librustc_resolve/diagnostics.rs +++ b/src/librustc_resolve/diagnostics.rs @@ -473,6 +473,26 @@ fn foo(f: i32, g: i32) {} // ok! ``` "##, +E0416: r##" +An identifier is bound more than once in a pattern. Example of erroneous +code: + +``` +match (1, 2) { + (x, x) => {} // error: identifier `x` is bound more than once in the + // same pattern +} +``` + +Please verify you didn't misspell identifiers' name. Example: + +``` +match (1, 2) { + (x, y) => {} // ok! +} +``` +"##, + E0417: r##" A static variable was referenced in a pattern. Example of erroneous code: @@ -796,7 +816,6 @@ register_diagnostics! { E0410, // variable from pattern is not bound in pattern 1 E0411, // use of `Self` outside of an impl or trait E0414, // only irrefutable patterns allowed here - E0416, // identifier is bound more than once in the same pattern E0418, // is not an enum variant, struct or const E0420, // is not an associated const E0421, // unresolved associated const From 99796a6c9c98f17c93384228396a8a808b46a1a0 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 6 Aug 2015 15:42:22 +0200 Subject: [PATCH 10/13] Update E0423 example --- src/librustc_resolve/diagnostics.rs | 26 +++++++++++++------------- src/librustc_typeck/diagnostics.rs | 4 ++-- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/librustc_resolve/diagnostics.rs b/src/librustc_resolve/diagnostics.rs index d2914b5913ac..b814af979dec 100644 --- a/src/librustc_resolve/diagnostics.rs +++ b/src/librustc_resolve/diagnostics.rs @@ -408,8 +408,8 @@ trait Foo { } ``` -To fix this error, please verify you didn't misspell the type name or -you did declare it. Examples: +To fix this error, please verify you didn't misspell the type name, +you did declare it or imported it into the scope. Examples: ``` struct Something; @@ -436,8 +436,8 @@ let Foo = 12i32; // error: declaration of `Foo` shadows an enum variant or ``` -To fix this error, you have to change the name of the declaration of the -shadowed object. Please also verify that neither name was misspelled. +To fix this error, make sure declarations do not shadow any enum variants or +structures in the scope. Please also verify that neither name was misspelled. Example: ``` @@ -458,7 +458,7 @@ The goal here is to avoid a conflict of names. "##, E0415: r##" -More than one parameter have the same name. Example of erroneous +More than one function parameter have the same name. Example of erroneous code: ``` @@ -532,8 +532,8 @@ match 0 { } ``` -Please verify you didn't misspell it or the enum variant, struct -or const was well declared and/or imported. Example: +Please verify you didn't misspell it and the enum variant, struct or const has +been declared and imported into scope. Example: ``` enum Something { @@ -555,7 +555,7 @@ erroneous code: ``` struct Foo { a: bool}; -println!("I am {}", Foo); +let f = Foo(); // error: `Foo` is a struct variant name, but this expression uses // it like a function name ``` @@ -564,10 +564,9 @@ Please verify you didn't misspell the name of what you actually wanted to use here. Example: ``` -struct Foo { a: bool}; +fn Foo() -> u32 { 0 } -let foo = Foo { a: true }; -println!("I am {}", foo); // ok! +let f = Foo(); // ok! ``` "##, @@ -729,7 +728,8 @@ Please verify you didn't misspell the import's name. "##, E0435: r##" -A non-constant value was used in a const. Example of erroneous code: +A non-constant value was used to initialise a constant. Example of erroneous +code: ``` let foo = 42u32; @@ -737,7 +737,7 @@ const FOO : u32 = foo; // error: attempt to use a non-constant value in a // constant ``` -To fix this error, please replace the value by a constant one. Example: +To fix this error, please replace the value with a constant. Example: ``` const FOO : u32 = 42u32; // ok! diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index 29efa0819d64..bc942e1cc771 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -1119,8 +1119,8 @@ fn main() { "##, E0102: r##" -You hit this error because the compiler the compiler lacks information -to determine a type for this variable. Erroneous code example: +You hit this error because the compiler lacks information to +determine a type for this variable. Erroneous code example: ``` fn main() { From 2a08cff97c94160ddd06cdec380bbde8bd4f1d1b Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 6 Aug 2015 20:47:10 +0200 Subject: [PATCH 11/13] Add another example for E0412 --- src/librustc_resolve/diagnostics.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/librustc_resolve/diagnostics.rs b/src/librustc_resolve/diagnostics.rs index b814af979dec..5fe1e2869173 100644 --- a/src/librustc_resolve/diagnostics.rs +++ b/src/librustc_resolve/diagnostics.rs @@ -406,6 +406,8 @@ impl Something {} // error: use of undeclared type name `Something` trait Foo { fn bar(N); // error: use of undeclared type name `N` } +// or: +fn foo(x: T) {} // error: use of undeclared type name `T` ``` To fix this error, please verify you didn't misspell the type name, @@ -414,13 +416,15 @@ you did declare it or imported it into the scope. Examples: ``` struct Something; -impl Something {} +impl Something {} // ok! // or: trait Foo { type N; - fn bar(Self::N); + fn bar(Self::N); // ok! } +//or: +fn foo(x: T) {} // ok! ``` "##, @@ -436,9 +440,8 @@ let Foo = 12i32; // error: declaration of `Foo` shadows an enum variant or ``` -To fix this error, make sure declarations do not shadow any enum variants or -structures in the scope. Please also verify that neither name was misspelled. -Example: +To fix this error, rename the variable such that it doesn't shadow any enum +variable or structure in scope. Example: ``` struct Foo; From 5aa6c155a3a5de2aa5a358e3d4f8ca212dece98f Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 7 Aug 2015 15:07:20 +0200 Subject: [PATCH 12/13] Improve examples of E0102 --- src/librustc_typeck/diagnostics.rs | 32 ++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index bc942e1cc771..0e0d31beaa1a 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -1123,27 +1123,39 @@ You hit this error because the compiler lacks information to determine a type for this variable. Erroneous code example: ``` +fn demo(devil: fn () -> !) { + let x: &_ = devil(); + // error: cannot determine a type for this local variable +} + +fn oh_no() -> ! { panic!("the devil is in the details") } + fn main() { - let x: &_; // error: cannot determine a type for this local variable + demo(oh_no); } ``` -You have two possibilities to solve this situation: - * Give an explicit definition of the variable - * Infer the variable - +To solve this situation, constrain the type of the variable. Examples: ``` -fn some_func(x: u32) { +fn some_func(x: &u32) { // some code } -fn main() { - let x = 0u32; // ok! - // or: - let x = 0; +fn demo(devil: fn () -> !) { + let x: &u32 = devil(); + // Here we defined the type at the variable creation + + let x: &_ = devil(); some_func(x); + // Here, the type is determined by the function argument type +} + +fn oh_no() -> ! { panic!("the devil is in the details") } + +fn main() { + demo(oh_no); } ``` "##, From c3d147eea60c891823e7e1c21003c392654a633b Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 7 Aug 2015 15:23:00 +0200 Subject: [PATCH 13/13] Add a guard example for E0416 --- src/librustc_resolve/diagnostics.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/librustc_resolve/diagnostics.rs b/src/librustc_resolve/diagnostics.rs index 5fe1e2869173..b758260ac2b9 100644 --- a/src/librustc_resolve/diagnostics.rs +++ b/src/librustc_resolve/diagnostics.rs @@ -494,6 +494,15 @@ match (1, 2) { (x, y) => {} // ok! } ``` + +Or maybe did you mean to unify? Consider using a guard: + +``` +match (A, B, C) { + (x, x2, see) if x == x2 => { /* A and B are equal, do one thing */ } + (y, z, see) => { /* A and B unequal; do another thing */ } +} +``` "##, E0417: r##"