Skip to content

Commit 6a957e1

Browse files
committed
Add a test case for u128::MAX - 1
1 parent 61b6363 commit 6a957e1

File tree

3 files changed

+23
-10
lines changed

3 files changed

+23
-10
lines changed

src/librustc_mir/hair/pattern/_match.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1501,6 +1501,8 @@ fn split_grouped_constructors<'p, 'a: 'p, 'tcx: 'a>(
15011501
if let Endpoint::Both = a.1 {
15021502
split_ctors.push(IntRange::range_to_ctor(tcx, ty, a.0..=a.0));
15031503
}
1504+
// Integer overflow cannot occur here, because only the first point may be
1505+
// u128::MIN and only the last may be u128::MAX.
15041506
let c = match a.1 {
15051507
Endpoint::Start => a.0,
15061508
Endpoint::End | Endpoint::Both => a.0 + 1,

src/test/ui/exhaustive_integer_patterns.rs

+14-9
Original file line numberDiff line numberDiff line change
@@ -140,21 +140,26 @@ fn main() {
140140
}
141141

142142
match (0u8, true) { //~ ERROR non-exhaustive patterns
143-
(0..=125, false) => {}
144-
(128..=255, false) => {}
145-
(0..=255, true) => {}
143+
(0 ..= 125, false) => {}
144+
(128 ..= 255, false) => {}
145+
(0 ..= 255, true) => {}
146146
}
147147

148148
match (0u8, true) { // ok
149-
(0..=125, false) => {}
150-
(128..=255, false) => {}
151-
(0..=255, true) => {}
152-
(125..128, false) => {}
149+
(0 ..= 125, false) => {}
150+
(128 ..= 255, false) => {}
151+
(0 ..= 255, true) => {}
152+
(125 .. 128, false) => {}
153153
}
154154

155155
match 0u8 { // ok
156-
0..2 => {}
157-
1..=2 => {}
156+
0 .. 2 => {}
157+
1 ..= 2 => {}
158158
_ => {}
159159
}
160+
161+
const lim: u128 = u128::MAX - 1;
162+
match 0u128 { //~ ERROR non-exhaustive patterns
163+
0 ..= lim => {}
164+
}
160165
}

src/test/ui/exhaustive_integer_patterns.stderr

+7-1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ error[E0004]: non-exhaustive patterns: `(126u8..=127u8, false)` not covered
6464
LL | match (0u8, true) { //~ ERROR non-exhaustive patterns
6565
| ^^^^^^^^^^^ pattern `(126u8..=127u8, false)` not covered
6666

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

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

0 commit comments

Comments
 (0)