Skip to content

Add E0323, E0324, E0325, E0369 and E0390 errors explanation #27586

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 12 commits into from
Aug 23, 2015
2 changes: 2 additions & 0 deletions src/librustc_typeck/coherence/orphan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ impl<'cx, 'tcx> OrphanChecker<'cx, 'tcx> {
span_err!(self.tcx.sess, span, E0390,
"only a single inherent implementation marked with `#[lang = \"{}\"]` \
is allowed for the `{}` primitive", lang, ty);
span_help!(self.tcx.sess, span,
"consider using a trait to implement these methods");
}
}
}
Expand Down
190 changes: 183 additions & 7 deletions src/librustc_typeck/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2410,6 +2410,132 @@ for types as needed by the compiler, and it is currently disallowed to
explicitly implement it for a type.
"##,

E0323: r##"
An associated const was implemented when another trait item was expected.
Erroneous code example:

```
trait Foo {
type N;
}

struct Bar;

impl Foo for Bar {
const N : u32 = 0;
// error: item `N` is an associated const, which doesn't match its
// trait `<Bar as Foo>`
}
```

Please verify that the associated const wasn't misspelled and the correct trait
was implemented. Example:

```
struct Bar;

trait Foo {
type N;
}

impl Foo for Bar {
type N = u32; // ok!
}

// or:
trait Foo {
const N : u32;
}

impl Foo for Bar {
const N : u32 = 0; // ok!
}
```
"##,

E0324: r##"
A method was implemented when another trait item was expected. Erroneous
code example:

```
struct Bar;

trait Foo {
const N : u32;

fn M();
}

impl Foo for Bar {
fn N() {}
// error: item `N` is an associated method, which doesn't match its
// trait `<Bar as Foo>`
}
```

To fix this error, please verify that the method name wasn't misspelled and
verify that you are indeed implementing the correct trait items. Example:

```
struct Bar;

trait Foo {
const N : u32;

fn M();
}

impl Foo for Bar {
const N : u32 = 0;

fn M() {} // ok!
}
```
"##,

E0325: r##"
An associated type was implemented when another trait item was expected.
Erroneous code example:

```
struct Bar;

trait Foo {
const N : u32;
}

impl Foo for Bar {
type N = u32;
// error: item `N` is an associated type, which doesn't match its
// trait `<Bar as Foo>`
}
```

Please verify that the associated type name wasn't misspelled and your
implementation corresponds to the trait definition. Example:

```
struct Bar;

trait Foo {
type N;
}

impl Foo for Bar {
type N = u32; // ok!
}

//or:
trait Foo {
const N : u32;
}

impl Foo for Bar {
const N : u32 = 0; // ok!
}
```
"##,

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.
Expand Down Expand Up @@ -2576,6 +2702,31 @@ to change this.
[RFC 953]: https://github.com/rust-lang/rfcs/pull/953
"##,

E0369: r##"
A binary operation was attempted on a type which doesn't support it.
Erroneous code example:

```
let x = 12f32; // error: binary operation `<<` cannot be applied to
// type `f32`

x << 2;
```

To fix this error, please check that this type implements this binary
operation. Example:

```
let x = 12u32; // the `u32` type does implement it:
// https://doc.rust-lang.org/stable/std/ops/trait.Shl.html

x << 2; // ok!
```

It is also possible to overload most operators for your own type by
implementing traits from `std::ops`.
"##,

E0371: r##"
When `Trait2` is a subtrait of `Trait1` (for example, when `Trait2` has a
definition like `trait Trait2: Trait1 { ... }`), it is not allowed to implement
Expand Down Expand Up @@ -2617,6 +2768,37 @@ For more information see the [opt-in builtin traits RFC](https://github.com/rust
-lang/rfcs/blob/master/text/0019-opt-in-builtin-traits.md).
"##,

E0390: r##"
You tried to implement methods for a primitive type. Erroneous code example:

```
struct Foo {
x: i32
}

impl *mut Foo {}
// error: only a single inherent implementation marked with
// `#[lang = "mut_ptr"]` is allowed for the `*mut T` primitive
```

This isn't allowed, but using a trait to implement a method is a good solution.
Example:

```
struct Foo {
x: i32
}

trait Bar {
fn bar();
}

impl Bar for *mut Foo {
fn bar() {} // ok!
}
```
"##,

E0391: r##"
This error indicates that some types or traits depend on each other
and therefore cannot be constructed.
Expand Down Expand Up @@ -2701,7 +2883,7 @@ register_diagnostics! {
E0085,
E0086,
E0090,
E0103,
E0103, // @GuillaumeGomez: I was unable to get this error, try your best!
E0104,
E0118,
E0122,
Expand Down Expand Up @@ -2760,12 +2942,8 @@ register_diagnostics! {
E0319, // trait impls for defaulted traits allowed just for structs/enums
E0320, // recursive overflow during dropck
E0321, // extended coherence rules for defaulted traits violated
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
E0328, // cannot implement Unsize explicitly
E0329, // associated const depends on type parameter or Self.
E0369, // binary operation `<op>` cannot be applied to types
E0370, // discriminant overflow
E0374, // the trait `CoerceUnsized` may only be implemented for a coercion
// between structures with one field being coerced, none found
Expand All @@ -2776,8 +2954,6 @@ register_diagnostics! {
// between structures
E0377, // the trait `CoerceUnsized` may only be implemented for a coercion
// between structures with the same definition
E0390, // only a single inherent implementation marked with
// `#[lang = \"{}\"]` is allowed for the `{}` primitive
E0393, // the type parameter `{}` must be explicitly specified in an object
// type because its default value `{}` references the type `Self`"
E0399, // trait items need to be implemented because the associated
Expand Down