Skip to content

Commit 5e11a99

Browse files
committed
Remove hacky branch in sort_candidate
Reusing `self.test` wasn't actually pulling a lot of weight.
1 parent b6e4299 commit 5e11a99

File tree

1 file changed

+14
-23
lines changed
  • compiler/rustc_mir_build/src/build/matches

1 file changed

+14
-23
lines changed

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

+14-23
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
673673
}
674674
}
675675
}
676+
(TestKind::Len { .. }, _) => {
677+
fully_matched = false;
678+
None
679+
}
676680

677681
(TestKind::Range(test), &TestCase::Range(pat)) => {
678682
if test.as_ref() == pat {
@@ -700,29 +704,16 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
700704
None
701705
}
702706

703-
(&TestKind::Eq { .. } | &TestKind::Len { .. }, _) => {
704-
// The call to `self.test(&match_pair)` below is not actually used to generate any
705-
// MIR. Instead, we just want to compare with `test` (the parameter of the method)
706-
// to see if it is the same.
707-
//
708-
// However, at this point we can still encounter or-patterns that were extracted
709-
// from previous calls to `sort_candidate`, so we need to manually address that
710-
// case to avoid panicking in `self.test()`.
711-
if let TestCase::Or { .. } = &match_pair.test_case {
712-
return None;
713-
}
714-
715-
// These are all binary tests.
716-
//
717-
// FIXME(#29623) we can be more clever here
718-
let pattern_test = self.test(match_pair);
719-
if pattern_test.kind == test.kind {
720-
fully_matched = true;
721-
Some(0)
722-
} else {
723-
fully_matched = false;
724-
None
725-
}
707+
// FIXME(#29623): return `Some(1)` when the values are different.
708+
(TestKind::Eq { value: test_val, .. }, TestCase::Constant { value: case_val })
709+
if test_val == case_val =>
710+
{
711+
fully_matched = true;
712+
Some(0)
713+
}
714+
(TestKind::Eq { .. }, _) => {
715+
fully_matched = false;
716+
None
726717
}
727718
};
728719

0 commit comments

Comments
 (0)