summary refs log tree commit diff
path: root/src/test/ui/pattern/usefulness/integer-ranges
diff options
context:
space:
mode:
authorEsteban Kuber <esteban@kuber.com.ar>2021-12-16 02:28:09 +0000
committerEsteban Kuber <esteban@kuber.com.ar>2022-03-08 00:18:24 +0000
commit084ca79e7c721e5b670eb4e4da4b45519c0822cb (patch)
tree4e6caa6b77d1e538e75be51515c4165d621f7081 /src/test/ui/pattern/usefulness/integer-ranges
parent2383858f34989f7c6c87da857bd038f5ce0a66b0 (diff)
downloadrust-084ca79e7c721e5b670eb4e4da4b45519c0822cb.tar.gz
rust-084ca79e7c721e5b670eb4e4da4b45519c0822cb.zip
When finding a match expr with multiple arms that requires more, suggest it
Given

```rust
match Some(42) {
    Some(0) => {}
    Some(1) => {}
}
```

suggest

```rust
match Some(42) {
    Some(0) => {}
    Some(1) => {}
    None | Some(_) => todo!(),
}
```
Diffstat (limited to 'src/test/ui/pattern/usefulness/integer-ranges')
-rw-r--r--src/test/ui/pattern/usefulness/integer-ranges/exhaustiveness.stderr12
-rw-r--r--src/test/ui/pattern/usefulness/integer-ranges/pointer-sized-int.deny.stderr6
2 files changed, 15 insertions, 3 deletions
diff --git a/src/test/ui/pattern/usefulness/integer-ranges/exhaustiveness.stderr b/src/test/ui/pattern/usefulness/integer-ranges/exhaustiveness.stderr
index 8734d0f04ac..56de29cbd81 100644
--- a/src/test/ui/pattern/usefulness/integer-ranges/exhaustiveness.stderr
+++ b/src/test/ui/pattern/usefulness/integer-ranges/exhaustiveness.stderr
@@ -96,7 +96,11 @@ LL |     match 0i8 {
    |           ^^^ pattern `0_i8` not covered
    |
    = note: the matched value is of type `i8`
-   = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
+help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
+   |
+LL ~         1 ..= i8::MAX => {}
+LL +         0_i8 => todo!()
+   |
 
 error[E0004]: non-exhaustive patterns: `u128::MAX` not covered
   --> $DIR/exhaustiveness.rs:59:8
@@ -144,7 +148,11 @@ LL |     match (0u8, true) {
    |           ^^^^^^^^^^^ pattern `(126_u8..=127_u8, false)` not covered
    |
    = note: the matched value is of type `(u8, bool)`
-   = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
+help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
+   |
+LL ~         (0 ..= 255, true) => {}
+LL +         (126_u8..=127_u8, false) => todo!()
+   |
 
 error: aborting due to 12 previous errors
 
diff --git a/src/test/ui/pattern/usefulness/integer-ranges/pointer-sized-int.deny.stderr b/src/test/ui/pattern/usefulness/integer-ranges/pointer-sized-int.deny.stderr
index 574c9849dbb..11a3bf5b177 100644
--- a/src/test/ui/pattern/usefulness/integer-ranges/pointer-sized-int.deny.stderr
+++ b/src/test/ui/pattern/usefulness/integer-ranges/pointer-sized-int.deny.stderr
@@ -153,7 +153,11 @@ LL |     match 0isize {
    = note: the matched value is of type `isize`
    = note: `isize` does not have a fixed maximum value, so a wildcard `_` is necessary to match exhaustively
    = help: add `#![feature(precise_pointer_size_matching)]` to the crate attributes to enable precise `isize` matching
-   = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
+help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
+   |
+LL ~         1 ..= isize::MAX => {}
+LL +         _ => todo!()
+   |
 
 error[E0004]: non-exhaustive patterns: type `usize` is non-empty
   --> $DIR/pointer-sized-int.rs:48:11