diff options
| author | Niko Matsakis <niko@alum.mit.edu> | 2016-03-11 13:30:32 -0500 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2016-03-25 06:45:42 -0400 |
| commit | f69eb8efbe5dbc373426bf0ff021b49f37db41cb (patch) | |
| tree | 10d6bbc6f8cc1a62e3caac9611b68261ea6f3cf4 /src/rustllvm/ExecutionEngineWrapper.cpp | |
| parent | 05baf645e47a0ed3893f2413696e56be180249ff (diff) | |
| download | rust-f69eb8efbe5dbc373426bf0ff021b49f37db41cb.tar.gz rust-f69eb8efbe5dbc373426bf0ff021b49f37db41cb.zip | |
issue a future-compat lint for constants of invalid type
This is a [breaking-change]: according to RFC #1445, constants used as
patterns must be of a type that *derives* `Eq`. If you encounter a
problem, you are most likely using a constant in an expression where the
type of the constant is some struct that does not currently implement
`Eq`. Something like the following:
```rust
struct SomeType { ... }
const SOME_CONST: SomeType = ...;
match foo {
SOME_CONST => ...
}
```
The easiest and most future compatible fix is to annotate the type in
question with `#[derive(Eq)]` (note that merely *implementing* `Eq` is
not enough, it must be *derived*):
```rust
struct SomeType { ... }
const SOME_CONST: SomeType = ...;
match foo {
SOME_CONST => ...
}
```
Another good option is to rewrite the match arm to use an `if`
condition (this is also particularly good for floating point types,
which implement `PartialEq` but not `Eq`):
```rust
match foo {
c if c == SOME_CONST => ...
}
```
Finally, a third alternative is to tag the type with
`#[structural_match]`; but this is not recommended, as the attribute is
never expected to be stabilized. Please see RFC #1445 for more details.
Diffstat (limited to 'src/rustllvm/ExecutionEngineWrapper.cpp')
0 files changed, 0 insertions, 0 deletions
