From d50fa7eff56e6d2b4daae4cf835dc8133b235c35 Mon Sep 17 00:00:00 2001 From: Nick Hamann Date: Tue, 19 May 2015 00:32:27 -0500 Subject: [PATCH 1/4] Add error explanation for E0326. --- src/librustc_typeck/diagnostics.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index bb60de955f0..6bac0299441 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -684,6 +684,25 @@ for types as needed by the compiler, and it is currently disallowed to explicitly implement it for a type. "##, +E0326: r##" +The types of any associated constants in a trait implementation must match the +types in the trait definition. This error indicates that there was a mismatch. + +Here's an example of this error: + +``` +trait Foo { + const BAR: bool; +} + +struct Bar; + +impl Foo for Bar { + const BAR: u32 = 5; // error, expected bool, found u32 +} +``` +"##, + E0368: r##" This error indicates that a binary assignment operator like `+=` or `^=` was applied to the wrong types. @@ -885,7 +904,6 @@ register_diagnostics! { E0323, // implemented an associated const when another trait item expected E0324, // implemented a method when another trait item expected E0325, // implemented an associated type when another trait item expected - E0326, // associated const implemented with different type from trait E0327, // referred to method instead of constant in match pattern E0328, // cannot implement Unsize explicitly E0366, // dropck forbid specialization to concrete type or region From 35d979d8f8bb63b6063e30954c7c71ddf863b380 Mon Sep 17 00:00:00 2001 From: Nick Hamann Date: Tue, 19 May 2015 00:33:39 -0500 Subject: [PATCH 2/4] Fix the error explanation for E0053. --- src/librustc_typeck/diagnostics.rs | 35 ++++++++++-------------------- 1 file changed, 11 insertions(+), 24 deletions(-) diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index 6bac0299441..00cdc6eb99f 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -65,40 +65,27 @@ impl Foo for Bar { "##, E0053: r##" -For any given method of a trait, the mutabilities of the parameters must match -between the trait definition and the implementation. +The parameters of any trait method must match between a trait implementation +and the trait definition. -Here's an example where the mutability of the `self` parameter is wrong: +Here are a couple examples of this error: ``` -trait Foo { fn foo(&self); } +trait Foo { + fn foo(x: u16); + fn bar(&self); +} struct Bar; impl Foo for Bar { - // error, the signature should be `fn foo(&self)` instead + // error, expected u16, found i16 + fn foo(x: i16) { } + + // error, values differ in mutability fn foo(&mut self) { } } - -fn main() {} ``` - -Here's another example, this time for a non-`self` parameter: - -``` -trait Foo { fn foo(x: &mut bool) -> bool; } - -struct Bar; - -impl Foo for Bar { - // error, the type of `x` should be `&mut bool` instead - fn foo(x: &bool) -> bool { *x } -} - -fn main() {} -``` - - "##, E0054: r##" From 50b802ade0d9aecf3a781c98c8f051b3714db3ea Mon Sep 17 00:00:00 2001 From: Nick Hamann Date: Tue, 19 May 2015 00:42:53 -0500 Subject: [PATCH 3/4] Add error explanations for E0185, E0186. --- src/librustc_typeck/diagnostics.rs | 44 ++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index 00cdc6eb99f..549478e4153 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -443,6 +443,48 @@ it has been disabled for now. [iss20126]: https://github.com/rust-lang/rust/issues/20126 "##, +E0185: r##" +An associated function for a trait was defined to be static, but an +implementation of the trait declared the same function to be a method (i.e. to +take a `self` parameter). + +Here's an example of this error: + +``` +trait Foo { + fn foo(); +} + +struct Bar; + +impl Foo for Bar { + // error, method `foo` has a `&self` declaration in the impl, but not in + // the trait + fn foo(&self) {} +} +"##, + +E0186: r##" +An associated function for a trait was defined to be a method (i.e. to take a +`self` parameter), but an implementation of the trait declared the same function +to be static. + +Here's an example of this error: + +``` +trait Foo { + fn foo(&self); +} + +struct Bar; + +impl Foo for Bar { + // error, method `foo` has a `&self` declaration in the trait, but not in + // the impl + fn foo() {} +} +"##, + 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 @@ -828,8 +870,6 @@ register_diagnostics! { E0174, // explicit use of unboxed closure methods are experimental E0182, E0183, - E0185, - E0186, E0187, // can't infer the kind of the closure E0188, // types differ in mutability E0189, // can only cast a boxed pointer to a boxed object From cc9d1de69251bae8b46133301fdeb0f13b8c4d51 Mon Sep 17 00:00:00 2001 From: Nick Hamann Date: Tue, 19 May 2015 01:32:42 -0500 Subject: [PATCH 4/4] Add error explanation for E0202. --- src/librustc_typeck/collect.rs | 2 +- src/librustc_typeck/diagnostics.rs | 9 ++++++++- src/test/compile-fail/assoc-inherent.rs | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index 014991f7ea5..a20a40ea7c0 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -877,7 +877,7 @@ fn convert_item(ccx: &CrateCtxt, it: &ast::Item) { if let ast::TypeImplItem(ref ty) = impl_item.node { if opt_trait_ref.is_none() { span_err!(tcx.sess, impl_item.span, E0202, - "associated items are not allowed in inherent impls"); + "associated types are not allowed in inherent impls"); } as_refsociated_type(ccx, ImplContainer(local_def(it.id)), diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index 549478e4153..64cbbb0032c 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -573,6 +573,14 @@ impl Foo { ``` "##, +E0202: r##" +Inherent associated types were part of [RFC 195] but are not yet implemented. +See [the tracking issue][iss8995] for the status of this implementation. + +[RFC 195]: https://github.com/rust-lang/rfcs/pull/195 +[iss8995]: https://github.com/rust-lang/rust/issues/8995 +"##, + E0204: r##" An attempt to implement the `Copy` trait for a struct failed because one of the fields does not implement `Copy`. To fix this, you must implement `Copy` for the @@ -881,7 +889,6 @@ register_diagnostics! { E0194, E0195, // lifetime parameters or bounds on method do not match the trait declaration E0196, // cannot determine a type for this closure - E0202, // associated items are not allowed in inherent impls 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 diff --git a/src/test/compile-fail/assoc-inherent.rs b/src/test/compile-fail/assoc-inherent.rs index e68c3e30b9a..7eab831258f 100644 --- a/src/test/compile-fail/assoc-inherent.rs +++ b/src/test/compile-fail/assoc-inherent.rs @@ -13,7 +13,7 @@ struct Foo; impl Foo { - type Bar = isize; //~ERROR associated items are not allowed in inherent impls + type Bar = isize; //~ERROR associated types are not allowed in inherent impls } fn main() {}