1
Fork 0

Remove hacky branch in sort_candidate

Reusing `self.test` wasn't actually pulling a lot of weight.
This commit is contained in:
Nadrieril 2024-02-15 04:22:56 +01:00
parent b6e4299415
commit 5e11a99bb6

View file

@ -673,6 +673,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
} }
} }
} }
(TestKind::Len { .. }, _) => {
fully_matched = false;
None
}
(TestKind::Range(test), &TestCase::Range(pat)) => { (TestKind::Range(test), &TestCase::Range(pat)) => {
if test.as_ref() == pat { if test.as_ref() == pat {
@ -700,29 +704,16 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
None None
} }
(&TestKind::Eq { .. } | &TestKind::Len { .. }, _) => { // FIXME(#29623): return `Some(1)` when the values are different.
// The call to `self.test(&match_pair)` below is not actually used to generate any (TestKind::Eq { value: test_val, .. }, TestCase::Constant { value: case_val })
// MIR. Instead, we just want to compare with `test` (the parameter of the method) if test_val == case_val =>
// to see if it is the same. {
// fully_matched = true;
// However, at this point we can still encounter or-patterns that were extracted Some(0)
// from previous calls to `sort_candidate`, so we need to manually address that }
// case to avoid panicking in `self.test()`. (TestKind::Eq { .. }, _) => {
if let TestCase::Or { .. } = &match_pair.test_case { fully_matched = false;
return None; None
}
// These are all binary tests.
//
// FIXME(#29623) we can be more clever here
let pattern_test = self.test(match_pair);
if pattern_test.kind == test.kind {
fully_matched = true;
Some(0)
} else {
fully_matched = false;
None
}
} }
}; };