From c158be082f07c2b2ed0a5f1db33627709396ac63 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 29 Jun 2015 16:00:57 +0200 Subject: [PATCH 1/9] Add E0195 error explanation --- src/librustc_typeck/diagnostics.rs | 39 +++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index d4977c5d3941c..1e83c1b6900a4 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -1250,6 +1250,44 @@ information see the [opt-in builtin traits RFC](https://github.com/rust-lang/ rfcs/blob/master/text/0019-opt-in-builtin-traits.md). "##, +E0195: r##" +Your method's lifetime parameters do not match the trait declaration. +Erroneous code example: + +``` +trait Trait { + fn t<'a,'b:'a>(x: &'a str, y: &'b str); +} + +struct Foo; + +impl Trait for Foo { + fn t<'a,'b>(x: &'a str, y: &'b str) { // error: lifetime parameters + // or bounds on method `t` + // do not match the trait + // declaration + } +} +``` + +The 'b lifetime constraints for `t` implementation does not match the +trait declaration. Ensure lifetime declarations match exactly in both trait +declaration and implementation. Example: + +``` +trait Trait { + fn t<'a,'b:'a>(x: &'a str, y: &'b str); +} + +struct Foo; + +impl Trait for Foo { + fn t<'a,'b:'a>(x: &'a str, y: &'b str) { // ok! + } +} +``` +"##, + E0197: r##" Inherent implementations (one that do not implement a trait but provide methods associated with a type) are always safe because they are not @@ -1686,7 +1724,6 @@ register_diagnostics! { E0193, // cannot bound type where clause bounds may only be attached to types // involving type parameters E0194, - E0195, // lifetime parameters or bounds on method do not match the trait declaration E0196, // cannot determine a type for this closure E0203, // type parameter has more than one relaxed default bound, // and only one is supported From 20f22b7f0e29068414933dd6d41c6a5785d3fd75 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 30 Jun 2015 10:35:46 +0200 Subject: [PATCH 2/9] Add E0093 error explanation --- src/librustc_typeck/diagnostics.rs | 37 +++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index 1e83c1b6900a4..57fbd52f71f4e 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -1022,6 +1022,42 @@ type Foo = Box; // ok! ``` "##, +E0093: r##" +You called an unknown intrinsic function. Erroneous code example: + +``` +#![feature(intrinsics)] + +extern "rust-intrinsic" { + fn foo(); +} + +fn main() { + unsafe { + foo(); + } +} +``` + +Please check you didn't make a mistake in the function's name. All intrinsic +functions are defined in librustc_trans/trans/intrinsic.rs and in +libcore/intrinsics.rs. Example: + +``` +#![feature(intrinsics)] + +extern "rust-intrinsic" { + fn atomic_fence(); +} + +fn main() { + unsafe { + atomic_fence(); + } +} +``` +"##, + 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 @@ -1688,7 +1724,6 @@ register_diagnostics! { E0086, E0090, E0092, - E0093, E0094, E0101, E0102, From ed6940fd384b1e42c3e3ad229e022af2e13b79c7 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 30 Jun 2015 10:44:20 +0200 Subject: [PATCH 3/9] Add E0094 error explanation --- src/librustc_typeck/diagnostics.rs | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index 57fbd52f71f4e..4d3d18cb16c02 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -1029,7 +1029,7 @@ You called an unknown intrinsic function. Erroneous code example: #![feature(intrinsics)] extern "rust-intrinsic" { - fn foo(); + fn foo(); // error: unrecognized intrinsic function: `foo` } fn main() { @@ -1047,7 +1047,7 @@ libcore/intrinsics.rs. Example: #![feature(intrinsics)] extern "rust-intrinsic" { - fn atomic_fence(); + fn atomic_fence(); // ok! } fn main() { @@ -1058,6 +1058,31 @@ fn main() { ``` "##, +E0094: r##" +You gave an invalid number of type parameters to an intrinsic function. +Erroneous code example: + +``` +#![feature(intrinsics)] + +extern "rust-intrinsic" { + fn size_of() -> usize; // error: intrinsic has wrong number + // of type parameters +} +``` + +Please check you give the right number of lifetime parameters and/or the +function definition. Example: + +``` +#![feature(intrinsics)] + +extern "rust-intrinsic" { + fn size_of() -> usize; // ok! +} +``` +"##, + 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 @@ -1724,7 +1749,6 @@ register_diagnostics! { E0086, E0090, E0092, - E0094, E0101, E0102, E0103, From 0ba2db5fde29bfac76a69cff819cb8388be90392 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 30 Jun 2015 10:47:49 +0200 Subject: [PATCH 4/9] Add E0211 error explanation --- src/librustc_typeck/diagnostics.rs | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index 4d3d18cb16c02..e81acc497b1b4 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -1528,6 +1528,29 @@ impl Copy for &'static Bar { } // error ``` "##, +E0211: r##" +You used an intrinsic function which doesn't correspond to its +definition. Erroneous code example: + +``` +#![feature(intrinsics)] + +extern "rust-intrinsic" { + fn size_of(); // error: intrinsic has wrong type +} +``` + +Please check the function definition. Example: + +``` +#![feature(intrinsics)] + +extern "rust-intrinsic" { + fn size_of() -> usize; +} +``` +"##, + E0243: r##" This error indicates that not enough type parameters were found in a type or trait. @@ -1790,7 +1813,6 @@ register_diagnostics! { E0208, E0209, // builtin traits can only be implemented on structs or enums E0210, // type parameter is not constrained by any local type - E0211, E0212, // cannot extract an associated type from a higher-ranked trait bound E0213, // associated types are not accepted in this context E0214, // parenthesized parameters may only be used with a trait From 758ea34146f4651cb78e2167de3c335007a8f26d Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 30 Jun 2015 10:58:52 +0200 Subject: [PATCH 5/9] Add E0092 error explanation --- src/librustc_typeck/diagnostics.rs | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index e81acc497b1b4..49f58d0d9e9de 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -1022,6 +1022,32 @@ type Foo = Box; // ok! ``` "##, +E0092: r##" +You tried to call an undefined atomic operation function. +Erroneous code example: + +``` +#![feature(intrinsics)] + +extern "rust-intrinsic" { + fn atomic_foo(); // error: unrecognized atomic operation + // function +} +``` + +Please check you didn't make a mistake in the function's name. All intrinsic +functions are defined in librustc_trans/trans/intrinsic.rs and in +libcore/intrinsics.rs. Example: + +``` +#![feature(intrinsics)] + +extern "rust-intrinsic" { + fn atomic_fence(); // ok! +} +``` +"##, + E0093: r##" You called an unknown intrinsic function. Erroneous code example: @@ -1771,7 +1797,6 @@ register_diagnostics! { E0085, E0086, E0090, - E0092, E0101, E0102, E0103, From edf6132be88fa2a51176f84d5fbee45046880717 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 30 Jun 2015 11:19:16 +0200 Subject: [PATCH 6/9] Add E0101 error explanation --- src/librustc_typeck/diagnostics.rs | 51 ++++++++++++++++++++++-------- 1 file changed, 38 insertions(+), 13 deletions(-) diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index 49f58d0d9e9de..affa0768697da 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -1023,7 +1023,7 @@ type Foo = Box; // ok! "##, E0092: r##" -You tried to call an undefined atomic operation function. +You tried to declare an undefined atomic operation function. Erroneous code example: ``` @@ -1037,7 +1037,7 @@ extern "rust-intrinsic" { Please check you didn't make a mistake in the function's name. All intrinsic functions are defined in librustc_trans/trans/intrinsic.rs and in -libcore/intrinsics.rs. Example: +libcore/intrinsics.rs in the Rust source code. Example: ``` #![feature(intrinsics)] @@ -1049,7 +1049,7 @@ extern "rust-intrinsic" { "##, E0093: r##" -You called an unknown intrinsic function. Erroneous code example: +You declared an unknown intrinsic function. Erroneous code example: ``` #![feature(intrinsics)] @@ -1067,7 +1067,7 @@ fn main() { Please check you didn't make a mistake in the function's name. All intrinsic functions are defined in librustc_trans/trans/intrinsic.rs and in -libcore/intrinsics.rs. Example: +libcore/intrinsics.rs in the Rust source code. Example: ``` #![feature(intrinsics)] @@ -1097,8 +1097,9 @@ extern "rust-intrinsic" { } ``` -Please check you give the right number of lifetime parameters and/or the -function definition. Example: +Please check that you provided the right number of lifetime parameters +and verify with the function declaration in the Rust source code. +Example: ``` #![feature(intrinsics)] @@ -1109,6 +1110,32 @@ extern "rust-intrinsic" { ``` "##, +E0101: r##" +You hit this error because the compiler the compiler lacks information +to determine a type for this expression. Erroneous code example: + +``` +fn main() { + let x = |_| {}; // error: cannot determine a type for this expression +} +``` + +You have two possibilities to solve this situation: + * Give an explicit definition of the expression + * Infer the expression + +Examples: + +``` +fn main() { + let x = |_ : u32| {}; // ok! + // or: + let x = |_| {}; + x(0u32); +} +``` +"##, + 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 @@ -1343,21 +1370,20 @@ Erroneous code example: ``` trait Trait { - fn t<'a,'b:'a>(x: &'a str, y: &'b str); + fn bar<'a,'b:'a>(x: &'a str, y: &'b str); } struct Foo; impl Trait for Foo { - fn t<'a,'b>(x: &'a str, y: &'b str) { // error: lifetime parameters - // or bounds on method `t` - // do not match the trait - // declaration + fn bar<'a,'b>(x: &'a str, y: &'b str) { + // error: lifetime parameters or bounds on method `bar` + // do not match the trait declaration } } ``` -The 'b lifetime constraints for `t` implementation does not match the +The `'b` lifetime constraint for bar() implementation does not match the trait declaration. Ensure lifetime declarations match exactly in both trait declaration and implementation. Example: @@ -1797,7 +1823,6 @@ register_diagnostics! { E0085, E0086, E0090, - E0101, E0102, E0103, E0104, From a481c4ecdc95bf9247f262334f288ff78001ff6c Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 30 Jun 2015 11:57:47 +0200 Subject: [PATCH 7/9] Add E0117 error explanation --- src/librustc_typeck/diagnostics.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index affa0768697da..7cc13a1a07737 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -1244,6 +1244,26 @@ impl Bytes { ... } // error, same as above ``` "##, +E0117: r##" +You tried to implement a trait on a type which isn't defined in your crate. +Erroneous code example: + +``` +impl Drop for u32 {} +``` + +The type on which you want to implement the trait has to be defined in +your crate. Example: + +``` +pub struct Foo; // you define your type in your crate + +impl Drop for Foo { // and you can implement the trait on it! + // code of trait implementation here +} +``` +"##, + E0121: r##" In order to be consistent with Rust's lack of global type inference, type placeholders are disallowed by design in item signatures. @@ -1826,7 +1846,6 @@ register_diagnostics! { E0102, E0103, E0104, - E0117, E0118, E0119, E0120, From 2881e83c96c6f35fdc6741bbb3f951507ef74ca5 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 30 Jun 2015 12:12:45 +0200 Subject: [PATCH 8/9] Add E0207 error explanation --- src/librustc_typeck/diagnostics.rs | 37 +++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index 7cc13a1a07737..83e6ea74d83dc 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -1600,6 +1600,42 @@ impl Copy for &'static Bar { } // error ``` "##, +E0207: r##" +You passed an unused type parameter when implementing a trait +on an object. Erroneous code example: + +``` +trait MyTrait { + fn get(&self) -> usize; +} + +struct Foo; + +impl MyTrait for Foo { + fn get(&self) -> usize { + 0 + } +} +``` + +Please check your object definition and remove unused type +parameter(s). Example: + +``` +trait MyTrait { + fn get(&self) -> usize; +} + +struct Foo; + +impl MyTrait for Foo { + fn get(&self) -> usize { + 0 + } +} +``` +"##, + E0211: r##" You used an intrinsic function which doesn't correspond to its definition. Erroneous code example: @@ -1878,7 +1914,6 @@ register_diagnostics! { E0196, // cannot determine a type for this closure E0203, // type parameter has more than one relaxed default bound, // and only one is supported - E0207, // type parameter is not constrained by the impl trait, self type, or predicate E0208, E0209, // builtin traits can only be implemented on structs or enums E0210, // type parameter is not constrained by any local type From be38926b6941f13b1f03c2e3523b98dd256b3c7b Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 30 Jun 2015 12:35:01 +0200 Subject: [PATCH 9/9] Add E0119 error explanation Add more explanations --- src/librustc_typeck/diagnostics.rs | 85 +++++++++++++++++++++++++++--- 1 file changed, 77 insertions(+), 8 deletions(-) diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index 83e6ea74d83dc..05ddfe89bcf5c 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -1245,15 +1245,16 @@ impl Bytes { ... } // error, same as above "##, E0117: r##" -You tried to implement a trait on a type which isn't defined in your crate. -Erroneous code example: +You got this error because because you tried to implement a foreign +trait for a foreign type (with maybe a foreign type parameter). Erroneous +code example: ``` impl Drop for u32 {} ``` -The type on which you want to implement the trait has to be defined in -your crate. Example: +The type, trait or the type parameter (or all of them) has to be defined +in your crate. Example: ``` pub struct Foo; // you define your type in your crate @@ -1261,6 +1262,75 @@ pub struct Foo; // you define your type in your crate impl Drop for Foo { // and you can implement the trait on it! // code of trait implementation here } + +trait Bar { // or define your trait in your crate + fn get(&self) -> usize; +} + +impl Bar for u32 { // and then you implement it on a foreign type + fn get(&self) -> usize { 0 } +} + +impl From for i32 { // or you use a type from your crate as + // a type parameter + fn from(i: Foo) -> i32 { + 0 + } +} +``` +"##, + +E0119: r##" +There are conflicting trait implementations for the same type. +Erroneous code example: + +``` +trait MyTrait { + fn get(&self) -> usize; +} + +impl MyTrait for T { + fn get(&self) -> usize { 0 } +} + +struct Foo { + value: usize +} + +impl MyTrait for Foo { // error: conflicting implementations for trait + // `MyTrait` + fn get(&self) -> usize { self.value } +} +``` + +When you write: + +``` +impl MyTrait for T { + fn get(&self) -> usize { 0 } +} +``` + +This makes the trait implemented on all types in the scope. So if you +try to implement it on another one after that, the implementations will +conflict. Example: + +``` +trait MyTrait { + fn get(&self) -> usize; +} + +impl MyTrait for T { + fn get(&self) -> usize { 0 } +} + +struct Foo; + +fn main() { + let f = Foo; + + f.get(); // the trait is implemented so we can use it +} ``` "##, @@ -1403,7 +1473,7 @@ impl Trait for Foo { } ``` -The `'b` lifetime constraint for bar() implementation does not match the +The lifetime constraint `'b` for bar() implementation does not match the trait declaration. Ensure lifetime declarations match exactly in both trait declaration and implementation. Example: @@ -1601,8 +1671,8 @@ impl Copy for &'static Bar { } // error "##, E0207: r##" -You passed an unused type parameter when implementing a trait -on an object. Erroneous code example: +You declared an unused type parameter when implementing a trait on an object. +Erroneous code example: ``` trait MyTrait { @@ -1883,7 +1953,6 @@ register_diagnostics! { E0103, E0104, E0118, - E0119, E0120, E0122, E0123,