Skip to content

Commit

Permalink
Add guarded arms to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
varkor committed Aug 16, 2018
1 parent 07064de commit 25ba911
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/test/ui/exhaustive_integer_patterns.rs
Expand Up @@ -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
}
}
8 changes: 7 additions & 1 deletion src/test/ui/exhaustive_integer_patterns.stderr
Expand Up @@ -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`.

0 comments on commit 25ba911

Please sign in to comment.