about summary refs log tree commit diff
path: root/src/liballoc
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2018-08-22 00:57:00 +0000
committerbors <bors@rust-lang.org>2018-08-22 00:57:00 +0000
commita79cffb8b8330527d262bdde56387d45ac46dd44 (patch)
tree449ba4ee567f5dff4b1c5f0d94be3203bae5a535 /src/liballoc
parent1cbf339626e52e1e66a6df3097051bb981bfa964 (diff)
parent6971c5d55d06c02c8f0b943b3d0b06ef2611c8ac (diff)
downloadrust-a79cffb8b8330527d262bdde56387d45ac46dd44.tar.gz
rust-a79cffb8b8330527d262bdde56387d45ac46dd44.zip
Auto merge of #50912 - varkor:exhaustive-integer-matching, r=arielb1
Exhaustive integer matching

This adds a new feature flag `exhaustive_integer_patterns` that enables exhaustive matching of integer types by their values. For example, the following is now accepted:
```rust
#![feature(exhaustive_integer_patterns)]
#![feature(exclusive_range_pattern)]

fn matcher(x: u8) {
  match x { // ok
    0 .. 32 => { /* foo */ }
    32 => { /* bar */ }
    33 ..= 255 => { /* baz */ }
  }
}
```
This matching is permitted on all integer (signed/unsigned and char) types. Sensible error messages are also provided. For example:
```rust
fn matcher(x: u8) {
  match x { //~ ERROR
    0 .. 32 => { /* foo */ }
  }
}
```
results in:
```
error[E0004]: non-exhaustive patterns: `32u8...255u8` not covered
 --> matches.rs:3:9
  |
6 |   match x {
  |         ^ pattern `32u8...255u8` not covered
```

This implements https://github.com/rust-lang/rfcs/issues/1550 for https://github.com/rust-lang/rust/issues/50907. While there hasn't been a full RFC for this feature, it was suggested that this might be a feature that obviously complements the existing exhaustiveness checks (e.g. for `bool`) and so a feature gate would be sufficient for now.
Diffstat (limited to 'src/liballoc')
0 files changed, 0 insertions, 0 deletions