Skip to content

Expand explanation of E0530 #87700

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 11, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 39 additions & 14 deletions compiler/rustc_error_codes/src/error_codes/E0530.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,57 @@
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
static TEST: i32 = 0;

let r: (i32, i32) = (0, 0);
let r = 123;
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
one of the following:
Fixed examples:

* struct name
* struct/enum variant
* static
* const
* associated const
```
static TEST: i32 = 0;

Fixed example:
let r = 123;
match r {
some_value => {} // ok!
}
```

or

```
static TEST: i32 = 0;
const TEST: i32 = 0; // const, not static

let r: (i32, i32) = (0, 0);
let r = 123;
match r {
something => {} // ok!
TEST => {} // const is ok!
other_values => {}
}
```