diff --git a/src/librustc_mir/hair/pattern/_match.rs b/src/librustc_mir/hair/pattern/_match.rs index 484b8209658..e928d4e5f03 100644 --- a/src/librustc_mir/hair/pattern/_match.rs +++ b/src/librustc_mir/hair/pattern/_match.rs @@ -1501,6 +1501,8 @@ enum Endpoint { 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, diff --git a/src/test/ui/exhaustive_integer_patterns.rs b/src/test/ui/exhaustive_integer_patterns.rs index 6e2bebc86ad..50fc825e74e 100644 --- a/src/test/ui/exhaustive_integer_patterns.rs +++ b/src/test/ui/exhaustive_integer_patterns.rs @@ -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 => {} + } } diff --git a/src/test/ui/exhaustive_integer_patterns.stderr b/src/test/ui/exhaustive_integer_patterns.stderr index 2222283247b..3a47a091012 100644 --- a/src/test/ui/exhaustive_integer_patterns.stderr +++ b/src/test/ui/exhaustive_integer_patterns.stderr @@ -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`.