-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Add error explanation for E0317, E0154, E0259, E0260. #25267
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 5 commits
7d9e605
c0412bc
f3a3684
e7fa00a
60ec4ab
ef03055
aa529ef
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 |
---|---|---|
|
@@ -10,8 +10,111 @@ | |
|
||
#![allow(non_snake_case)] | ||
|
||
// Error messages for EXXXX errors. | ||
// Each message should start and end with a new line, and be wrapped to 80 characters. | ||
// In vim you can `:set tw=80` and use `gq` to wrap paragraphs. Use `:set tw=0` to disable. | ||
register_long_diagnostics! { | ||
|
||
E0154: r##" | ||
Imports (`use` statements) are not allowed after non-item statements, such as | ||
variable declarations and expression statements. | ||
|
||
Wrong example: | ||
``` | ||
fn f() { | ||
// Variable declaration before import | ||
let x = 0; | ||
use std::io::Read; | ||
... | ||
} | ||
``` | ||
|
||
The solution is to declare the imports at the top of the block, function, or | ||
file. | ||
|
||
Here is the previous example again, with the correct order: | ||
``` | ||
fn f() { | ||
use std::io::Read; | ||
let x = 0; | ||
... | ||
} | ||
``` | ||
|
||
See the Declaration Statements section of the reference for more information | ||
about what constitutes an Item declaration and what does not: | ||
|
||
http://doc.rust-lang.org/reference.html#statements | ||
"##, | ||
|
||
E0259: r##" | ||
The name chosen for an external crate conflicts with another external crate that | ||
has been imported into the current module. | ||
|
||
Wrong example: | ||
``` | ||
extern a; | ||
extern crate_a as a; | ||
``` | ||
|
||
The solution is to choose a different name that doesn't conflict with any | ||
external crate imported into the current module. | ||
|
||
Correct example: | ||
``` | ||
extern a; | ||
extern crate_a as other_name; | ||
``` | ||
"##, | ||
|
||
E0260: r##" | ||
The name for an item declaration conflicts with an external crate's name. | ||
|
||
For instance, | ||
``` | ||
extern abc; | ||
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. Need an |
||
|
||
struct abc; | ||
``` | ||
|
||
There are two possible solutions: | ||
|
||
Solution #1: Rename the item. | ||
|
||
``` | ||
extern abc; | ||
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. Need |
||
|
||
struct xyz; | ||
``` | ||
|
||
Solution #2: Import the crate with a different name. | ||
|
||
``` | ||
extern abc as xyz; | ||
|
||
struct abc; | ||
``` | ||
|
||
See the Declaration Statements section of the reference for more information | ||
about what constitutes an Item declaration and what does not: | ||
|
||
http://doc.rust-lang.org/reference.html#statements | ||
"##, | ||
|
||
E0317: r##" | ||
User-defined types or type parameters cannot shadow the primitive types. | ||
This error indicates you tried to define a type, struct or enum with the same | ||
name as an existing primitive type, and is therefore invalid. | ||
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. Maybe drop the "and is therefore invalid" here? |
||
|
||
See the Types section of the reference for more information about the primitive | ||
types: | ||
|
||
http://doc.rust-lang.org/reference.html#types | ||
"## | ||
|
||
} | ||
|
||
register_diagnostics! { | ||
E0154, | ||
E0157, | ||
E0153, | ||
E0251, // a named type or value has already been imported in this module | ||
|
@@ -22,9 +125,6 @@ register_diagnostics! { | |
E0256, // import conflicts with type in this module | ||
E0257, // inherent implementations are only allowed on types defined in the current module | ||
E0258, // import conflicts with existing submodule | ||
E0259, // an extern crate has already been imported into this module | ||
E0260, // name conflicts with an external crate that has been imported into this module | ||
E0317, // user-defined types or type parameters cannot shadow the primitive types | ||
E0364, // item is private | ||
E0365 // item is private | ||
} |
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.
I love this error message, but I think the "Wrong example" wording is a bit awkward (despite its incidence elsewhere). In this case you could maybe say "Here's an example that demonstrates the error:".