Skip to content

Commit 116e46e

Browse files
committed
Malformed range patterns can't happen thanks to E0030
1 parent d48cd48 commit 116e46e

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

src/librustc_mir/hair/pattern/_match.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -1107,8 +1107,7 @@ fn all_constructors<'a, 'tcx>(
11071107
debug!("all_constructors({:?})", pcx.ty);
11081108
let make_range = |start, end| {
11091109
IntRange(
1110-
// `unwrap()` is ok because we know the type is an integer and the range is
1111-
// well-formed.
1110+
// `unwrap()` is ok because we know the type is an integer.
11121111
IntRange::from_range(cx.tcx, start, end, pcx.ty, &RangeEnd::Included, pcx.span)
11131112
.unwrap(),
11141113
)
@@ -1265,13 +1264,12 @@ impl<'tcx> IntRange<'tcx> {
12651264
// which makes the interval arithmetic simpler.
12661265
let bias = IntRange::signed_bias(tcx, ty);
12671266
let (lo, hi) = (lo ^ bias, hi ^ bias);
1268-
// Make sure the interval is well-formed.
1269-
if lo > hi || lo == hi && *end == RangeEnd::Excluded {
1270-
None
1271-
} else {
1272-
let offset = (*end == RangeEnd::Excluded) as u128;
1273-
Some(IntRange { range: lo..=(hi - offset), ty, span })
1267+
let offset = (*end == RangeEnd::Excluded) as u128;
1268+
if lo > hi || (lo == hi && *end == RangeEnd::Excluded) {
1269+
// This hould have been caught earlier by E0030
1270+
bug!("malformed range pattern: {}..={}", lo, (hi - offset));
12741271
}
1272+
Some(IntRange { range: lo..=(hi - offset), ty, span })
12751273
} else {
12761274
None
12771275
}

0 commit comments

Comments
 (0)