Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 45b7218

Browse files
authoredAug 10, 2021
Rollup merge of rust-lang#87700 - kornelski:e530text, r=oli-obk
Expand explanation of E0530 The explanation didn't cover a puzzling case of enum variants missing fields.
2 parents ef52055 + ecb6686 commit 45b7218

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 numberDiff line numberDiff line change
@@ -1,32 +1,57 @@
11
A 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
628
static TEST: i32 = 0;
729
8-
let r: (i32, i32) = (0, 0);
30+
let r = 123;
931
match 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;
2953
match r {
30-
something => {} // ok!
54+
TEST => {} // const is ok!
55+
other_values => {}
3156
}
3257
```

0 commit comments

Comments
 (0)
Please sign in to comment.