]> git.lizzy.rs Git - rust.git/blob - src/librustc_error_codes/error_codes/E0170.md
Rollup merge of #62514 - stephaneyfx:box-ffi, r=nikomatsakis
[rust.git] / src / librustc_error_codes / error_codes / E0170.md
1 Enum variants are qualified by default. For example, given this type:
2
3 ```
4 enum Method {
5     GET,
6     POST,
7 }
8 ```
9
10 You would match it using:
11
12 ```
13 enum Method {
14     GET,
15     POST,
16 }
17
18 let m = Method::GET;
19
20 match m {
21     Method::GET => {},
22     Method::POST => {},
23 }
24 ```
25
26 If you don't qualify the names, the code will bind new variables named "GET" and
27 "POST" instead. This behavior is likely not what you want, so `rustc` warns when
28 that happens.
29
30 Qualified names are good practice, and most code works well with them. But if
31 you prefer them unqualified, you can import the variants into scope:
32
33 ```
34 use Method::*;
35 enum Method { GET, POST }
36 # fn main() {}
37 ```
38
39 If you want others to be able to import variants from your module directly, use
40 `pub use`:
41
42 ```
43 pub use Method::*;
44 pub enum Method { GET, POST }
45 # fn main() {}
46 ```