Skip to content

Commit a6778a2

Browse files
committed
Improve E0317 long diagnostics
1 parent f8c2d57 commit a6778a2

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

src/librustc_resolve/diagnostics.rs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,41 @@ https://doc.rust-lang.org/reference.html#statements
207207
E0317: r##"
208208
User-defined types or type parameters cannot shadow the primitive types.
209209
This error indicates you tried to define a type, struct or enum with the same
210-
name as an existing primitive type.
210+
name as an existing primitive type:
211+
212+
```
213+
struct u8 {
214+
// ...
215+
}
216+
```
217+
218+
To fix this, simply name it something else.
219+
220+
Such an error may also occur if you define a type parameter which shadows a
221+
primitive type. An example would be something like:
222+
223+
```
224+
impl<u8> MyTrait for Option<u8> {
225+
// ...
226+
}
227+
```
228+
229+
In such a case, if you meant for `u8` to be a generic type parameter (i.e. any
230+
type can be used in its place), use something like `T` instead:
231+
232+
```
233+
impl<T> MyTrait for Option<T> {
234+
// ...
235+
}
236+
```
237+
238+
On the other hand, if you wished to refer to the specific type `u8`, remove it
239+
from the type parameter list:
240+
241+
```
242+
impl MyTrait for Option<u8> {
243+
// ...
244+
}
211245
212246
See the Types section of the reference for more information about the primitive
213247
types:

0 commit comments

Comments
 (0)