]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_error_codes/src/error_codes/E0575.md
Rollup merge of #92310 - ehuss:rustdoc-ice, r=estebank
[rust.git] / compiler / rustc_error_codes / src / error_codes / E0575.md
1 Something other than a type or an associated type was given.
2
3 Erroneous code example:
4
5 ```compile_fail,E0575
6 enum Rick { Morty }
7
8 let _: <u8 as Rick>::Morty; // error!
9
10 trait Age {
11     type Empire;
12     fn Mythology() {}
13 }
14
15 impl Age for u8 {
16     type Empire = u16;
17 }
18
19 let _: <u8 as Age>::Mythology; // error!
20 ```
21
22 In both cases, we're declaring a variable (called `_`) and we're giving it a
23 type. However, `<u8 as Rick>::Morty` and `<u8 as Age>::Mythology` aren't types,
24 therefore the compiler throws an error.
25
26 `<u8 as Rick>::Morty` is an enum variant, you cannot use a variant as a type,
27 you have to use the enum directly:
28
29 ```
30 enum Rick { Morty }
31
32 let _: Rick; // ok!
33 ```
34
35 `<u8 as Age>::Mythology` is a trait method, which is definitely not a type.
36 However, the `Age` trait provides an associated type `Empire` which can be
37 used as a type:
38
39 ```
40 trait Age {
41     type Empire;
42     fn Mythology() {}
43 }
44
45 impl Age for u8 {
46     type Empire = u16;
47 }
48
49 let _: <u8 as Age>::Empire; // ok!
50 ```