Expand explanation of E0530
This commit is contained in:
parent
e91405b9d5
commit
ecb6686914
@ -1,32 +1,57 @@
|
|||||||
A binding shadowed something it shouldn't.
|
A binding shadowed something it shouldn't.
|
||||||
|
|
||||||
Erroneous code example:
|
A match arm or a variable has a name that is already used by
|
||||||
|
something else, e.g.
|
||||||
|
|
||||||
|
* struct name
|
||||||
|
* enum variant
|
||||||
|
* static
|
||||||
|
* associated constant
|
||||||
|
|
||||||
|
This error may also happen when an enum variant *with fields* is used
|
||||||
|
in a pattern, but without its fields.
|
||||||
|
|
||||||
|
```compile_fail
|
||||||
|
enum Enum {
|
||||||
|
WithField(i32)
|
||||||
|
}
|
||||||
|
|
||||||
|
use Enum::*;
|
||||||
|
match WithField(1) {
|
||||||
|
WithField => {} // error: missing (_)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Match bindings cannot shadow statics:
|
||||||
|
|
||||||
```compile_fail,E0530
|
```compile_fail,E0530
|
||||||
static TEST: i32 = 0;
|
static TEST: i32 = 0;
|
||||||
|
|
||||||
let r: (i32, i32) = (0, 0);
|
let r = 123;
|
||||||
match r {
|
match r {
|
||||||
TEST => {} // error: match bindings cannot shadow statics
|
TEST => {} // error: name of a static
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
To fix this error, just change the binding's name in order to avoid shadowing
|
Fixed examples:
|
||||||
one of the following:
|
|
||||||
|
|
||||||
* struct name
|
|
||||||
* struct/enum variant
|
|
||||||
* static
|
|
||||||
* const
|
|
||||||
* associated const
|
|
||||||
|
|
||||||
Fixed example:
|
|
||||||
|
|
||||||
```
|
```
|
||||||
static TEST: i32 = 0;
|
static TEST: i32 = 0;
|
||||||
|
|
||||||
let r: (i32, i32) = (0, 0);
|
let r = 123;
|
||||||
match r {
|
match r {
|
||||||
something => {} // ok!
|
some_value => {} // ok!
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
or
|
||||||
|
|
||||||
|
```
|
||||||
|
const TEST: i32 = 0; // const, not static
|
||||||
|
|
||||||
|
let r = 123;
|
||||||
|
match r {
|
||||||
|
TEST => {} // const is ok!
|
||||||
|
other_values => {}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
Loading…
x
Reference in New Issue
Block a user