Skip to content

Commit 6ea816b

Browse files
committed
Experiment: remove hack
1 parent 9a05cf2 commit 6ea816b

File tree

1 file changed

+6
-17
lines changed
  • compiler/rustc_mir_build/src/build/matches

1 file changed

+6
-17
lines changed

compiler/rustc_mir_build/src/build/matches/test.rs

+6-17
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
216216

217217
target_blocks
218218
};
219+
let target_blocks = make_target_blocks(self);
219220

220221
let place = place_builder.to_place(self);
221222
let place_ty = place.ty(&self.local_decls, self.tcx);
@@ -224,7 +225,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
224225
let source_info = self.source_info(test.span);
225226
match test.kind {
226227
TestKind::Switch { adt_def, ref variants } => {
227-
let target_blocks = make_target_blocks(self);
228228
// Variants is a BitVec of indexes into adt_def.variants.
229229
let num_enum_variants = adt_def.variants().len();
230230
debug_assert_eq!(target_blocks.len(), num_enum_variants + 1);
@@ -270,7 +270,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
270270
}
271271

272272
TestKind::SwitchInt { switch_ty, ref options } => {
273-
let target_blocks = make_target_blocks(self);
274273
let terminator = if *switch_ty.kind() == ty::Bool {
275274
assert!(!options.is_empty() && options.len() <= 2);
276275
let [first_bb, second_bb] = *target_blocks else {
@@ -340,7 +339,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
340339
);
341340
self.non_scalar_compare(
342341
eq_block,
343-
make_target_blocks,
342+
target_blocks,
344343
source_info,
345344
value,
346345
ref_str,
@@ -351,15 +350,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
351350
if !ty.is_scalar() {
352351
// Use `PartialEq::eq` instead of `BinOp::Eq`
353352
// (the binop can only handle primitives)
354-
self.non_scalar_compare(
355-
block,
356-
make_target_blocks,
357-
source_info,
358-
value,
359-
place,
360-
ty,
361-
);
362-
} else if let [success, fail] = *make_target_blocks(self) {
353+
self.non_scalar_compare(block, target_blocks, source_info, value, place, ty);
354+
} else if let [success, fail] = *target_blocks {
363355
assert_eq!(value.ty(), ty);
364356
let expect = self.literal_operand(test.span, value);
365357
let val = Operand::Copy(place);
@@ -371,7 +363,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
371363

372364
TestKind::Range(ref range) => {
373365
let lower_bound_success = self.cfg.start_new_block();
374-
let target_blocks = make_target_blocks(self);
375366

376367
// Test `val` by computing `lo <= val && val <= hi`, using primitive comparisons.
377368
// FIXME: skip useless comparison when the range is half-open.
@@ -401,8 +392,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
401392
}
402393

403394
TestKind::Len { len, op } => {
404-
let target_blocks = make_target_blocks(self);
405-
406395
let usize_ty = self.tcx.types.usize;
407396
let actual = self.temp(usize_ty, test.span);
408397

@@ -466,7 +455,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
466455
fn non_scalar_compare(
467456
&mut self,
468457
block: BasicBlock,
469-
make_target_blocks: impl FnOnce(&mut Self) -> Vec<BasicBlock>,
458+
target_blocks: Vec<BasicBlock>,
470459
source_info: SourceInfo,
471460
value: Const<'tcx>,
472461
mut val: Place<'tcx>,
@@ -591,7 +580,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
591580
);
592581
self.diverge_from(block);
593582

594-
let [success_block, fail_block] = *make_target_blocks(self) else {
583+
let [success_block, fail_block] = *target_blocks else {
595584
bug!("`TestKind::Eq` should have two target blocks")
596585
};
597586
// check the result

0 commit comments

Comments
 (0)