diff options
| author | bors <bors@rust-lang.org> | 2018-08-22 00:57:00 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2018-08-22 00:57:00 +0000 |
| commit | a79cffb8b8330527d262bdde56387d45ac46dd44 (patch) | |
| tree | 449ba4ee567f5dff4b1c5f0d94be3203bae5a535 /src/librustc/mir | |
| parent | 1cbf339626e52e1e66a6df3097051bb981bfa964 (diff) | |
| parent | 6971c5d55d06c02c8f0b943b3d0b06ef2611c8ac (diff) | |
| download | rust-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/librustc/mir')
| -rw-r--r-- | src/librustc/mir/mod.rs | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs index 54fe30e609d..bafeb5dd128 100644 --- a/src/librustc/mir/mod.rs +++ b/src/librustc/mir/mod.rs @@ -2228,7 +2228,7 @@ pub fn fmt_const_val<W: Write>(fmt: &mut W, const_val: &ty::Const) -> fmt::Resul } } -pub fn print_miri_value<W: Write>(value: Value, ty: Ty, f: &mut W) -> fmt::Result { +pub fn print_miri_value<'tcx, W: Write>(value: Value, ty: Ty<'tcx>, f: &mut W) -> fmt::Result { use ty::TypeVariants::*; // print some primitives if let Value::Scalar(ScalarMaybeUndef::Scalar(Scalar::Bits { bits, .. })) = value { |
