]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_error_codes/src/error_codes/E0530.md
Merge commit '97e504549371d7640cf011d266e3c17394fdddac' into sync_cg_clif-2021-12-20
[rust.git] / compiler / rustc_error_codes / src / error_codes / E0530.md
1 A binding shadowed something it shouldn't.
2
3 A match arm or a variable has a name that is already used by
4 something else, e.g.
5
6 * struct name
7 * enum variant
8 * static
9 * associated constant
10
11 This error may also happen when an enum variant *with fields* is used
12 in a pattern, but without its fields.
13
14 ```compile_fail
15 enum Enum {
16     WithField(i32)
17 }
18
19 use Enum::*;
20 match WithField(1) {
21     WithField => {} // error: missing (_)
22 }
23 ```
24
25 Match bindings cannot shadow statics:
26
27 ```compile_fail,E0530
28 static TEST: i32 = 0;
29
30 let r = 123;
31 match r {
32     TEST => {} // error: name of a static
33 }
34 ```
35
36 Fixed examples:
37
38 ```
39 static TEST: i32 = 0;
40
41 let r = 123;
42 match r {
43     some_value => {} // ok!
44 }
45 ```
46
47 or
48
49 ```
50 const TEST: i32 = 0; // const, not static
51
52 let r = 123;
53 match r {
54     TEST => {} // const is ok!
55     other_values => {}
56 }
57 ```