Skip to content

Commit

Permalink
Add a test case for u128::MAX - 1
Browse files Browse the repository at this point in the history
  • Loading branch information
varkor committed Aug 21, 2018
1 parent 61b6363 commit 6a957e1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
2 changes: 2 additions & 0 deletions src/librustc_mir/hair/pattern/_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1501,6 +1501,8 @@ fn split_grouped_constructors<'p, 'a: 'p, 'tcx: 'a>(
if let Endpoint::Both = a.1 {
split_ctors.push(IntRange::range_to_ctor(tcx, ty, a.0..=a.0));
}
// Integer overflow cannot occur here, because only the first point may be
// u128::MIN and only the last may be u128::MAX.
let c = match a.1 {
Endpoint::Start => a.0,
Endpoint::End | Endpoint::Both => a.0 + 1,
Expand Down
23 changes: 14 additions & 9 deletions src/test/ui/exhaustive_integer_patterns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,21 +140,26 @@ fn main() {
}

match (0u8, true) { //~ ERROR non-exhaustive patterns
(0..=125, false) => {}
(128..=255, false) => {}
(0..=255, true) => {}
(0 ..= 125, false) => {}
(128 ..= 255, false) => {}
(0 ..= 255, true) => {}
}

match (0u8, true) { // ok
(0..=125, false) => {}
(128..=255, false) => {}
(0..=255, true) => {}
(125..128, false) => {}
(0 ..= 125, false) => {}
(128 ..= 255, false) => {}
(0 ..= 255, true) => {}
(125 .. 128, false) => {}
}

match 0u8 { // ok
0..2 => {}
1..=2 => {}
0 .. 2 => {}
1 ..= 2 => {}
_ => {}
}

const lim: u128 = u128::MAX - 1;
match 0u128 { //~ ERROR non-exhaustive patterns
0 ..= lim => {}
}
}
8 changes: 7 additions & 1 deletion src/test/ui/exhaustive_integer_patterns.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ error[E0004]: non-exhaustive patterns: `(126u8..=127u8, false)` not covered
LL | match (0u8, true) { //~ ERROR non-exhaustive patterns
| ^^^^^^^^^^^ pattern `(126u8..=127u8, false)` not covered

error: aborting due to 10 previous errors
error[E0004]: non-exhaustive patterns: `340282366920938463463374607431768211455u128` not covered
--> $DIR/exhaustive_integer_patterns.rs:162:11
|
LL | match 0u128 { //~ ERROR non-exhaustive patterns
| ^^^^^ pattern `340282366920938463463374607431768211455u128` not covered

error: aborting due to 11 previous errors

For more information about this error, try `rustc --explain E0004`.

0 comments on commit 6a957e1

Please sign in to comment.