]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_error_codes/src/error_codes/E0531.md
Rollup merge of #92310 - ehuss:rustdoc-ice, r=estebank
[rust.git] / compiler / rustc_error_codes / src / error_codes / E0531.md
1 An unknown tuple struct/variant has been used.
2
3 Erroneous code example:
4
5 ```compile_fail,E0531
6 let Type(x) = Type(12); // error!
7 match Bar(12) {
8     Bar(x) => {} // error!
9     _ => {}
10 }
11 ```
12
13 In most cases, it's either a forgotten import or a typo. However, let's look at
14 how you can have such a type:
15
16 ```edition2018
17 struct Type(u32); // this is a tuple struct
18
19 enum Foo {
20     Bar(u32), // this is a tuple variant
21 }
22
23 use Foo::*; // To use Foo's variant directly, we need to import them in
24             // the scope.
25 ```
26
27 Either way, it should work fine with our previous code:
28
29 ```edition2018
30 struct Type(u32);
31
32 enum Foo {
33     Bar(u32),
34 }
35 use Foo::*;
36
37 let Type(x) = Type(12); // ok!
38 match Type(12) {
39     Type(x) => {} // ok!
40     _ => {}
41 }
42 ```