-
Notifications
You must be signed in to change notification settings - Fork 13.3k
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
Changes from 2 commits
d6b9e0b
8a75dcd
0efc7f1
1f81002
18f4e8c
2537abf
9e1ea5e
c8b9e83
40617b6
fc65f55
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 |
---|---|---|
|
@@ -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 | ||
not possible with a `static` variable. So please verify you didn't | ||
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 variable is spelled correctly and if so, try to use a |
||
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: | ||
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 |
||
|
||
``` | ||
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 | ||
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 if the method's argument list should have contained |
||
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: | ||
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. Not really necessary here I think 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 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: | ||
|
@@ -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 ... | ||
|
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 needs to know the value of the pattern at compile time,