File tree Expand file tree Collapse file tree 1 file changed +39
-14
lines changed
compiler/rustc_error_codes/src/error_codes Expand file tree Collapse file tree 1 file changed +39
-14
lines changed Original file line number Diff line number Diff line change 11A binding shadowed something it shouldn't.
22
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:
426
527``` compile_fail,E0530
628static TEST: i32 = 0;
729
8- let r: (i32, i32) = (0, 0) ;
30+ let r = 123 ;
931match r {
10- TEST => {} // error: match bindings cannot shadow statics
32+ TEST => {} // error: name of a static
1133}
1234```
1335
14- To fix this error, just change the binding's name in order to avoid shadowing
15- one of the following:
36+ Fixed examples:
1637
17- * struct name
18- * struct/enum variant
19- * static
20- * const
21- * associated const
38+ ```
39+ static TEST: i32 = 0;
2240
23- Fixed example:
41+ let r = 123;
42+ match r {
43+ some_value => {} // ok!
44+ }
45+ ```
46+
47+ or
2448
2549```
26- static TEST: i32 = 0;
50+ const TEST: i32 = 0; // const, not static
2751
28- let r: (i32, i32) = (0, 0) ;
52+ let r = 123 ;
2953match r {
30- something => {} // ok!
54+ TEST => {} // const is ok!
55+ other_values => {}
3156}
3257```
You can’t perform that action at this time.
0 commit comments