about summary refs log tree commit diff
path: root/src/libsyntax
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/libsyntax
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/libsyntax')
-rw-r--r--src/libsyntax/feature_gate.rs3
1 files changed, 3 insertions, 0 deletions
diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs
index bc36bde5cba..71ad118ed8e 100644
--- a/src/libsyntax/feature_gate.rs
+++ b/src/libsyntax/feature_gate.rs
@@ -471,6 +471,9 @@ declare_features! (
     // 'a: { break 'a; }
     (active, label_break_value, "1.28.0", Some(48594), None),
 
+    // Integer match exhaustiveness checking
+    (active, exhaustive_integer_patterns, "1.30.0", Some(50907), None),
+
     // #[panic_implementation]
     (active, panic_implementation, "1.28.0", Some(44489), None),