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
63 changes: 60 additions & 3 deletions src/librustc_resolve/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,66 @@ 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
_ => {}
}
```

The compiler needs to know the value of the pattern at compile time,
which is not possible with a `static` variable. Please verify that the
Copy link
Member

Choose a reason for hiding this comment

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

nit: saying "is not possible" may be re-opening a can of worms by implicitly inviting back those who were arguing, back when we first split up the two forms, that the static / const distinction was unnecessary.

I would prefer something like:

The compiler needs to know the value of the pattern at compile time; compile-time patterns can defined via const or enum items. Please verify that the identifier is spelled correctly, and if so, use a const instead of static to define it.
Example:
...

variable is spelled correctly and if so, try to use a `const` instead.
Example:

```
const FOO : i32 = 0;

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

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

```
struct Foo;

impl Foo {
fn bar(self) {}

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

Please check if the method's argument list should have contained self,
Copy link
Member

Choose a reason for hiding this comment

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

self, &self or &mut self.

&self, or &mut self (in case you didn't want to create a static method),
and add it if so. Example:

```
struct Foo;

impl Foo {
fn bar(self) {}

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

E0428: r##"
A type or module has been defined more than once. Example of erroneous
code:
Expand Down Expand Up @@ -448,16 +508,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