File tree 1 file changed +39
-14
lines changed
compiler/rustc_error_codes/src/error_codes
1 file changed +39
-14
lines changed Original file line number Diff line number Diff line change 1
1
A binding shadowed something it shouldn't.
2
2
3
- Erroneous code example:
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:
4
26
5
27
``` compile_fail,E0530
6
28
static TEST: i32 = 0;
7
29
8
- let r: (i32, i32) = (0, 0) ;
30
+ let r = 123 ;
9
31
match r {
10
- TEST => {} // error: match bindings cannot shadow statics
32
+ TEST => {} // error: name of a static
11
33
}
12
34
```
13
35
14
- To fix this error, just change the binding's name in order to avoid shadowing
15
- one of the following:
36
+ Fixed examples:
16
37
17
- * struct name
18
- * struct/enum variant
19
- * static
20
- * const
21
- * associated const
38
+ ```
39
+ static TEST: i32 = 0;
22
40
23
- Fixed example:
41
+ let r = 123;
42
+ match r {
43
+ some_value => {} // ok!
44
+ }
45
+ ```
46
+
47
+ or
24
48
25
49
```
26
- static TEST: i32 = 0;
50
+ const TEST: i32 = 0; // const, not static
27
51
28
- let r: (i32, i32) = (0, 0) ;
52
+ let r = 123 ;
29
53
match r {
30
- something => {} // ok!
54
+ TEST => {} // const is ok!
55
+ other_values => {}
31
56
}
32
57
```
You can’t perform that action at this time.
0 commit comments