]> git.lizzy.rs Git - rust.git/commitdiff
Add guarded arms to tests
authorvarkor <github@varkor.com>
Sat, 2 Jun 2018 09:53:47 +0000 (10:53 +0100)
committervarkor <github@varkor.com>
Thu, 16 Aug 2018 19:09:05 +0000 (20:09 +0100)
src/test/ui/exhaustive_integer_patterns.rs
src/test/ui/exhaustive_integer_patterns.stderr

index e8f2affbec35812e307c991000bf085b32a5dc9c..294481389f7133ef89d8a1054c5caa9ee1bd56af 100644 (file)
@@ -120,4 +120,16 @@ fn main() {
     match 0i128 {
         i128::MIN ..= i128::MAX => {} // ok
     }
+
+    // Make sure that guards don't factor into the exhaustiveness checks.
+    match 0u8 { //~ ERROR non-exhaustive patterns
+        0 .. 128 => {}
+        128 ..= 255 if true => {}
+    }
+
+    match 0u8 {
+        0 .. 128 => {}
+        128 ..= 255 if false => {}
+        128 ..= 255 => {} // ok, because previous arm was guarded
+    }
 }
index 0f7ab8688c678bbda42ee9c121acab211b3fc5c7..a2ed9416b50bbce6200252f5981423a217bf7bbf 100644 (file)
@@ -46,6 +46,12 @@ error[E0004]: non-exhaustive patterns: `0i16` not covered
 LL |     match 0i16 { //~ ERROR non-exhaustive patterns
    |           ^^^^ pattern `0i16` not covered
 
-error: aborting due to 7 previous errors
+error[E0004]: non-exhaustive patterns: `128u8..=255u8` not covered
+  --> $DIR/exhaustive_integer_patterns.rs:125:11
+   |
+LL |     match 0u8 { //~ ERROR non-exhaustive patterns
+   |           ^^^ pattern `128u8..=255u8` not covered
+
+error: aborting due to 8 previous errors
 
 For more information about this error, try `rustc --explain E0004`.