]> git.proxmox.com Git - rustc.git/blob - compiler/rustc_error_codes/src/error_codes/E0574.md
New upstream version 1.48.0~beta.8+dfsg1
[rustc.git] / compiler / rustc_error_codes / src / error_codes / E0574.md
1 Something other than a struct, variant or union has been used when one was
2 expected.
3
4 Erroneous code example:
5
6 ```compile_fail,E0574
7 mod Mordor {}
8
9 let sauron = Mordor { x: () }; // error!
10
11 enum Jak {
12 Daxter { i: isize },
13 }
14
15 let eco = Jak::Daxter { i: 1 };
16 match eco {
17 Jak { i } => {} // error!
18 }
19 ```
20
21 In all these errors, a type was expected. For example, in the first error,
22 we tried to instantiate the `Mordor` module, which is impossible. If you want
23 to instantiate a type inside a module, you can do it as follow:
24
25 ```
26 mod Mordor {
27 pub struct TheRing {
28 pub x: usize,
29 }
30 }
31
32 let sauron = Mordor::TheRing { x: 1 }; // ok!
33 ```
34
35 In the second error, we tried to bind the `Jak` enum directly, which is not
36 possible: you can only bind one of its variants. To do so:
37
38 ```
39 enum Jak {
40 Daxter { i: isize },
41 }
42
43 let eco = Jak::Daxter { i: 1 };
44 match eco {
45 Jak::Daxter { i } => {} // ok!
46 }
47 ```