Skip to content

Commit 3531c52

Browse files
committed
Factor out range construction in all_constructors
1 parent 8f7ba7a commit 3531c52

File tree

1 file changed

+5
-16
lines changed

1 file changed

+5
-16
lines changed

src/librustc_mir/hair/pattern/_match.rs

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,6 +1156,7 @@ fn all_constructors<'a, 'tcx>(
11561156
pcx: PatCtxt<'tcx>,
11571157
) -> Vec<Constructor<'tcx>> {
11581158
debug!("all_constructors({:?})", pcx.ty);
1159+
let make_range = |start, end| ConstantRange(start, end, pcx.ty, RangeEnd::Included, pcx.span);
11591160
match pcx.ty.kind {
11601161
ty::Bool => [true, false]
11611162
.iter()
@@ -1219,20 +1220,8 @@ fn all_constructors<'a, 'tcx>(
12191220
ty::Char => {
12201221
vec![
12211222
// The valid Unicode Scalar Value ranges.
1222-
ConstantRange(
1223-
'\u{0000}' as u128,
1224-
'\u{D7FF}' as u128,
1225-
cx.tcx.types.char,
1226-
RangeEnd::Included,
1227-
pcx.span,
1228-
),
1229-
ConstantRange(
1230-
'\u{E000}' as u128,
1231-
'\u{10FFFF}' as u128,
1232-
cx.tcx.types.char,
1233-
RangeEnd::Included,
1234-
pcx.span,
1235-
),
1223+
make_range('\u{0000}' as u128, '\u{D7FF}' as u128),
1224+
make_range('\u{E000}' as u128, '\u{10FFFF}' as u128),
12361225
]
12371226
}
12381227
ty::Int(_) | ty::Uint(_)
@@ -1248,12 +1237,12 @@ fn all_constructors<'a, 'tcx>(
12481237
let bits = Integer::from_attr(&cx.tcx, SignedInt(ity)).size().bits() as u128;
12491238
let min = 1u128 << (bits - 1);
12501239
let max = min - 1;
1251-
vec![ConstantRange(min, max, pcx.ty, RangeEnd::Included, pcx.span)]
1240+
vec![make_range(min, max)]
12521241
}
12531242
ty::Uint(uty) => {
12541243
let size = Integer::from_attr(&cx.tcx, UnsignedInt(uty)).size();
12551244
let max = truncate(u128::max_value(), size);
1256-
vec![ConstantRange(0, max, pcx.ty, RangeEnd::Included, pcx.span)]
1245+
vec![make_range(0, max)]
12571246
}
12581247
_ => {
12591248
if cx.is_uninhabited(pcx.ty) {

0 commit comments

Comments
 (0)