Skip to content

Add error explanations for E0185, E0186, E0202, E0326. Fix E0053. #25593

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 26, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/librustc_typeck/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down
108 changes: 80 additions & 28 deletions src/librustc_typeck/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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); }

struct Bar;

impl Foo for Bar {
// error, the signature should be `fn foo(&self)` instead
fn foo(&mut self) { }
trait Foo {
fn foo(x: u16);
fn bar(&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 }
}
// error, expected u16, found i16
fn foo(x: i16) { }

fn main() {}
// error, values differ in mutability
fn foo(&mut self) { }
}
```


"##,

E0054: r##"
Expand Down Expand Up @@ -456,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
Expand Down Expand Up @@ -544,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
Expand Down Expand Up @@ -684,6 +721,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.
Expand Down Expand Up @@ -822,8 +878,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
Expand All @@ -835,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
Expand Down Expand Up @@ -885,7 +938,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
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/assoc-inherent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}