Skip to content

Add E0417, E0424, E0425, E0426, E0430, E0431 and E0432 error explanations #27230

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 10 commits into from
Jul 27, 2015
73 changes: 70 additions & 3 deletions src/librustc_resolve/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,76 @@ impl Bar {
```
"##,

E0417: r##"
A static variable was referenced in a pattern. Example of erroneous code:

```
static FOO : i32 = 0;

match 0 {
FOO => {} // error: static variables cannot be referenced in a
// pattern, use a `const` instead
_ => {}
}
```

Compiler needs to know the pattern value at compile's time, which is
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The compiler needs to know the value of the pattern at compile time,

not possible with a `static` variable. So please verify you didn't
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please verify that the variable is spelled correctly and if so, try to use a const instead.

misspell the variable's name or use a `const` instead. Example:

```
const FOO : i32 = 0;

match 0 {
FOO => {} // ok!
_ => {}
}
```
"##,

E0424: r##"
`self` keyword was used in a static method. Example of erroneous code:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The self keyword


```
struct Foo;

impl Foo {
fn bar(self) {}

fn foo() {
self.bar(); // error: `self` is not available in a static method.
}
}
```

Please verify you didn't forget to add `self` in your method's argument
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check if the method's argument list should have contained self, &self, or &mut self (in case you didn't want to create a static method), and add it if so.

list if your intention wasn't to create a static method. Example:

```
struct Foo;

impl Foo {
fn bar(self) {}

fn foo(self) {
self.bar(); // ok!
}
}
```

Or please verify you didn't misspell the variable's name:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really necessary here I think

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to be sure to cover all of errors possible (that's what error code explanation are for, no ? ^^).


```
struct Foo;

impl Foo {
fn foo(sel: i32) {
println!("{}", sel); // ok!
}
}
```
"##,

E0428: r##"
A type or module has been defined more than once. Example of erroneous
code:
Expand Down Expand Up @@ -448,16 +518,13 @@ register_diagnostics! {
E0414, // only irrefutable patterns allowed here
E0415, // identifier is bound more than once in this parameter list
E0416, // identifier is bound more than once in the same pattern
E0417, // static variables cannot be referenced in a pattern, use a
// `const` instead
E0418, // is not an enum variant, struct or const
E0419, // unresolved enum variant, struct or const
E0420, // is not an associated const
E0421, // unresolved associated const
E0422, // does not name a structure
E0423, // is a struct variant name, but this expression uses it like a
// function name
E0424, // `self` is not available in a static method.
E0425, // unresolved name
E0426, // use of undeclared label
E0427, // cannot use `ref` binding mode with ...
Expand Down