Skip to content

Commit bb15c47

Browse files
committed
Rollup merge of rust-lang#25267 - meqif:explain_e0317, r=alexcrichton
Add diagnostic message for E0317, E0154, E0259 and E0260; part of rust-lang#24407. About E0317, I was unsure if I should add an example of what could be wrong, such as `struct i64`, `enum char { A, B }` or `type isize = i64`. I decided against it, since the diagnostic message looks clear enough to me. What do you think?
2 parents e91d272 + aa529ef commit bb15c47

File tree

1 file changed

+104
-4
lines changed

1 file changed

+104
-4
lines changed

src/librustc_resolve/diagnostics.rs

Lines changed: 104 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,111 @@
1010

1111
#![allow(non_snake_case)]
1212

13+
// Error messages for EXXXX errors.
14+
// Each message should start and end with a new line, and be wrapped to 80 characters.
15+
// In vim you can `:set tw=80` and use `gq` to wrap paragraphs. Use `:set tw=0` to disable.
16+
register_long_diagnostics! {
17+
18+
E0154: r##"
19+
Imports (`use` statements) are not allowed after non-item statements, such as
20+
variable declarations and expression statements.
21+
22+
Here is an example that demonstrates the error:
23+
```
24+
fn f() {
25+
// Variable declaration before import
26+
let x = 0;
27+
use std::io::Read;
28+
...
29+
}
30+
```
31+
32+
The solution is to declare the imports at the top of the block, function, or
33+
file.
34+
35+
Here is the previous example again, with the correct order:
36+
```
37+
fn f() {
38+
use std::io::Read;
39+
let x = 0;
40+
...
41+
}
42+
```
43+
44+
See the Declaration Statements section of the reference for more information
45+
about what constitutes an Item declaration and what does not:
46+
47+
http://doc.rust-lang.org/reference.html#statements
48+
"##,
49+
50+
E0259: r##"
51+
The name chosen for an external crate conflicts with another external crate that
52+
has been imported into the current module.
53+
54+
Wrong example:
55+
```
56+
extern crate a;
57+
extern crate crate_a as a;
58+
```
59+
60+
The solution is to choose a different name that doesn't conflict with any
61+
external crate imported into the current module.
62+
63+
Correct example:
64+
```
65+
extern crate a;
66+
extern crate crate_a as other_name;
67+
```
68+
"##,
69+
70+
E0260: r##"
71+
The name for an item declaration conflicts with an external crate's name.
72+
73+
For instance,
74+
```
75+
extern crate abc;
76+
77+
struct abc;
78+
```
79+
80+
There are two possible solutions:
81+
82+
Solution #1: Rename the item.
83+
84+
```
85+
extern crate abc;
86+
87+
struct xyz;
88+
```
89+
90+
Solution #2: Import the crate with a different name.
91+
92+
```
93+
extern crate abc as xyz;
94+
95+
struct abc;
96+
```
97+
98+
See the Declaration Statements section of the reference for more information
99+
about what constitutes an Item declaration and what does not:
100+
101+
http://doc.rust-lang.org/reference.html#statements
102+
"##,
103+
104+
E0317: r##"
105+
User-defined types or type parameters cannot shadow the primitive types.
106+
This error indicates you tried to define a type, struct or enum with the same
107+
name as an existing primitive type.
108+
109+
See the Types section of the reference for more information about the primitive
110+
types:
111+
112+
http://doc.rust-lang.org/reference.html#types
113+
"##
114+
115+
}
116+
13117
register_diagnostics! {
14-
E0154,
15118
E0157,
16119
E0153,
17120
E0251, // a named type or value has already been imported in this module
@@ -22,9 +125,6 @@ register_diagnostics! {
22125
E0256, // import conflicts with type in this module
23126
E0257, // inherent implementations are only allowed on types defined in the current module
24127
E0258, // import conflicts with existing submodule
25-
E0259, // an extern crate has already been imported into this module
26-
E0260, // name conflicts with an external crate that has been imported into this module
27-
E0317, // user-defined types or type parameters cannot shadow the primitive types
28128
E0364, // item is private
29129
E0365 // item is private
30130
}

0 commit comments

Comments
 (0)