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