-
Notifications
You must be signed in to change notification settings - Fork 13.5k
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
Changes from 6 commits
2f84173
8ef395f
6715ec8
1ac7633
768111f
73685af
73b369d
5650709
633fe44
962b61f
a37af48
0642d99
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1278,6 +1278,15 @@ fn main() { | |
``` | ||
"##, | ||
|
||
E0103: r##" | ||
You hit this error because the compiler the compiler lacks information | ||
to determine a type for this pattern binding. | ||
|
||
You have two possibilities to solve this situation: | ||
* Give an explicit definition of the expression | ||
* Infer the expression | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think either of these make sense in this case. I'd need an example of this error and a solution to be sure though. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't find the way to span it. So for the moment, I took the same error explanation than the previous ones (since this is spanned from the same place, I guess it must be quite similar). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, but neither suggestion makes sense (or is useful) when talking about patterns. |
||
"##, | ||
|
||
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 | ||
|
@@ -2410,6 +2419,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>` | ||
} | ||
``` | ||
|
||
To fix this error, please verify you didn't misspell the associated | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please verify that the associated const wasn't misspelled and the correct trait item was implemented. |
||
const name or you did implement the good trait item. 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 you didn't misspell the method name. Example: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please verify that the method name wasn't misspelled and verify that you are indeed implementing the correct trait items |
||
|
||
``` | ||
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>` | ||
} | ||
``` | ||
|
||
To fix this error, please verify you didn't misspell the associated type name | ||
and that your trait item implementation corresponds to the trait definition. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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. | ||
|
@@ -2576,6 +2711,28 @@ 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 this type implements this binary operation. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please check that ... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please check that ... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please check that [...] |
||
Example: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is also possible to overload most operators for your own type by implementing traits from |
||
|
||
``` | ||
let x = 12u32; // the `u32` type does implement it: | ||
// https://doc.rust-lang.org/stable/std/ops/trait.Shl.html | ||
|
||
x << 2; // ok! | ||
``` | ||
"##, | ||
|
||
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 | ||
|
@@ -2617,6 +2774,22 @@ 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 on an `*mut T` type. Erroneous code example: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You tried to implement methods for a mutable raw pointer ( |
||
|
||
``` | ||
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 | ||
``` | ||
|
||
To fix this, please follow the compiler recommendations. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The compiler doesn't recommend anything here. How about "This isn't allowed, perhaps you might get the desired effects by wrapping the raw pointer in a struct", and then suggest doing |
||
"##, | ||
|
||
E0391: r##" | ||
This error indicates that some types or traits depend on each other | ||
and therefore cannot be constructed. | ||
|
@@ -2701,7 +2874,6 @@ register_diagnostics! { | |
E0085, | ||
E0086, | ||
E0090, | ||
E0103, | ||
E0104, | ||
E0118, | ||
E0122, | ||
|
@@ -2760,12 +2932,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 | ||
|
@@ -2776,8 +2944,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 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"the compiler the compiler" :)