Skip to content

Commit de07294

Browse files
authored
Unrolled build for rust-lang#121706
Rollup merge of rust-lang#121706 - Nadrieril:simplify-sort-candidate, r=matthewjasper match lowering: Remove hacky branch in sort_candidate Reusing `self.test()` there wasn't actually pulling a lot of weight. In particular the `TestKind::Len` cases were all already correctly handled. r? `@matthewjasper`
2 parents e612d07 + f363c1a commit de07294

File tree

1 file changed

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

1 file changed

+17
-34
lines changed

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

+17-34
Original file line numberDiff line numberDiff line change
@@ -583,10 +583,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
583583
fully_matched = true;
584584
Some(variant_index.as_usize())
585585
}
586-
(&TestKind::Switch { .. }, _) => {
587-
fully_matched = false;
588-
None
589-
}
590586

591587
// If we are performing a switch over integers, then this informs integer
592588
// equality, but nothing else.
@@ -611,10 +607,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
611607
options.len()
612608
})
613609
}
614-
(&TestKind::SwitchInt { .. }, _) => {
615-
fully_matched = false;
616-
None
617-
}
618610

619611
(
620612
&TestKind::Len { len: test_len, op: BinOp::Eq },
@@ -703,34 +695,25 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
703695
None
704696
}
705697
}
706-
(&TestKind::Range { .. }, _) => {
707-
fully_matched = false;
708-
None
709-
}
710698

711-
(&TestKind::Eq { .. } | &TestKind::Len { .. }, _) => {
712-
// The call to `self.test(&match_pair)` below is not actually used to generate any
713-
// MIR. Instead, we just want to compare with `test` (the parameter of the method)
714-
// to see if it is the same.
715-
//
716-
// However, at this point we can still encounter or-patterns that were extracted
717-
// from previous calls to `sort_candidate`, so we need to manually address that
718-
// case to avoid panicking in `self.test()`.
719-
if let TestCase::Or { .. } = &match_pair.test_case {
720-
return None;
721-
}
699+
// FIXME(#29623): return `Some(1)` when the values are different.
700+
(TestKind::Eq { value: test_val, .. }, TestCase::Constant { value: case_val })
701+
if test_val == case_val =>
702+
{
703+
fully_matched = true;
704+
Some(0)
705+
}
722706

723-
// These are all binary tests.
724-
//
725-
// FIXME(#29623) we can be more clever here
726-
let pattern_test = self.test(match_pair);
727-
if pattern_test.kind == test.kind {
728-
fully_matched = true;
729-
Some(0)
730-
} else {
731-
fully_matched = false;
732-
None
733-
}
707+
(
708+
TestKind::Switch { .. }
709+
| TestKind::SwitchInt { .. }
710+
| TestKind::Len { .. }
711+
| TestKind::Range { .. }
712+
| TestKind::Eq { .. },
713+
_,
714+
) => {
715+
fully_matched = false;
716+
None
734717
}
735718
};
736719

0 commit comments

Comments
 (0)